| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 421 人关注过本帖
标题:[求助]c# 调用非托管代码的问题
只看楼主 加入收藏
sunrise520
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-1-12
收藏
 问题点数:0 回复次数:0 
[求助]c# 调用非托管代码的问题
c++生成的dll中有如下结构:
struct LPRImage
{
int nSize;
int nChannels;
int depth;
int nColorMode;
int dataOrder;
int origin;
int width;
int height;
int imageSize;
unsigned char *pData;
int step; SYSTEMTIME timeStamp;
};

另有如下函数:
__declspec(dllexport) long __stdcall LPRLoadImage( const char* pFilePath, LPRImage** ppImage );


请问如何转换成托管代码及如何调用?
我如下转换:

[StructLayout(LayoutKind.Sequential)]
public unsafe struct LPRImage
{
public int size;
public int nChannels;
public int depth; public int nColorMode;
public int dataOrder;
public int origin;
public int width;
public int height;
public int imageSize;
[MarshalAs(UnmanagedType.ByValArray)]
public byte[] pData;
public int step;
public SYSTEMTIME timeStamp;
}

public static extern int LPRLoadImage([System.Runtime.InteropServices.InAttribute()] [MarshalAsAttribute(UnmanagedType.LPStr)] string pFilePath, ref System.IntPtr ppImage);

现在不知道如何调用,因为ppImage是一个指向结构体指针的指针,请高手指点?


是否可以给一个调用的例子吗?我看了一下dll提供者的c++的调用示例,实例如下:

// 读取图片文件
CString fileName = m_imgPath + "\\" + fileNames[i];
LPRImage* pImage = NULL;
LPRRESULT lr = LPRLoadImage( fileName, &pImage );


高手根据如上实例,能否给出一个相对完整的吃c#调用示例吗?
搜索更多相关主题的帖子: 托管 代码 
2010-01-12 11:32
快速回复:[求助]c# 调用非托管代码的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028364 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved