开发者

Call static lib function embedded in DLL

开发者 https://www.devze.com 2023-04-13 09:29 出处:网络
Let\'s say the following architecture: A s开发者_JAVA百科tatic library is used/linked within a DLL

Let's say the following architecture:

  • A s开发者_JAVA百科tatic library is used/linked within a DLL
  • The DLL is loaded (either implicitly or explicitly) by an executable

Is it possible from the executable code to access code of the static library without relinking it explicitly nor inserting wrapper functions in the DLL? In other terms, I am looking for a way to make a dll export of dependant static library code.


Given your constraints, the answer is no.

The reason is that the executable doesn't have any visibility into the dependencies or "call-ees" of the DLL. As far as the executable is concerned, he's just knows about the DLL itself: at link time, the executable knows only about those exports it is consuming from the DLL. He's going to LoadLibrary() against the DLL (which will fail if the dependencies of said DLL aren't resolvable), then call the exports of said DLL.

If you can't statically link with the library used by the DLL for some reason, another approach is to wrap the calls to said static library. This can be a pain of there are lots of calls, but there are automated tools which others have created to help. In particular I've used this before to create a wrapper for a DLL which exported hundreds of functions when I wanted to intercept a particular one: http://www.codeproject.com/KB/DLL/CreateYourProxyDLLs.aspx


The answer may easily be: Yes.

The only requirement is:

In your static LIB file you must define __declspec(dllexport) for all what you want to export. When you then include this LIB file into your DLL project all the functions that you have declared as __declspec(dllexport) will be automatically DLL Exports and can be accessed from your Exe.

0

精彩评论

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

关注公众号