如何在没有 LIB 文件的情况下使用 C 中的 DLL 中的函数?我知道所有的函数原型(prototype)和它们的名字。
最佳答案
是的,你可以。你应该使用 GetProcAddress function,直接在DLL中调用函数,不涉及LIB
Processes explicitly linking to a DLL call GetProcAddress to obtain the address of an exported function in the DLL. You use the returned function pointer to call the DLL function.
引用上面链接的例子:
typedef UINT (CALLBACK* LPFNDLLFUNC1)(DWORD,UINT);
...
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer
DWORD dwParam1;
UINT uParam2, uReturnVal;
hDLL = LoadLibrary("MyDLL");
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,
"DLLFunc1");
if (!lpfnDllFunc1)
{
// handle the error
FreeLibrary(hDLL);
return SOME_ERROR_CODE;
}
else
{
// call the function
uReturnVal = lpfnDllFunc1(dwParam1, uParam2);
}
}
关于c - 在没有库的情况下在 C 中使用 DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11698228/