c - 在没有库的情况下在 C 中使用 DLL

标签 c dll

如何在没有 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/

相关文章:

c++ - 是否可以在不同时间使用恒定的内存地址值?

c - 获取 ELF 二进制文件的加载地址,dlopen 未按预期工作

c - openCV 在 C 中获取子图像

c - While 循环中的 FIFO 卡住并等待读取

c# - 从生成的 C 代码创建 dll 库

asp.net - 模块 ".dll"已加载,但未找到入口点

c++ - 无法在 CMake 中创建动态库并将其链接到另一个动态库?

c - 如何从用户空间使用 ioremap() api 在 uClinux 中读写 SPI Flash 存储器上的寄存器

c# - 如何将 C++ COM DLL 'flatten' 转换为标准导出方法? (由 c# 使用)

python - 使用 IronPython 覆盖 DLL 函数