调用从C#C ++函数 [英] Call a C++ function from C#

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

问题描述

我有2个C ++动态链接库。其中一个包含以下功能:

I have 2 C++ DLLs. One of them contains the following function:

void init(const unsigned char* initData, const unsigned char* key)

另一种包含此功能:

BYTE* encrypt(BYTE *inOut, UINT inputSize, BYTE *secretKey, UINT secretKeySize).



有没有一种方法调用从C#这2个功能?我知道你可以使用函数[DllImport]在C#中调用C ++函数,但指针给了我一个困难时期。

Is there a way to call these 2 functions from C#? I know you can use [DllImport] in C# to call C++ functions, but the pointers are giving me a hard time.

任何帮助,将不胜感激!

Any help would be appreciated!

推荐答案

是的,你可以从C#假设它们被包裹在外部的C部分称这两种。我不能给你一个详细的PInvoke签名,因为我没有对下面就如何将各种参数之间的关联,但工作的足够信息。

Yes, you can call both of these from C# assuming that they are wrapped in extern "C" sections. I can't give you a detailed PInvoke signature because I don't have enough information on how the various parameters are related but the following will work.

[DllImport("yourdllName.dll")]
public static extern void init(IntPtr initData, IntPtr key);

[DllImport("yourdllName.dll")]
public static extern IntPtr encrpyt(IntPtr inout, unsigned inuputSize, IntPtr key, unsigned secretKeySize);



那将使我们能够创造更加美好的签名信息小品

Pieces of information that would allow us to create a better signature


  1. 是加密的收益分配的内存?

  2. 如果#1是真实的,是如何分配的内存

  3. 您能否给的参数如何工作的基本描述?

  4. 我猜,所有的指针值的代表元素,而不是一个单一的元素是否正确?

  1. Is the return of encrypt allocated memory?
  2. If #1 is true, how is the memory allocated
  3. Can you give a basic description on how the parameters work?
  4. I'm guessing that all of the pointer values represents arrays / groups of elements instead of a single element correct?

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

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