开发者

DLL export of a static function

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.


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.


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


As Romain said, a static function is private to the file and you can't export it. You can try:

  1. export the entire class
  2. try make the static method a static inline method. The compiler is free to inline such a function at the call sites (which is more likely to happen the less those call sites are, among other factors) (which is what you've done already, so I'm guessing this didn't work in your case 12 years ago. :D)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜