參考資訊:
http://www.winprog.org/tutorial/
http://winapi.freetechsecrets.com/win32/
https://github.com/gammasoft71/Examples_Win32
http://masm32.com/board/index.php?topic=3584.0
https://learn.microsoft.com/en-us/windows/win32/winmsg/window-styles
main.c
#include <stdio.h> #include <stdlib.h> #include <windows.h> #include "resource.h" void DropFile(HINSTANCE hInstance, DWORD dwID, TCHAR *pResType, TCHAR *pFileName) { DWORD dwRet = 0; HRSRC hRes = FindResource(hInstance, MAKEINTRESOURCE(dwID), pResType); HGLOBAL hRsc = LoadResource(hInstance, hRes); LPVOID lpRsc = (unsigned char *)LockResource(hRsc); DWORD dwFileSize = SizeofResource(hInstance, hRes); HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize); LPVOID pvData = GlobalLock(hGlobal); memcpy(pvData, lpRsc, dwFileSize); HANDLE hFile = CreateFile(pFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(hFile, pvData, dwFileSize, &dwRet, NULL); CloseHandle(hFile); GlobalUnlock(hGlobal); GlobalFree(hGlobal); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { DropFile(hInstance, IDD_ELF, "DATA", "tmp.exe"); DropFile(hInstance, IDD_LIB, "DATA", "tmp.exe.so"); ExitProcess(0); return 0; }
main.rc
#include <windows.h> #include "resource.h" IDD_ELF DATA "test.exe" IDD_LIB DATA "test.exe.so"
resource.h
#define IDD_ELF 101 #define IDD_LIB 102
編譯、執行
$ x86_64-w64-mingw32-windres main.rc -o main.res $ winegcc main.c main.res -o main $ wine ./main.exe