在DLL导入的c#中使用C语言方法 [英] Use C language Method in c# from DLL import

查看:187
本文介绍了在DLL导入的c#中使用C语言方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c中使用c语言方法#



How i can use c language method in c#

int encrypt(unsigned char *key, unsigned char *dataToEncrypt,
    unsigned int in_data_len, unsigned char *out_data,
    unsigned int *out_data_len)





如何在c#中为dll导入设计方法我声明这个





how i can design method in c# for with dll import i declare this

const string _dllLocation = @"E:\EPS-Doc\Crypto Kernel\EMC Corporation\cksetup\cklibrary\ck.dll";
        [DllImport(_dllLocation)]
        public static extern unsafe int encrypt(byte* key, byte* dataToEncrypt, uint in_data_len, byte* out_data, uint* out_data_len);





但是如何我可以实现这个



but how i can implement this

推荐答案

委托是添加到C#的新东西,我不相信你想要使用它。如果你有任何方法,它们就像指针一样可用于方法等。



其次,在C#中也没有 unsigned char 但是,您可以以某种方式将数据转换为字节数组,然后对其进行处理。



您正在展示的代码的第二部分是可以的。 C#基于C ++,因此它包含了C ++所具有的大部分内容,C#中的指针也可以。你也可以使用指针,看看这里: http://msdn.microsoft.com/en-us /library/y31yhkeb.aspx [ ^ ]



最后一件事,是否有任何错误?因为我觉得很好!
delegates are a new thing added to C#, which I don't believe you want to use. They're like pointers and can be used for methods etc to work on if you're having any.

Secondly, in C# there is also no unsigned char however, you can somehow convert the data to byte array and then work on it.

The second part of the code, that you're showing, is OK. C# is based on C++, so it includes most of the stuff C++ has, pointers are also OK in C#. You can use pointers too, have a look here: http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx[^]

Last thing, did it give any error? Because I think it is fine!


这篇关于在DLL导入的c#中使用C语言方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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