在C#中调用C ++函数 [英] calling c++ function in c#

查看:139
本文介绍了在C#中调用C ++函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,下面是代码示例.请建议我该怎么做才能将c ++编写的函数调用为c#函数.
预先谢谢你
C ++代码

Hi following is the code example. Please suggest what should I do to call c++ written function to a c# function.
Thank you in advance
c++ code

// type defs. for Graphic Gemms Code - see later

#define BYTE_IMAGE

#ifdef BYTE_IMAGE
typedef unsigned char kz_pixel_t;        /* for 8 bit-per-pixel images */
#define uiNR_OF_GREY (256)
#else
typedef unsigned short kz_pixel_t;       /* for 12 bit-per-pixel images (default) */
# define uiNR_OF_GREY (4096)
#endif
static int CLAHE (kz_pixel_t* pImage, unsigned int uiXRes, unsigned int uiYRes,
         kz_pixel_t Min, kz_pixel_t Max, unsigned int uiNrX, unsigned int uiNrY,
              unsigned int uiNrBins, float fCliplimit)
 {
...
...
}


C#调用代码


c# calling code

csharpfunction()
{
CLAHE((byte*)im, 0, 0, 0, 0, 0, 0, 0, 0.02);
}


我是图像实例. C ++代码获取字节格式的指针.如何将引用转换为我的图像对象以将函数作为字节*传递.


im is image instance. the c++ code gets the pointer in byte formate. how can I convert the referece to my image object to pass in the function as byte*.
Please help will be very thankful to you.

推荐答案

据我了解,您需要使用C ++代码创建一个程序集,然后使用以下代码:

http://msdn.microsoft.com/en-us/library/aa984739%28v = vs.71%29.aspx [ ^ ]

我不是100%知道这一点,但是在使用Windows DLL时,这就是我的工作.
From what I understand, you need to create an assembly with you C++ code and then use the following:

http://msdn.microsoft.com/en-us/library/aa984739%28v=vs.71%29.aspx[^]

Im not 100% sure of this, but when using the Windows DLLs thats what I do.


您可以做的是....
创建一个c ++代码的程序集,然后
通过在C#代码中实现属性在C#中使用它...

尝试使用DLLImport,然后提供已创建的DLL的名称,然后在C#代码中以这种方式引用该dll文件....

快乐编码...
What you can do is ....
Create a assembly of the c++ code and then
use it in C# by implementing Attributes in your C# code...

Try using DLLImport and then give the name of the DLL that you have created and then refer to that dll file this way in your C# code....

Happy Coding...


如果图像是位图,请使用msdn.microsoft.com/en-us/library/5ey6h79d.aspx只需将IntPtr替换为字节*.
If image is a bitmap use msdn.microsoft.com/en-us/library/5ey6h79d.aspx just replace IntPtr wíth byte*.


这篇关于在C#中调用C ++函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆