0

我想知道是否可以在某种库中创建一个入口点(main 或 winmain)。我正在尝试编写一个窗口管理器代码,我想将主函数放在一个库中,其中应用程序特定文件只定义了一些由 winmain 调用的外部函数(例如 extern render() 或 extern refresh())

我尝试自己执行此操作,但出现未定义入口点的错误。

4

2 回答 2

0

我只是花了最后几天试图为自己弄清楚这一点并且很幸运。

注意我只为静态库(.lib)尝试了这个

.lib 文件的问题是,如果您调用库的函数,它们只会被使用并连接到您的项目。现在最小项目的问题是您将只有一个主要功能。但这不是您的项目调用的,那么它与它有什么联系呢?

我的解决方案可能不是那么优雅,但它对我有用:创建一个 LibConnection.h,其中包含 lib.h 并从 lib.cpp 调用一个虚拟函数。在我看来,不好的部分是你必须将你的 lib.h 和 Connectionlib.h 包含到你的项目文件中。

像这样:

//Lib.h
void ConnectionFunction();

//Lib.cpp
int main(int argc, char* argv[])
{
    //do some stuff
}

//This function doesn't do anything but it is important 
//that you define it in your lib.h and declare it in your lib.cpp
void ConnectionFunction()
{
}

现在您有了一个基本库,并且必须创建一个像这样的连接文件:

//LibConnection.h
#include "Lib.h"
//now we call the connectionfunction
//remember non of this get really called but it makes possible connecting with your
//almost empty library
void Dummy()
{
     ConnectionFunction();
}

然后在你的空项目中:

//testapp.cpp
#include "LibConnection.h"
//remember to include the lib.h and the libconnection.h into your project files

void Foo()
{
    //this function doesn't get called but your project is running!
}

希望这可以帮助 :)

于 2013-05-11T07:16:38.630 回答
0

您可以使用项目中的模块定义文件从 DLL 中指定导出。

于 2011-08-18T20:14:23.397 回答