2014-01-05 71 views
0

我已經厭倦了在代碼塊中創建一個dll文件,然後在我的Powerpoint演示文稿中使用它。在我剛纔的函數的參數下面提到的DLL文件包含(LPCSTR在代碼塊中創建一個dll文件,並在PowerPoint中使用它2007

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" (???) 
+2

'聲明函數SomeFunction庫 「myfile.dll」 別名 「SomeFunction」(BYVAL sometext作爲字符串)'。還要確保讓你的本地'SomeFunction'使用* Pascal *調用約定。另請參見[聲明聲明的解析](http://msdn.microsoft.com/zh-cn/library/office/aa189024%28v=office.10%29.aspx)。 – IInspectable

+0

我已經使用ByVal sometext作爲字符串,但它沒有工作。但我不確定調用該函數。我只用於例如: DLL_EXPORT(「Hello World」) – Hamid

+1

DLL_EXPORT不是函數名稱。它是一個C++宏,可以爲該DLL的實現和客戶端使用相同的頭文件。它可能展開爲「extern」C「'。調用約定應該指定爲:'DLL_EXPORT void __stdcall SomeFunction(const LPCSTR sometext)'。 – IInspectable

回答

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) 
相關問題