c++ - 在 C++ 中导入一个 dll 函数

标签 c++ c function dll import

我有一个名为 swedll32.dll 的 Dll 文件,用于天文计算。 我已经在 C# 中导入了这些函数并正在使用它们。 但在 C++ 中,我尝试了所有可能的方法来导入这些函数,但它不起作用。

有人可以演示如何使用给定名称导入函数吗?

int swe_calc_ut(double tjd_ut,int ipl,int iflag,double* xx,char* serr), 在哪里 tjd_ut =儒略日,世界时 ipl = body 号码 iflag = 一个 32 位整数,包含指示需要哪种计算的位标志。

xx=经度、纬度、距离、经度速度、纬度速度和距离速度的 6 个 double 组。

serr[256] =出现错误时返回错误信息的字符串。

最佳答案

虽然以下内容仍然有效,但此 stack overflow answer也可能有所帮助。

article包含一个从 DLL 导入函数的示例,但要点是:

int CallMyDLL(void){ 

  /* get handle to dll */ 
 HINSTANCE hGetProcIDDLL = LoadLibrary("C:\\MyDLL.dll"); 

 /* get pointer to the function in the dll*/ 
 FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"MyFunction"); 

 /* 
  Define the Function in the DLL for reuse. This is just prototyping the dll's 
  function. 
  A mock of it. Use "stdcall" for maximum compatibility. 
 */ 
 typedef int (__stdcall * pICFUNC)(char *, int); 

 pICFUNC MyFunction; 
 MyFunction = pICFUNC(lpfnGetProcessID); 

 /* The actual call to the function contained in the dll */ 
 char s[]= "hello";
 int intMyReturnVal = MyFunction(s, 5); 

 /* Release the Dll */ 
 FreeLibrary(hGetProcIDDLL); 

 /* The return val from the dll */ 
  return intMyReturnVal; 
}

关于c++ - 在 C++ 中导入一个 dll 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57020401/

相关文章:

c++ - 数组如何与条件运算符一起使用?

c++ - 算术运算和编译器优化

c++ - Long 变量到 char 数组

c - 在 Linux C 程序中的非特权套接字(非原始套接字)上设置 TCP 选项

C语言中字符转二进制

javascript - 无法在函数内嵌套 Javascript 函数

java数学函数f(x)

c++ - QCryptographicHash 对于同一字符串给出不同的结果

javascript - 返回函数表达式而不是结果

c++ - 类中的指针初始化