【问题标题】:Build a window application as a DLL library in Visual Studio 2019 C++在 Visual Studio 2019 C++ 中将窗口应用程序构建为 DLL 库
【发布时间】:2021-08-12 15:45:37
【问题描述】:

我需要帮助来解决问题,因为我没有足够的经验。我在 Visual Studio 2019 中创建了一个简单的 winodws,效果很好,但是我需要将其编译为 dll 库,以便第三方应用程序可以从该库中调用函数并绘制窗口。

我还没有计划与从 dll 调用此函数的应用程序进行任何交互 - 我只想显示一个窗口。

exe文件的实际代码很简单:

#include "MyForm.h"

#include <Windows.h>

using namespace windows2;


int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {

    Application::EnableVisualStyles();

    Application::SetCompatibleTextRenderingDefault(false);

    Application::Run(gcnew MyForm);

    return 0;
}

我尝试将其转换为 dll 文件,但编译时出现错误

BOOL APIENTRY DllMain(HMODULE hModule,
    DWORD  ul_reason_for_call,
    LPVOID lpReserved
)
{
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    Application::Run(gcnew MyForm);
    
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

严重性代码描述项目文件行抑制状态 警告 C4747 调用托管“DllMain”:托管代码可能无法运行 在加载程序锁定下,包括 DLL 入口点和从 DLL 入口点 windows2 C:\VIsualC\windows2\windows2\MyForm.cpp 1

谁能告诉我如何把这个窗口编译成一个dll?

The entire project in a zip archive for VS in its entirety

【问题讨论】:

    标签: c winapi


    【解决方案1】:

    在Visual Studio中,然后将Project-> Properties-> Configuration Properties-> General-> Configuration Type从Application (.exe)改为Dynamic Library (.dll)(别忘了选择对应的平台,你的项目是x64的。)

    【讨论】:

      猜你喜欢
      • 2020-02-19
      • 2019-12-22
      • 2021-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多