用 Mingw gcc 编译 dll

#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;

}


编译命令:

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加入版本信息,如何使用导入导出库。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值