我不太瞭解DLL,所以我構建了一個簡單的示例,我可以幫助解答一些問題。我在這裏有一個簡單的dll。如何在運行時鏈接期間從我的DLL中調用函數?
// HelloDLL.cpp
#include "stdafx.h"
int __declspec(dllexport) Hello(int x, int y);
int Hello(int x, int y)
{
return (x + y);
}
我怎麼會叫Hello(int x, int y)
功能在一個單獨的程序,一旦我已經運行LoadLibrary()
?以下是我迄今爲止的一個粗略佈局,但我不確定我擁有的是否正確,如果是,請繼續。
// UsingHelloDLL.cpp
#include "stdafx.h"
#include <windows.h>
int main(void)
{
HINSTANCE hinstLib;
// Get the dll
hinstLib = LoadLibrary(TEXT("HelloDLL.dll"));
// If we got the dll, then get the function
if (hinstLib != NULL)
{
//
// code to handle function call goes here.
//
// Free the dll when we're done
FreeLibrary(hinstLib);
}
// else print a message saying we weren't able to get the dll
printf("Could not load HelloDLL.dll\n");
return 0;
}
任何人都可以幫我瞭解如何處理函數調用?任何特殊情況下,我應該知道未來使用dll的情況?
'GetProcAddress的()'會是你要找的內容;它記錄在[MSDN](http://msdn.microsoft.com)。 –