在code :: blocks中创建一个dll文件并在powerpoint 2007中使用它

时间:2014-01-05 15:30:45

标签: c++ dll powerpoint codeblocks declare

我已经厌倦了在代码块中创建一个dll文件,然后在我的powerpoint演示文稿中使用它。在我下面提到的dll文件中,函数的参数包含( LPCSTR

 void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
MessageBoxA(0, sometext, "  DLL Message  ", MB_OK | MB_ICONINFORMATION);
}

在我的powerpoint文件中,我有

Declare Function DLL_EXPORT _
Lib "myfile.dll" _
Alias "SomeFunction" (???)  

当我运行文件时,我得到了 enter image description here 因为我不知道如何在powerpoint中定义我的函数的参数。我的意思是代码的这一部分:

 Alias "SomeFunction" (???)

1 个答案:

答案 0 :(得分:0)

您的C ++代码使用了错误的调用约定。它应该是:

__declspec(dllexport) void __stdcall SomeFunction(const char* sometext)

如果您愿意,可以使用DLL_EXPORTAPIENTRYLPCSTR等宏。但是,至少在你知道宏的含义之前,它可能更容易明确,如上所示。

您的函数的正确VBA声明是:

Declare Sub SomeFunction Lib "myfile.dll" (ByVal sometext As String)

然而,仅凭这一点还不够,因为你的功能将受到名称修饰和破坏。您可以使用dumpbin或Dependency Walker来查看导出函数的实际名称。然后你的VBA声明需要像这样修改:

Declare Sub SomeFunction Lib "myfile.dll" Alias "<DecoratedNameHere>" (ByVal sometext As String)