DLL export of a static function

天大地大妈咪最大 提交于 2019-12-01 06:29:45

问题


I have the following static function:

static inline HandVal
              StdDeck_StdRules_EVAL_N( StdDeck_CardMask cards, int n_cards )

Can I export this function in a DLL? If so, how?

Thanks,

Mike

Background information:

I'm doing this because the original source code came with a VS project designed to compile as a static (.lib) library. In order to use ctypes/Python, I'm converting the project to a DLL.

I started a VS project as a DLL and imported the original source code. The project builds into a DLL, but none of the functions (including functions such as the one listed above) are exported (as confirmed by both the absence of dllexport in the source code and tools such as DLL Export Viewer). I tried to follow the general advice here (create an exportable wrapper function within the header) to no avail...functions still don't appear to be exported.


回答1:


You may not export that function from a DLL. static functions are equivalent to private to that file.

You can create a method in the file that calls it and export that.




回答2:


By defining a function with static and inline you are effectively guaranteeing that it will be only in the modules that includes the definition.

Either edit each file to remove the static inline (which might break) or change everything to use a PreProcessor directive that will allow you to have either:

#define MYAPI static inline

or

#define MYAPI __declspec(dllexport)

and then

MYAPI HandVal StdDeck_StdRules_EVAL_N( StdDeck_CardMask cards, int n_cards )

or build a set of wrappers as a seperate module which does

__declspec(dllexport) HandVal Public_StdDeck_StdRules_EVAL_N( StdDeck_CardMask cards, int n_cards )
{
     return StdDeck_StdRules_EVAL_N(cards, n_cards);
}


来源:https://stackoverflow.com/questions/2984316/dll-export-of-a-static-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!