static void test_find_resource(void) { HRSRC rsrc; rsrc = FindResourceW( GetModuleHandleW(NULL), MAKEINTRESOURCEW(1), (LPCWSTR)RT_MENU ); ok( rsrc != 0, "resource not found\n" ); rsrc = FindResourceExW( GetModuleHandleW(NULL), (LPCWSTR)RT_MENU, MAKEINTRESOURCEW(1), MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL )); ok( rsrc != 0, "resource not found\n" ); rsrc = FindResourceExW( GetModuleHandleW(NULL), (LPCWSTR)RT_MENU, MAKEINTRESOURCEW(1), MAKELANGID( LANG_GERMAN, SUBLANG_DEFAULT )); ok( rsrc != 0, "resource not found\n" ); SetLastError( 0xdeadbeef ); rsrc = FindResourceW( GetModuleHandleW(NULL), MAKEINTRESOURCEW(1), (LPCWSTR)RT_DIALOG ); ok( !rsrc, "resource found\n" ); ok( GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND, "wrong error %u\n", GetLastError() ); SetLastError( 0xdeadbeef ); rsrc = FindResourceW( GetModuleHandleW(NULL), MAKEINTRESOURCEW(2), (LPCWSTR)RT_MENU ); ok( !rsrc, "resource found\n" ); ok( GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND, "wrong error %u\n", GetLastError() ); SetLastError( 0xdeadbeef ); rsrc = FindResourceExW( GetModuleHandleW(NULL), (LPCWSTR)RT_MENU, MAKEINTRESOURCEW(1), MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT ) ); ok( !rsrc, "resource found\n" ); ok( GetLastError() == ERROR_RESOURCE_LANG_NOT_FOUND, "wrong error %u\n", GetLastError() ); SetLastError( 0xdeadbeef ); rsrc = FindResourceExW( GetModuleHandleW(NULL), (LPCWSTR)RT_MENU, MAKEINTRESOURCEW(1), MAKELANGID( LANG_FRENCH, SUBLANG_DEFAULT ) ); ok( !rsrc, "resource found\n" ); ok( GetLastError() == ERROR_RESOURCE_LANG_NOT_FOUND, "wrong error %u\n", GetLastError() ); }
/*********************************************************************** * OleUIPasteSpecialW (OLEDLG.22) */ UINT WINAPI OleUIPasteSpecialW(LPOLEUIPASTESPECIALW ps) { LPCDLGTEMPLATEW dlg_templ = (LPCDLGTEMPLATEW)ps->hResource; UINT ret; TRACE("(%p)\n", ps); if(TRACE_ON(ole)) dump_pastespecial(ps); if(!ps->lpSrcDataObj) OleGetClipboard(&ps->lpSrcDataObj); if(ps->hInstance || !ps->hResource) { HINSTANCE hInst = ps->hInstance ? ps->hInstance : OLEDLG_hInstance; const WCHAR *name = ps->hInstance ? ps->lpszTemplate : MAKEINTRESOURCEW(IDD_PASTESPECIAL4); HRSRC hrsrc; if(name == NULL) return OLEUI_ERR_LPSZTEMPLATEINVALID; hrsrc = FindResourceW(hInst, name, MAKEINTRESOURCEW(RT_DIALOG)); if(!hrsrc) return OLEUI_ERR_FINDTEMPLATEFAILURE; dlg_templ = LoadResource(hInst, hrsrc); if(!dlg_templ) return OLEUI_ERR_LOADTEMPLATEFAILURE; } ret = DialogBoxIndirectParamW(OLEDLG_hInstance, dlg_templ, ps->hWndOwner, ps_dlg_proc, (LPARAM)ps); return ret; }
/*********************************************************************** * AtlAxCreateDialogW [atl100.@] * * See AtlAxCreateDialogA * */ HWND WINAPI AtlAxCreateDialogW(HINSTANCE hInst, LPCWSTR name, HWND owner, DLGPROC dlgProc ,LPARAM param) { HRSRC hrsrc; HGLOBAL hgl; LPCDLGTEMPLATEW ptr; LPDLGTEMPLATEW newptr; HWND res; TRACE("(%p %s %p %p %lx)\n", hInst, debugstr_w(name), owner, dlgProc, param); hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG ); if ( !hrsrc ) return NULL; hgl = LoadResource (hInst, hrsrc); if ( !hgl ) return NULL; ptr = LockResource ( hgl ); if (!ptr) { FreeResource( hgl ); return NULL; } newptr = AX_ConvertDialogTemplate( ptr ); if ( newptr ) { res = CreateDialogIndirectParamW( hInst, newptr, owner, dlgProc, param ); HeapFree( GetProcessHeap(), 0, newptr ); } else res = NULL; FreeResource ( hrsrc ); return res; }
/* * @implemented */ PVOID WINAPI EngFindResource(HANDLE h, int iName, int iType, PULONG pulSize) { HRSRC HRSrc; DWORD Size = 0; HGLOBAL Hg; LPVOID Lock = NULL; if ((HRSrc = FindResourceW( (HMODULE) h, MAKEINTRESOURCEW(iName), MAKEINTRESOURCEW(iType)))) { if ((Size = SizeofResource( (HMODULE) h, HRSrc ))) { if ((Hg = LoadResource( (HMODULE) h, HRSrc ))) { Lock = LockResource( Hg ); } } } *pulSize = Size; return (PVOID) Lock; }
/*********************************************************************** * get_first_resource * * Helper for create_app_icon_images(). Enum proc for EnumResourceNamesW() * which just gets the handle for the first resource and stops further * enumeration. */ static BOOL CALLBACK get_first_resource(HMODULE module, LPCWSTR type, LPWSTR name, LONG_PTR lparam) { HRSRC *res_info = (HRSRC*)lparam; *res_info = FindResourceW(module, name, (LPCWSTR)RT_GROUP_ICON); return FALSE; }
///////////////////////////////////////////////////////////////////////////// // LaunchUrlmonDialog ///////////////////////////////////////////////////////////////////////////// int LaunchUrlmonDialog ( IN HWND hWnd, IN DWORD dwAction, IN DWORD dwPermissions, IN LPCTSTR lpszText ) { int iRet = ERROR_CALL_NOT_IMPLEMENTED; UMDLGPARAMS umparams; umparams.eDlgType = GetDialogType(dwAction, dwPermissions); umparams.pszMsg = lpszText; iRet = DialogBoxIndirectParamW(HINST_RESDLL, (LPCDLGTEMPLATEW)LoadResource(HINST_RESDLL, FindResourceW(HINST_RESDLL, MAKEINTRESOURCEW(IDD_URLMON), RT_DIALOG)), SHGetLastActiveWindow(hWnd), (DLGPROC)UrlmonDialogProc, (LPARAM)&umparams); return iRet; }
/************************************************************************* * ShellAboutW [SHELL32.289] */ BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff, HICON hIcon ) { ABOUT_INFO info; HRSRC hRes; DLGTEMPLATE *DlgTemplate; BOOL bRet; TRACE("\n"); // DialogBoxIndirectParamW will be called with the hInstance of the calling application, so we have to preload the dialog template hRes = FindResourceW(shell32_hInstance, MAKEINTRESOURCEW(IDD_ABOUT), (LPWSTR)RT_DIALOG); if(!hRes) return FALSE; DlgTemplate = (DLGTEMPLATE *)LoadResource(shell32_hInstance, hRes); if(!DlgTemplate) return FALSE; info.szApp = szApp; info.szOtherStuff = szOtherStuff; info.hIcon = hIcon ? hIcon : LoadIconW( 0, (LPWSTR)IDI_WINLOGO ); bRet = DialogBoxIndirectParamW((HINSTANCE)GetWindowLongPtrW( hWnd, GWLP_HINSTANCE ), DlgTemplate, hWnd, AboutDlgProc, (LPARAM)&info ); return bRet; }
static BOOL ANIMATE_LoadResW(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPCWSTR lpName) { static const WCHAR aviW[] = { 'A', 'V', 'I', 0 }; HRSRC hrsrc; MMIOINFO mminfo; LPVOID lpAvi; hrsrc = FindResourceW(hInst, lpName, aviW); if (!hrsrc) return FALSE; infoPtr->hRes = LoadResource(hInst, hrsrc); if (!infoPtr->hRes) return FALSE; lpAvi = LockResource(infoPtr->hRes); if (!lpAvi) return FALSE; memset(&mminfo, 0, sizeof(mminfo)); mminfo.fccIOProc = FOURCC_MEM; mminfo.pchBuffer = lpAvi; mminfo.cchBuffer = SizeofResource(hInst, hrsrc); infoPtr->hMMio = mmioOpenW(NULL, &mminfo, MMIO_READ); if (!infoPtr->hMMio) { FreeResource(infoPtr->hRes); return FALSE; } return TRUE; }
BOOL GetManifestStringFromModule(HMODULE mod, LPSTR manifest, SIZE_T size) { HRSRC rsrc = FindResourceW(mod, MAKEINTRESOURCE(1), RT_MANIFEST); if(!rsrc) return FALSE; ULONG rsrc_size = SizeofResource(mod, rsrc); HGLOBAL grsrc = LoadResource(mod, rsrc); if(!grsrc) return FALSE; PVOID prsrc = LockResource(grsrc); if(!prsrc) { FreeResource(grsrc); return FALSE; } ByteBuffer tmp; tmp.resize(rsrc_size); memcpy(&tmp[0], prsrc, rsrc_size); tmp.push_back(0); StringCbCopyA(manifest, size, (LPCSTR) &tmp[0]); UnlockResource(prsrc); FreeResource(grsrc); return TRUE; }
HPROPSHEETPAGE SH_CreatePropertySheetPage(WORD wDialogId, DLGPROC pfnDlgProc, LPARAM lParam, LPCWSTR pwszTitle) { HRSRC hRes = FindResourceW(shell32_hInstance, MAKEINTRESOURCEW(wDialogId), (LPWSTR)RT_DIALOG); if (hRes == NULL) { ERR("failed to find resource id\n"); return NULL; } LPVOID pTemplate = LoadResource(shell32_hInstance, hRes); if (pTemplate == NULL) { ERR("failed to load resource\n"); return NULL; } PROPSHEETPAGEW Page; memset(&Page, 0x0, sizeof(PROPSHEETPAGEW)); Page.dwSize = sizeof(PROPSHEETPAGEW); Page.dwFlags = PSP_DLGINDIRECT; Page.pResource = (DLGTEMPLATE*)pTemplate; Page.pfnDlgProc = pfnDlgProc; Page.lParam = lParam; Page.pszTitle = pwszTitle; if (pwszTitle) Page.dwFlags |= PSP_USETITLE; return CreatePropertySheetPageW(&Page); }
static void add_authors( HWND list ) { static const WCHAR eol[] = {'\r','\n',0}; static const WCHAR authors[] = {'A','U','T','H','O','R','S',0}; WCHAR *strW, *start, *end; HRSRC rsrc = FindResourceW( shell32_hInstance, authors, (LPCWSTR)RT_RCDATA ); char *strA = LockResource( LoadResource( shell32_hInstance, rsrc )); DWORD sizeW, sizeA = SizeofResource( shell32_hInstance, rsrc ); if (!strA) return; sizeW = MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, NULL, 0 ) + 1; if (!(strW = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) ))) return; MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, strW, sizeW ); strW[sizeW - 1] = 0; start = strpbrkW( strW, eol ); /* skip the header line */ while (start) { while (*start && strchrW( eol, *start )) start++; if (!*start) break; end = strpbrkW( start, eol ); if (end) *end++ = 0; SendMessageW( list, LB_ADDSTRING, -1, (LPARAM)start ); start = end; } HeapFree( GetProcessHeap(), 0, strW ); }
// Fills the structure in mk_Memory with a pointer to the resource in memory // mk_Resource.sw_Module may be = "" if the cabinet is in the EXE which created the process. BOOL GetMemory() { CStrW sw_ResName = mk_Resource.sw_Name; if (mk_Resource.u32_ID) sw_ResName.FormatResource(mk_Resource.u32_ID); WCHAR* u16_Module = 0; // Resource is in the calling process if (mk_Resource.sw_Module.Len()) u16_Module = mk_Resource.sw_Module; // Load the resource (via Filemapping, there is no memory consumption here) HMODULE h_DLL = GetModuleHandleW(u16_Module); HRSRC h_Resource = FindResourceW(h_DLL, sw_ResName, mk_Resource.sw_Type); HGLOBAL h_Global = LoadResource (h_DLL, h_Resource); mk_Memory.p_Addr = LockResource (h_Global); mk_Memory.s32_Size = SizeofResource(h_DLL, h_Resource); mk_Memory.s32_Pos = 0; if (mk_Memory.p_Addr == 0 || mk_Memory.s32_Size == 0) { mi_Error.Set(FDIERROR_INVAL_RESOURCE,0,0); return FALSE; } return TRUE; }
bool KAppRes::PrepareRes() { bool retval = false; KFilePath pathRes = KFilePath::GetFilePath(g_hInstance); HRSRC hResInfo = NULL; HGLOBAL hResDat = NULL; PVOID pResBuffer = NULL; DWORD dwResBuffer; wchar_t szTempPath[MAX_PATH] = { 0 }; wchar_t szTempFilePath[MAX_PATH] = { 0 }; //BOOL fRetCode; //DWORD dwWritten; pathRes.RemoveExtension(); pathRes.AddExtension(L"kui"); if (GetFileAttributesW(pathRes) != INVALID_FILE_ATTRIBUTES) { m_strResPackPath = pathRes.value(); } else { hResInfo = FindResourceW(_ModulePtr->GetResourceInstance(), L"kuires.dat", L"SKIN"); if (!hResInfo) goto clean0; hResDat = LoadResource(_ModulePtr->GetResourceInstance(), hResInfo); if (!hResDat) goto clean0; pResBuffer = LockResource(hResDat); if (!pResBuffer) goto clean0; dwResBuffer = SizeofResource(_ModulePtr->GetResourceInstance(), hResInfo); m_memZipRes.SetData(pResBuffer, dwResBuffer); /* GetTempPathW(MAX_PATH, szTempPath); GetTempFileNameW(szTempPath, L"kui", 0, szTempFilePath); m_hTempRes = CreateFileW(szTempFilePath, GENERIC_ALL, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL); if (INVALID_HANDLE_VALUE == m_hTempRes) goto clean0; fRetCode = WriteFile(m_hTempRes, pResBuffer, dwResBuffer, &dwWritten, NULL); if (!fRetCode) goto clean0; fRetCode = FlushFileBuffers(m_hTempRes); m_strResPackPath = szTempFilePath;*/ } retval = true; clean0: return retval; }
BOOL WINAPI WriteAppletToFile(HANDLE FileHandle) { BOOL Success = FALSE; HRSRC ResourceHandle = NULL; HGLOBAL Resource = NULL; DWORD BytesCount = 0; LPVOID Bytes = NULL; ResourceHandle = FindResourceW( g_ModuleHandle, MAKEINTRESOURCEW(IDR_X64_EXE), RT_RCDATA ); if (!ResourceHandle) return FALSE; BytesCount = SizeofResource( g_ModuleHandle, ResourceHandle ); Resource = LoadResource( g_ModuleHandle, ResourceHandle ); if (!Resource) goto Cleanup; Bytes = LockResource(Resource); if (!Bytes) goto Cleanup; Success = WriteFile( FileHandle, Bytes, BytesCount, NULL, NULL ); Cleanup: if (Bytes) UnlockResource(Bytes); if (Resource) FreeResource(Resource); return Success; }
Resource loadResourceWin32(int name) { HMODULE handle = GetModuleHandle(L"jsrdbg"); HRSRC rc = FindResourceW(handle, MAKEINTRESOURCE(name), RT_RCDATA); if (rc == nullptr) { auto errnum = GetLastError(); throw std::runtime_error("Failed loading resource: " + systemErrorString(errnum)); } HGLOBAL rcData = LoadResource(handle, rc); auto len = SizeofResource(handle, rc); auto addr = static_cast<void*>(LockResource(rcData)); return Resource(addr, len); }
void pySetup() { // Set Menu Icon ICONDATA pyIcon; HRSRC hRes = FindResourceW(hInst, MAKEINTRESOURCEW(IDB_PNG1), L"PNG"); HGLOBAL hMem = LoadResource(hInst, hRes); pyIcon.data = LockResource(hMem); pyIcon.size = SizeofResource(hInst, hRes); _plugin_menuseticon(hMenu, &pyIcon); FreeResource(hMem); // Register menu entry _plugin_menuaddentry(hMenu, MENU_TEMPLATE, "Template"); // edit this (name in subwindow) }
static void register_fake_dll( const WCHAR *name, const void *data, size_t size ) { static const WCHAR atlW[] = {'a','t','l','.','d','l','l',0}; static const WCHAR moduleW[] = {'M','O','D','U','L','E',0}; static const WCHAR regtypeW[] = {'W','I','N','E','_','R','E','G','I','S','T','R','Y',0}; static const WCHAR manifestW[] = {'W','I','N','E','_','M','A','N','I','F','E','S','T',0}; const IMAGE_RESOURCE_DIRECTORY *resdir; LDR_RESOURCE_INFO info; HRESULT hr = S_OK; HMODULE module = (HMODULE)((ULONG_PTR)data | 1); HRSRC rsrc; if ((rsrc = FindResourceW( module, manifestW, MAKEINTRESOURCEW(RT_MANIFEST) ))) { char *manifest = LoadResource( module, rsrc ); register_manifest( name, manifest, SizeofResource( module, rsrc ), data, size ); } info.Type = (ULONG_PTR)regtypeW; if (LdrFindResourceDirectory_U( module, &info, 1, &resdir )) return; if (!registrar) { /* create the object by hand since we can't guarantee that atl and ole32 are registered */ IClassFactory *cf; HRESULT (WINAPI *pDllGetClassObject)( REFCLSID clsid, REFIID iid, LPVOID *ppv ); HMODULE atl = LoadLibraryW( atlW ); if ((pDllGetClassObject = (void *)GetProcAddress( atl, "DllGetClassObject" ))) { hr = pDllGetClassObject( &CLSID_Registrar, &IID_IClassFactory, (void **)&cf ); if (SUCCEEDED( hr )) { hr = IClassFactory_CreateInstance( cf, NULL, &IID_IRegistrar, (void **)®istrar ); IClassFactory_Release( cf ); } } if (!registrar) { ERR( "failed to create IRegistrar: %x\n", hr ); return; } } TRACE( "registering %s\n", debugstr_w(name) ); IRegistrar_ClearReplacements( registrar ); IRegistrar_AddReplacement( registrar, moduleW, name ); EnumResourceNamesW( module, regtypeW, register_resource, (LONG_PTR)&hr ); if (FAILED(hr)) ERR( "failed to register %s: %x\n", debugstr_w(name), hr ); }
// 有BUG得到的 bitmap大小为0 Gdiplus::Bitmap* PictureManager::LoadBitmapFromResource( HMODULE module, UINT resID, LPCTSTR resType ) { Gdiplus::Bitmap* bitmap = nullptr; do { HRSRC hRsc = FindResourceW(module, MAKEINTRESOURCE(resID), resType); if (!hRsc) { DWORD err = GetLastError(); break; } int sizeRsc = SizeofResource(module, hRsc); auto FreeResouceFun = [](HGLOBAL h) { FreeResource(h); }; std::unique_ptr < std::remove_pointer<HGLOBAL>::type, std::function<void(HGLOBAL p) >> hGlobalRes(LoadResource(module, hRsc), FreeResouceFun); if (!hGlobalRes) { break; } auto GlobalFreeFun = [](HGLOBAL global) { //GlobalFree(global); }; std::unique_ptr < std::remove_pointer<HGLOBAL>::type, std::function<void(HGLOBAL) >> global2(GlobalAlloc(GMEM_MOVEABLE, sizeRsc), GlobalFreeFun); if (!global2) { break; } if (!CopyToDestGlobal(hGlobalRes.get(), global2.get(), sizeRsc)) break; LPSTREAM stream; HRESULT hr = CreateStreamOnHGlobal(global2.get(), TRUE, &stream); if (!SUCCEEDED(hr)) { break; } bitmap = Gdiplus::Bitmap::FromStream(stream); } while (0); return bitmap; }
AVIAN_EXPORT const uint8_t* bootJar(unsigned* size) { if (HRSRC hResInfo = FindResourceW( NULL, RESID_BOOT_JAR, reinterpret_cast<LPCWSTR>(RT_RCDATA))) { if (HGLOBAL hRes = LoadResource(NULL, hResInfo)) { *size = SizeofResource(NULL, hResInfo); return (const uint8_t*)LockResource(hRes); } } fprintf(stderr, "boot.jar resource not found\n"); *size = 0; return NULL; }
HWND WINAPI OnCreateDialogParamW(HINSTANCE hInstance, LPCWSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam) { //typedef HWND (WINAPI* OnCreateDialogParamW_t)(HINSTANCE hInstance, LPCWSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam); ORIGINALFASTEX(CreateDialogParamW,NULL); HWND hWnd = NULL; BOOL bAttachGui = FALSE, bStyleHidden = FALSE; LPCDLGTEMPLATE lpTemplate = NULL; DWORD lStyle = 0; //lpTemplate ? lpTemplate->style : 0; DWORD lStyleEx = 0; //lpTemplate ? lpTemplate->dwExtendedStyle : 0; // Загрузить ресурс диалога, и глянуть его параметры lStyle/lStyleEx HRSRC hDlgSrc = FindResourceW(hInstance, lpTemplateName, RT_DIALOG); if (hDlgSrc) { HGLOBAL hDlgHnd = LoadResource(hInstance, hDlgSrc); if (hDlgHnd) { lpTemplate = (LPCDLGTEMPLATE)LockResource(hDlgHnd); if (lpTemplate) { lStyle = lpTemplate ? lpTemplate->style : 0; lStyleEx = lpTemplate ? lpTemplate->dwExtendedStyle : 0; } } } if ((!lpTemplate || CheckCanCreateWindow(NULL, (LPWSTR)32770, lStyle, lStyleEx, hWndParent, bAttachGui, bStyleHidden)) && F(CreateDialogParamW) != NULL) { //if (bAttachGui) //{ // x = grcConEmuClient.left; y = grcConEmuClient.top; // nWidth = grcConEmuClient.right - grcConEmuClient.left; nHeight = grcConEmuClient.bottom - grcConEmuClient.top; //} hWnd = F(CreateDialogParamW)(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam); DWORD dwErr = GetLastError(); if (hWnd && bAttachGui) { OnGuiWindowAttached(hWnd, NULL, NULL, (LPCWSTR)32770, lStyle, lStyleEx, bStyleHidden); SetLastError(dwErr); } } return hWnd; }
static NTSTATUS WriteResource( HANDLE Handle, HANDLE Module, PWSTR ResourceName, PULONG PBytesTransferred) { HRSRC Resource; HGLOBAL ResourceGlob; PVOID ResourceData; DWORD ResourceSize; if ((Resource = FindResourceW(Module, ResourceName, RT_RCDATA)) && (ResourceGlob = LoadResource(Module, Resource)) && (ResourceData = LockResource(ResourceGlob)) && (ResourceSize = SizeofResource(Module, Resource)) && (WriteFile(Handle, ResourceData, ResourceSize, PBytesTransferred, 0))) return STATUS_SUCCESS; else return FspNtStatusFromWin32(GetLastError()); }
static BOOL CALLBACK register_resource( HMODULE module, LPCWSTR type, LPWSTR name, LONG_PTR arg ) { HRESULT *hr = (HRESULT *)arg; WCHAR *buffer; HRSRC rsrc = FindResourceW( module, name, type ); char *str = LoadResource( module, rsrc ); DWORD lenW, lenA = SizeofResource( module, rsrc ); if (!str) return FALSE; lenW = MultiByteToWideChar( CP_UTF8, 0, str, lenA, NULL, 0 ) + 1; if (!(buffer = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) ))) return FALSE; MultiByteToWideChar( CP_UTF8, 0, str, lenA, buffer, lenW ); buffer[lenW - 1] = 0; *hr = IRegistrar_StringRegister( registrar, buffer ); HeapFree( GetProcessHeap(), 0, buffer ); return TRUE; }
LPVOID LoadDialogResource( IN HMODULE hModule, IN LPCWSTR ResourceName, OUT LPDWORD ResourceLength) { HRSRC hSrc; HGLOBAL hRes; PVOID Result; /* find resource */ hSrc = FindResourceW(hModule, ResourceName, (LPCWSTR)RT_DIALOG); if (!hSrc) { /* failed to find resource */ return NULL; } /* now load the resource */ hRes = LoadResource(hAppInstance, hSrc); if (!hRes) { /* failed to load resource */ return NULL; } /* now lock the resource */ Result = LockResource(hRes); if (!Result) { /* failed to lock resource */ return NULL; } if (ResourceLength) { /* store output length */ *ResourceLength = SizeofResource(hAppInstance, hSrc); } /* done */ return Result; }
static BOOL load_data(LPVOID *data, DWORD *sz) { HRSRC rsrc; HGLOBAL h; rsrc = FindResourceW(NULL, L"extra", L"extra"); if (rsrc == NULL) { show_last_error(L"Failed to find portable data in exe"); return false; } h = LoadResource(NULL, rsrc); if (h == NULL) { show_last_error(L"Failed to load portable data from exe"); return false; } *data = LockResource(h); if (*data == NULL) { show_last_error(L"Failed to lock portable data in exe"); return false; } *sz = SizeofResource(NULL, rsrc); if (sz == 0) { show_last_error(L"Failed to get size of portable data in exe"); return false; } return true; }
HRESULT Bitmap::LoadFromResource( ID2D1RenderTarget* pRenderTarget, IWICImagingFactory* pImagingFactory, ID2D1Bitmap** ppBitmap, int id, PWSTR type) { auto hResInfo = FindResourceW(nullptr, MAKEINTRESOURCEW(id), type); if (hResInfo == nullptr) { return E_FAIL; } auto hResData = LoadResource(nullptr, hResInfo); if (hResData == nullptr) { return E_FAIL; } auto pMemory = LockResource(hResData); if (pMemory == nullptr) { return E_FAIL; } auto size = SizeofResource(nullptr, hResInfo); if (size == 0) { return E_FAIL; } CComPtr<IWICStream> pStream; auto hr = pImagingFactory->CreateStream(&pStream); if (FAILED(hr)) { return hr; } hr = pStream->InitializeFromMemory((PBYTE)pMemory, size); if (FAILED(hr)) { return hr; } CComPtr<IWICBitmapDecoder> pDecoder; hr = pImagingFactory->CreateDecoderFromStream(pStream, nullptr, WICDecodeMetadataCacheOnDemand, &pDecoder); if (FAILED(hr)) { return hr; } CComPtr<IWICBitmapFrameDecode> pFrame; hr = pDecoder->GetFrame(0, &pFrame); if (FAILED(hr)) { return hr; } CComPtr<IWICFormatConverter> pConverter; hr = pImagingFactory->CreateFormatConverter(&pConverter); if (FAILED(hr)) { return hr; } hr = pConverter->Initialize(pFrame, GUID_WICPixelFormat32bppPRGBA, WICBitmapDitherTypeNone, nullptr, 0, WICBitmapPaletteTypeMedianCut); if (FAILED(hr)) { return hr; } hr = pRenderTarget->CreateBitmapFromWicBitmap(pConverter, nullptr, ppBitmap); return hr; }
static BOOL create_tmp_ini_file(HMODULE hm, WCHAR *ini_file) { HRSRC hrsrc; HGLOBAL hmem = NULL; DWORD rsrc_size, bytes_written; VOID *rsrc_data; HANDLE hf = INVALID_HANDLE_VALUE; if(!get_temp_ini_path(ini_file)) { ERR("Can't get temp ini file path\n"); goto error; } if(!(hrsrc = FindResourceW(hm, REGINST, REGINST))) { ERR("Can't find REGINST resource\n"); goto error; } rsrc_size = SizeofResource(hm, hrsrc); hmem = LoadResource(hm, hrsrc); rsrc_data = LockResource(hmem); if(!rsrc_data || !rsrc_size) { ERR("Can't load REGINST resource\n"); goto error; } if((hf = CreateFileW(ini_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ERR("Unable to create temp ini file\n"); goto error; } if(!WriteFile(hf, rsrc_data, rsrc_size, &bytes_written, NULL) || rsrc_size != bytes_written) { ERR("Write failed\n"); goto error; } FreeResource(hmem); CloseHandle(hf); return TRUE; error: if(hmem) FreeResource(hmem); if(hf != INVALID_HANDLE_VALUE) CloseHandle(hf); return FALSE; }
static void register_fake_dll( const WCHAR *name, const void *data, size_t size ) { static const WCHAR atlW[] = {'a','t','l','1','0','0','.','d','l','l',0}; static const WCHAR moduleW[] = {'M','O','D','U','L','E',0}; static const WCHAR regtypeW[] = {'W','I','N','E','_','R','E','G','I','S','T','R','Y',0}; static const WCHAR manifestW[] = {'W','I','N','E','_','M','A','N','I','F','E','S','T',0}; const IMAGE_RESOURCE_DIRECTORY *resdir; LDR_RESOURCE_INFO info; HRESULT hr = S_OK; HMODULE module = (HMODULE)((ULONG_PTR)data | 1); HRSRC rsrc; if ((rsrc = FindResourceW( module, manifestW, MAKEINTRESOURCEW(RT_MANIFEST) ))) { char *manifest = LoadResource( module, rsrc ); register_manifest( name, manifest, SizeofResource( module, rsrc ), data, size ); } info.Type = (ULONG_PTR)regtypeW; if (LdrFindResourceDirectory_U( module, &info, 1, &resdir )) return; if (!registrar) { HRESULT (WINAPI *pAtlCreateRegistrar)(IRegistrar**); HMODULE atl = LoadLibraryW( atlW ); if ((pAtlCreateRegistrar = (void *)GetProcAddress( atl, "AtlCreateRegistrar" ))) hr = pAtlCreateRegistrar( ®istrar ); else hr = E_NOINTERFACE; if (!registrar) { ERR( "failed to create IRegistrar: %x\n", hr ); return; } } TRACE( "registering %s\n", debugstr_w(name) ); IRegistrar_ClearReplacements( registrar ); IRegistrar_AddReplacement( registrar, moduleW, name ); EnumResourceNamesW( module, regtypeW, register_resource, (LONG_PTR)&hr ); if (FAILED(hr)) ERR( "failed to register %s: %x\n", debugstr_w(name), hr ); }
/*********************************************************************** * MSSTYLES_GetActiveThemeIni * * Retrieve the ini file for the selected color/style */ static PUXINI_FILE MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf) { static const WCHAR szFileResNamesResource[] = { 'F','I','L','E','R','E','S','N','A','M','E','S','\0' }; DWORD dwColorCount = 0; DWORD dwSizeCount = 0; DWORD dwColorNum = 0; DWORD dwSizeNum = 0; DWORD i; DWORD dwResourceIndex; LPWSTR tmp; HRSRC hrsc; /* Count the number of available colors & styles, and determine the index number of the color/style we are interested in */ tmp = tf->pszAvailColors; while(*tmp) { if(!lstrcmpiW(tf->pszSelectedColor, tmp)) dwColorNum = dwColorCount; tmp += lstrlenW(tmp)+1; dwColorCount++; } tmp = tf->pszAvailSizes; while(*tmp) { if(!lstrcmpiW(tf->pszSelectedSize, tmp)) dwSizeNum = dwSizeCount; tmp += lstrlenW(tmp)+1; dwSizeCount++; } if(!(hrsc = FindResourceW(tf->hTheme, MAKEINTRESOURCEW(1), szFileResNamesResource))) { TRACE("FILERESNAMES map not found\n"); return NULL; } tmp = LoadResource(tf->hTheme, hrsc); dwResourceIndex = (dwSizeCount * dwColorNum) + dwSizeNum; for(i=0; i < dwResourceIndex; i++) { tmp += lstrlenW(tmp)+1; } return UXINI_LoadINI(tf->hTheme, tmp); }
string InitialState::decode(int shaderResourceID){ HRSRC h = FindResourceW(NULL, MAKEINTRESOURCE(shaderResourceID), L"SHADER"); HGLOBAL hRes = LoadResource(NULL, h); char* resData = (char*)LockResource(hRes); int size = SizeofResource(NULL, h); char* newData = new char[size + 1]; memset(newData, 0, size + 1); memcpy(newData, resData, size + 1); string s(newData); delete []newData; ostringstream ostr; istringstream istr(s); Poco::Base64Decoder decoder(istr); Poco::StreamCopier::copyStream(decoder, ostr); return ostr.str(); }
static HRESULT resource_register(Registrar *This, LPCOLESTR resFileName, LPCOLESTR szID, LPCOLESTR szType, BOOL do_register) { HINSTANCE hins; HRSRC src; LPSTR regstra; LPWSTR regstrw; DWORD len, reslen; HRESULT hres; hins = LoadLibraryExW(resFileName, NULL, LOAD_LIBRARY_AS_DATAFILE); if(hins) { src = FindResourceW(hins, szID, szType); if(src) { regstra = (LPSTR)LoadResource(hins, src); reslen = SizeofResource(hins, src); if(regstra) { len = MultiByteToWideChar(CP_ACP, 0, regstra, reslen, NULL, 0)+1; regstrw = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len*sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, regstra, reslen, regstrw, -1); regstrw[len-1] = '\0'; hres = string_register(This, regstrw, do_register); HeapFree(GetProcessHeap(), 0, regstrw); }else { WARN("could not load resource\n"); hres = HRESULT_FROM_WIN32(GetLastError()); } }else { WARN("Could not find source\n"); hres = HRESULT_FROM_WIN32(GetLastError()); } FreeLibrary(hins); }else { WARN("Could not load resource file\n"); hres = HRESULT_FROM_WIN32(GetLastError()); } return hres; }