c++方法从c#dllimport调用返回0
c++ method returning 0 from c# dllimport call
我正在调用函数,得到的只是0,这是使用了多年的第三方软件,所以我知道它是正确的。这是c++头文件:
#ifdef __cplusplus
extern "C" {
#endif
int __stdcall initialise();
int __stdcall closedown();
int __stdcall WGS84ToLocal(double * lat, double * longt, int d);
int __stdcall LocalToWGS84(double * lat, double * longt, int d);
int __stdcall OSGB36ToOSGBGrid(double lat, double longt, double * east, double * north);
int __stdcall OSGBGridToOSGB36(double east, double north, double * lat, double * longt);
这是我的代码
class Program
{
public static double lon = 50.82011492;
public static double lat = 0.117981131;
public static double north = 50.82011492;
public static double east = 0.117981131;
public static Int32 OGB_M = 150;
public static int iErr = 0;
[DllImport("TTDatum3.Dll", EntryPoint = "WGS84ToLocal", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
public static extern Int32 WGS84ToLocal([In, Out]ref double lat, [In, Out] ref double lon, Int32 datum);
[DllImport("TTDatum3.Dll", EntryPoint="LocalToWGS84", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
public static extern Int32 LocalToWGS84([In,Out]ref double lat,[In,Out] ref double lon, Int32 datum);
[DllImport("TTDatum3.Dll", EntryPoint = "OSGB36ToOSGBGrid", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
public static extern Int32 OSGB36ToOSGBGrid( double lat, double lon, [In,Out] ref double east, [In,Out] ref double north);
[DllImport("TTDatum3.Dll", EntryPoint = "OSGBGridToOSGB36", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
public static extern Int32 OSGBGridToOSGB36(double east, double north, [In,Out] ref double lat,[In,Out] ref double lon);
public static void Main(string[] args)
{
iErr = OSGBGridToOSGB36(east, north, ref lon, ref lat);
Console.WriteLine(iErr);
iErr = LocalToWGS84(ref lon, ref lat, OGB_M);
Console.WriteLine(iErr);
}
在Main中,lat和lon的顺序与上面的方法相反。不知道这是否是你问题的原因,但这只是一个输入。
你预计iErr会回来什么?请修复该部分,然后提供更新。
相关文章:
- 从python中调用C++函数并获取返回值
- 返回递归调用和仅递归调用的区别
- 获取从C++中同一类中的构造函数调用的方法返回的值
- 调用CreateProcess()并获取字符串的返回值
- 使用JsonCpp将数据返回到带有pybind11的python会在python调用中产生Symbol not foun
- 将错误返回给调用方而不是立即在 C++ 中抛出错误是否是一种好的做法
- 返回指向对象的指针的函数调用是否为 prvalue?
- 如何安全地从 DLL 调用返回对象
- getopt_long_only第二次调用时返回 -1
- 如何构造可以调用和返回两种不同类型的模板
- 从返回 std::optional of std::vector 的函数中获取结果到调用方
- C++如何使函数返回调用它的对象
- 谷歌嘲笑!我的测试出错.默认情况下,呼叫将返回调用
- 仅使用有关类型而不是对象的信息返回调用的类型
- 从C#返回调用C++dll函数的值时发生访问冲突
- 问题5.3:访问/返回/调用动态创建的复选框(?)
- 按值返回调用复制构造函数或复制赋值运算符
- Tcl_Eval在出错时返回调用堆栈
- 按值返回调用复制构造函数
- 为什么在没有显式返回语句的情况下,递归返回调用会跳出堆栈