开发者

External entry point C++ (lib or dll)

I wondered if it was possible to 开发者_如何转开发create an entry point (main or winmain) in an library of some sorts. I'm trying to write a window manager code and I'd like to have the main function in a library with the application specific files just defining a few external functions called by winmain (such as extern render() or extern refresh())

I tried to do this on my own, but I'm getting an error of the entry point not being defined.


You can specify exports from your DLL using a Module-Definition file in your project.


I just spend the last couple of days trying to figure out this for myself and got lucky.

note I only tried this for static libraries (.lib)

The thing with .lib files is that they only get used and connected to your project if you call a function of the library. now the problem with a minimal project is that you will only have a main function. But this isn't called by your project so how is it connected with it then?

My solution, might not be that elegant but it works for me: create a LibConnection.h where you include the lib.h and call one dummy function from you lib.cpp. The bad part, in my opinion, is that you have to include your lib.h and your Connectionlib.h to your project files.

like this:

//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()
{
}

now you have a basic library and have to create a connection file like this:

//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();
}

and then in you empty project:

//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!
}

Hope this helps :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜