Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在C++;_C++_C_Function_Dll_Import - Fatal编程技术网

C++ 在C++;

C++ 在C++;,c++,c,function,dll,import,C++,C,Function,Dll,Import,我有一个名为swedll32.Dll的Dll文件,用于天文计算。 我已经在C#中导入了这些函数,并且正在使用它们。 但是在C++中,我尝试了各种方法来导入这些函数,但是它不起作用。 请某人演示一下如何导入一个函数,例如使用给定的名称 int-swe\u-calc\ut(双tjd\u-ut、int-ipl、int-iflag、双*xx、字符*serr), 哪里 世界时间朱利安日 ipl=车身编号 iflag=包含位标志的32位整数,该位标志指示所需的计算类型 xx=6个双精度数组,用于表示经度、纬

我有一个名为swedll32.Dll的Dll文件,用于天文计算。 我已经在C#中导入了这些函数,并且正在使用它们。 但是在C++中,我尝试了各种方法来导入这些函数,但是它不起作用。 请某人演示一下如何导入一个函数,例如使用给定的名称

int-swe\u-calc\ut(双tjd\u-ut、int-ipl、int-iflag、双*xx、字符*serr)
, 哪里 世界时间朱利安日 ipl=车身编号 iflag=包含位标志的32位整数,该位标志指示所需的计算类型

xx=6个双精度数组,用于表示经度、纬度、距离、速度(以长为单位)、速度(以纬度为单位)和速度(以距离为单位)


serr[256]=在发生错误时返回错误消息的字符串。

虽然以下内容仍然有效,但这可能也会有所帮助

其中包含从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; 
}

虽然以下内容仍然有效,但这也可能有所帮助

其中包含从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; 
}

在回答这个问题之前,我尝试了一下,但没有成功。稍后我将发布错误C2664“int(char*,int)”:无法将参数1从“const char[6]”转换为“char*”,错误C2065“returnintMyReturnVal”:未声明的标识符第一个错误表示您调用它是错误的。给我们看看你的实际代码。第二个是打字错误。在代码> >返回>代码>之后,必须有一个空间。在C++方法之前,你能看到堆栈溢出链接吗?我想这可能会解决你的问题。我发布的代码可能不是C++11+。错误的调用是
“hello”
是只读文本,编译器(正确地)将其等同于
常量
变量。我编辑了Horatius的例子来修正这个错误。在回答这个问题之前我尝试了一下,但是没有成功。稍后我将发布错误C2664“int(char*,int)”:无法将参数1从“const char[6]”转换为“char*”,错误C2065“returnintMyReturnVal”:未声明的标识符第一个错误表示您调用它是错误的。给我们看看你的实际代码。第二个是打字错误。在代码> >返回>代码>之后,必须有一个空间。在C++方法之前,你能看到堆栈溢出链接吗?我想这可能会解决你的问题。我发布的代码可能不是C++11+。错误的调用是
“hello”
是只读文本,编译器(正确地)将其等同于
常量
变量。我编辑了Horatius的示例以修复此错误。