如何在运行时构建DLL?

时间:2017-03-11 01:22:59

标签: c++ dll build runtime compiled

问题说明

我有一个在运行时加载dll的应用程序。我希望允许用户在应用程序运行时更改该dll中的代码。当用户单击应用程序中的“编译”按钮时,它将释放来自dll的所有数据。释放dll后,应用程序将重建dll。本质上是作为一个 运行时编译程序。

理想实施

void ReCompile()
{
    //hDLL contains dll that was already loaded.
    FreeLibrary(hDLL);

    //code to rebuild MyDll.DLL would go here.

    LPCWSTR dll = L"MyDll.dll";
    hDLL = LoadLibrary(dll);
}

这当前有效,我只需要知道如何通过代码重建dll,使其感觉更加流畅和直观。

当前实施

void Free() 
{
    FreeLibrary(hDLL);
}

//I go into my other visual studio that's running and press the build button myself.

void ReloadDll()
{
    LPCWSTR dll = L"MyDll.dll";
    hDLL = LoadLibrary(dll);
}

1 个答案:

答案 0 :(得分:0)

归功于TheUndeadFish。

void ReCompile()
{
    //hDLL contains dll that was already loaded.
    FreeLibrary(hDLL);

    //my solution
    system("msbuild \"D:\\Neumont\\Imagine\\RenderEngine\\Imagine.sln\" /property:Configuration=Debug /property:platform=Win32 ");
    //general purpose
    system("msbuild <path to your sln> /property:Configuration=build /property:platform=YourPlatform");


    LPCWSTR dll = L"MyDll.dll";
    hDLL = LoadLibrary(dll);
}

您需要将msbuild路径添加到环境变量中。我的位于C:\ Program Files(x86)\ MSBuild \ 14.0 \ Bin。你可能要运行vcvars32.bat

在运行{@ 3}}

中运行时构建DLL的视频