以下的代碼在EXE中,執行無誤。可是在DLL中FindResource返回的值就為0了,我用::GetLastError(),得出的值是1813,也就是取不到資源,這是為什麼?
BOOL ExtractFile(char *szZlibFile,DWORD dwRID) { HANDLE hFile = NULL ; HRSRC hRsrc = NULL ; HGLOBAL hGlobal = NULL ; DWORD dwResSize = 0, dwBytesWrite = 0, dwBytesRead = 0; PVOID pRsrc = NULL, pConfigEncrypt = NULL; hRsrc = FindResource( NULL, MAKEINTRESOURCE(dwRID), "ZLIB"); if(hRsrc == NULL) { MyDbgPrint("[ExtractFile] Locate Resource Error: %d\n", GetLastError()); return FALSE; } dwResSize = SizeofResource(NULL, hRsrc); hGlobal = LoadResource(NULL, hRsrc); if(hGlobal == NULL) { MyDbgPrint("[ExtractFile] Load Resource Error: %d\n", GetLastError()); return FALSE; } pRsrc = LockResource(hGlobal); hFile = CreateFile( szZlibFile , GENERIC_ALL, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if(hFile == INVALID_HANDLE_VALUE) { MyDbgPrint("[ExtractFile] Create %s File Error: %d\n", szZlibFile , GetLastError()); return FALSE; } if( WriteFile( hFile, pRsrc, dwResSize, &dwBytesWrite, NULL) == FALSE) { MyDbgPrint("[ExtractFile] Write %s File Error: %d\n", szZlibFile , GetLastError()); return FALSE; } CloseHandle(hFile); MyDbgPrint("[ExtractFile] Write %s File Success\n",szZlibFile); return TRUE; }