#include <windows.h>
__declspec(dllexport) int __cdecl Add(int a, int b)
{
return (a + b);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
MessageBoxA(NULL, "hello", "world", 0);
/* Code path executed when DLL is loaded into a process's address space. */
break;
case DLL_THREAD_ATTACH:
/* Code path executed when a new thread is created within the process. */
break;
case DLL_THREAD_DETACH:
/* Code path executed when a thread within the process has exited *cleanly*. */
break;
case DLL_PROCESS_DETACH:
/* Code path executed when DLL is unloaded from a process's address space. */
break;
}
return TRUE;
__declspec(dllexport) int __cdecl Add(int a, int b)
{
return (a + b);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
MessageBoxA(NULL, "hello", "world", 0);
/* Code path executed when DLL is loaded into a process's address space. */
break;
case DLL_THREAD_ATTACH:
/* Code path executed when a new thread is created within the process. */
break;
case DLL_THREAD_DETACH:
/* Code path executed when a thread within the process has exited *cleanly*. */
break;
case DLL_PROCESS_DETACH:
/* Code path executed when DLL is unloaded from a process's address space. */
break;
}
return TRUE;
}
编译命令:
gcc -c -o add_basic.o add_basic.c
gcc -o add_basic.dll -s -shared add_basic.o -Wl,--subsystem,windows
转载http://www.transmissionzero.co.uk/computing/building-dlls-with-mingw/
还有不少编程编译的细节可以在上面的网址上找到:比如给DLL加入版本信息,如何使用导入导出库。