C#调用的dll中函数返回值问题
先上代码
头文件
//head begin
//dll_01.h
typedef struct point
{
double X;
double Y;
}Point;
Point * CaculateTrack( unsigned int step );
//head end
源文件
//.cpp
//dll_01.cpp
Point * CaculateTrack( unsigned int step )
{
Point * pTrackPoint = NULL;
pTrackPoint = (Point*)calloc( step + 1, sizeof( Point ) );
g_TrackX = (double*)calloc( step, sizeof( double ) );
g_TrackY = (double*)calloc( step, sizeof( double ) );
for( unsigned int i = 1; i <= step; i++ )
{
pTrackPoint[ i ].X = g_TrackX[ i ] = g_TrackX[ i - 1 ] + i;
pTrackPoint[ i ].Y = g_TrackY[ i ] = g_TrackY[ i - 1 ] + i + 1;
}
return pTrackPoint;
}
//end .cpp
//C#中的声明部分
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct point
{
/// double
public double X;
/// double
public double Y;
}
[System.Runtime.InteropServices.DllImportAttribute("Dll_01.dll", EntryPoint = "iNEMO_CaculateTrack")]
public static extern System.IntPtr CaculateTrack( uint step) ;
//end C#
就这样,返回值变为了intptr类型,请问大家我想要取出调用函数中的返回值怎么样对intptr进行操作呢
头文件
//head begin
//dll_01.h
typedef struct point
{
double X;
double Y;
}Point;
Point * CaculateTrack( unsigned int step );
//head end
源文件
//.cpp
//dll_01.cpp
Point * CaculateTrack( unsigned int step )
{
Point * pTrackPoint = NULL;
pTrackPoint = (Point*)calloc( step + 1, sizeof( Point ) );
g_TrackX = (double*)calloc( step, sizeof( double ) );
g_TrackY = (double*)calloc( step, sizeof( double ) );
for( unsigned int i = 1; i <= step; i++ )
{
pTrackPoint[ i ].X = g_TrackX[ i ] = g_TrackX[ i - 1 ] + i;
pTrackPoint[ i ].Y = g_TrackY[ i ] = g_TrackY[ i - 1 ] + i + 1;
}
return pTrackPoint;
}
//end .cpp
//C#中的声明部分
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct point
{
/// double
public double X;
/// double
public double Y;
}
[System.Runtime.InteropServices.DllImportAttribute("Dll_01.dll", EntryPoint = "iNEMO_CaculateTrack")]
public static extern System.IntPtr CaculateTrack( uint step) ;
//end C#
就这样,返回值变为了intptr类型,请问大家我想要取出调用函数中的返回值怎么样对intptr进行操作呢
...全文
相关推荐
C#调用C++编写的DLL函数各种参数传递问题
1. 不返回值的参数 C++ 原型: bool SendNewSms(char *szTel, char *szMessage); C#引用; [DllImport( CdmaCard.dll,EntryPoint=SendNewSms)] public static extern bool SendNewSms(string phone,string msg); 2. 带返回值(char *) C++原型: BOOL GetCardErrorMessage(char *szErrorMessage , int
c# 调用C++编写 的DLL函数各种参数传递问题。
c# 调用C++编写 的DLL函数各种参数传递问题。数据处理问题等等。
yolov3 dll c# 调用
yolov3 源码编译dll ,c#调用 ,权重现在不能共享, 自己网上寻找。
c#中如何调用外部DLL
每种编程语言调用DLL的方法都不尽相同,在此只对用C#调用DLL的方法进行介绍。
C#调用C/C++ Dll中函数实例代码
实例代码说明如何在托管的C#代码中调用非托管的Win32 API或者自己用C/C++写的Dll中的函数,以及如何传递输入、输出字符串参数,结构类型参数等问题。


进程/线程/DLL
