參數,我發現在MSDN上這個例子中,我試圖使用它,但我有得到它的問題與參數合作(http://msdn.microsoft.com/en-us/library/ms686944(VS.85).aspx)動態調用外部DLL與CPP
下面是我想要的代碼使用和我試圖調用的方法有4個參數(CString a,CString b,CString c,BOOL d)。
extern "C" __declspec(dllexport) int __stdcall
ImportFile(CString a, CString b, CString c, BOOL d)
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(TEXT("C:\MyDll.dll"));
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "TestFunction");
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
(ProcAdd) (a, b, c, d);
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function
if (!fRunTimeLinkSuccess)
return -1;
return 0;
}
任何想法我在做什麼錯?提前致謝!!!
什麼不成?我懷疑調用LoadLibrary()作爲反斜槓不會在DLL的路徑中轉義。 – hmjd
你的代碼在哪裏失敗? GetProcAddress是否返回NULL? – Abhineet
我得到一個編譯錯誤C2197:'MYPROC':太多的調用參數 – spyter