简体   繁体   中英

Build a window application as a DLL library in Visual Studio 2019 C++

I need help in solving a problem, as I simply do not have enough experience. I created a simple winodws in Visual Studio 2019 and it works well, but I need to compile it as a dll library so that a third-party application can call a function from this library and the window is drawn.

I don't plan any interaction with the application that called this function from the dll yet - I just want to show a window.

The actual code for the exe file is quite simple:

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

I tried to convert it to a dll file but when compiling I get errors

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

Severity Code Description Project File Line Suppression State Warning C4747 Calling managed 'DllMain': Managed code may not be run under loader lock, including the DLL entrypoint and calls reached from the DLL entrypoint windows2 C:\VIsualC\windows2\windows2\MyForm.cpp 1

Can someone tell me how to compile this window into a dll?

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

In Visual Studio, then change Project-> Properties-> Configuration Properties-> General-> Configuration Type from Application (.exe) to Dynamic Library (.dll) (Don't forget to choose the corresponding platform, your project is x64.)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM