C#调用的dll中函数返回值问题

dxpfigo 2012-04-13 01:33:15
先上代码

头文件
//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进行操作呢
...全文
148 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Red_angelX 2012-04-18
  • 打赏
  • 举报
回复
unsafe
{
}
wzaen 2012-04-18
  • 打赏
  • 举报
回复
[return: MarshalAs(UnmanagedType.***)]
里面有LPArray, LPStruct之类的东东,没试过,仅供参考吧。
ouyh12345 2012-04-13
  • 打赏
  • 举报
回复
再包装一下dll,让在参数中返回
向立天 2012-04-13
  • 打赏
  • 举报
回复
这个问题最好去C#版块问问

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧