静态函数的 DLL 导出

发布于 2024-09-04 20:17:21 字数 551 浏览 12 评论 0原文

我有以下静态函数:

static inline HandVal
              StdDeck_StdRules_EVAL_N( StdDeck_CardMask cards, int n_cards )

我可以在 DLL 中导出该函数吗?如果是这样,怎么办?

谢谢,

Mike

背景信息:

我这样做是因为原始源代码附带一个 VS 项目,旨在编译为静态 (.lib) 库。为了使用 ctypes/Python,我将项目转换为 DLL。

我以 DLL 的形式启动了一个 VS 项目并导入了原始源代码。该项目构建为 DLL,但没有导出任何函数(包括上面列出的函数)(通过源代码中缺少 dllexport 和 DLL Export Viewer 等工具来确认)。我尝试遵循此处的一般建议(在header)无济于事...功能似乎仍然没有被导出。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪我终i 2024-09-11 20:17:21

您不能从 DLL 中导出该函数。静态函数相当于该文件的私有函数。

您可以在文件中创建一个调用它的方法并将其导出。

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.

你没皮卡萌 2024-09-11 20:17:21

通过使用静态内联定义函数,您可以有效地保证它仅存在于包含该定义的模块中。

要么编辑每个文件以删除静态内联(这可能会破坏),要么更改所有内容以使用预处理器指令,该指令将允许您具有:

#define MYAPI static inline

#define MYAPI __declspec(dllexport)

然后

MYAPI HandVal StdDeck_StdRules_EVAL_N( StdDeck_CardMask cards, int n_cards )

或将一组包装器构建为单独的模块

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

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文