c# 外部引用c++非托管DLL问题,十万火急,数据结构int32_t

abutwang 2011-09-01 01:16:45
global 文件

#ifndef _GLOBAL_H_
#define _GLOBAL_H_

#ifndef int32_t
#define int32_t int
#endif

#ifndef float32_t
#define float32_t float
#endif

#endif

========================================
#ifndef _DSP_H_
#define _DSP_H_

#include "global.h"

#ifdef WIN32
#ifdef _USRDLL
#define DSP_API __declspec(dllexport)
#else
#define DSP_API
#endif
#else
#define DSP_API
#endif

#ifdef __cplusplus
extern "C"
{
#endif

DSP_API void *BPFilter_Create(int32_t n, float32_t fs, float32_t fl, float32_t fh);
DSP_API void BPFilter_Free(void **handle);
#ifdef __cplusplus
}
#endif

#endif


请问
1:c#外部引用BPFilter_Create、BPFilter_Free代码如何下,
2:如何处理int32_t、float32_t这种结构
3:还有当有前缀是const float32_t fs如何处理


...全文
125 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuyongxu 2011-09-01
  • 打赏
  • 举报
回复
帮顶一下!!
sdl2005lyx 2011-09-01
  • 打赏
  • 举报
回复
楼主,2和3,这样给你解释:
C++的#define宏定义,只是个别名而已,你只须考虑它对应的原始类型即可。
即float32_t,考虑float本身,int32_t考虑int本身。

DSP_API void *BPFilter_Create(int32_t n, float32_t fs, float32_t fl, float32_t fh);

对应声明:
[DllImport("xxx.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
public static extern IntPtr BPFilter_Create(int, float fs, float fl, float fh);

“const float32_t fs如何处理”,编译器强调是输入参数,不允许修改,对应C#
[In]float fs //[In]为参数封送的方向属性,指示CLR不进行回传拷贝。

最后一个问题:
“DSP_API void BPFilter_Free(void **handle);”
问一下,C++那边是要释放多个handle吗,一般会写成:
DSP_API void BPFilter_Free(void *handle);”

那么C#的映射:
[DllImport("xxx.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
public static extern void BPFilter_Free(IntPtr handle);

你先确定一下。。。


abutwang 2011-09-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wknight_it 的回复:]
http://blog.csdn.net/xqf222/article/details/5877795
[/Quote]

也就是说float32_t,就当成float处理,再。net库里就是:System.Single咯
风骑士之怒 2011-09-01
  • 打赏
  • 举报
回复
http://blog.csdn.net/xqf222/article/details/5877795
abutwang 2011-09-01
  • 打赏
  • 举报
回复
没人遇到过么
abutwang 2011-09-01
  • 打赏
  • 举报
回复
自顶下

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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