我有一个名为 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/