是使用G++?

发布于 2025-02-12 15:20:35 字数 1068 浏览 0 评论 0原文

我正在尝试使用G ++将项目编译为DLL。我能够成功地编译.dll并将其导入我的C#项目。 However, I am using this tutorial: http://www.richelbilderbeek.nl/CppGppCreateDll.htm说您需要在为了创建DLL。

unitEntrypoint.cpp

//---------------------------------------------------------------------------
#include <windows.h>
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
  return 1;
}
//---------------------------------------------------------------------------
int WINAPI WinMain(      
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{  
  return 0;
}
//---------------------------------------------------------------------------

当我编译此文件外,除其他.cpp文件外,它确实可以。但是,当我排除此文件并且在任何地方都没有dllentrypoint或Winmain时,DLL也可以工作。我确实有要用“ #define dllexport __declspec(dllexport)”和“ extern” c“ C”导出的功能。

谁能告诉我 /为什么需要Winmain / dllentrypoint?

I am trying to compile a project into a dll using g++. I am able to compile the .dll and import it into my c# projects successfully. However, I am using this tutorial: http://www.richelbilderbeek.nl/CppGppCreateDll.htm which says you need to include a file such as the following in order to create a dll.

UnitEntryPoint.cpp

//---------------------------------------------------------------------------
#include <windows.h>
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
  return 1;
}
//---------------------------------------------------------------------------
int WINAPI WinMain(      
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{  
  return 0;
}
//---------------------------------------------------------------------------

When I compile this file in addition to the other .cpp files, it does work. However, the dll also works when I exclude this file and have no DllEntryPoint or WinMain anywhere. I do have the functions I want to export wrapped with "#define DllExport __declspec( dllexport )" and extern "C".

Can anyone tell me if / why a WinMain/DllEntryPoint is required?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无名指的心愿 2025-02-19 15:20:35

DllEntryPoint() is optional and provides a entry point/main function so to speak for the dll as in it's the first thing that is called upon during dll injection/loading.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文