开发者

Static Linking Function in a DLL Project

开发者 https://www.devze.com 2023-01-04 06:19 出处:网络
I don\'t know why but I thought I could statically link a function from an Import Library.It would seem I am the only one who has ever tried because I can\'t for the life of me find a similar post.Is

I don't know why but I thought I could statically link a function from an Import Library. It would seem I am the only one who has ever tried because I can't for the life of me find a similar post. Is there a way to selectively static link functions from a dynamically linked project without creating a new project and/or recompiling it as static? The module itself communicates over an interface and I'm not really big on exporting functions. I just want to static link the code to create the object....

how bad would it be to 开发者_如何转开发turn this into a macro?

IClassFactory* CF = NULL;
hr = CoGetClassObject (
    CLSID_CF,
    CLSCTX_INPROC_SERVER,
    NULL,
    IID_IClassFactory,
    (void**)&CF );

Interface* Instance = NULL;
hr = CF->CreateInstance (
    NULL,
    IID_Interface,
    (void**)&Instance );


Static linking and import libraries dont go together. An import library is used for helping the linker figure out that the functions you call are in a DLL.

If you want static linking (assuming you have the code available) then reconfigure-recompile the DLL project to a static library.


If this is your own project (or you have source code and are willing to modify it), you could use inline functions for the functions you don't want to dynamically link.

0

精彩评论

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