C#.net中的dllimport,(C ++ DLL) [英] dllimport in c# .net ,(c++ dll)

查看:57
本文介绍了C#.net中的dllimport,(C ++ DLL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C ++编写的dll.我正在调用这些函数.

我有这个C ++声明.

1-

I have a dll that is written in c++. And I am p/invoking to call the functions.

I have this c++ declaration.

1-

__declspec(dllexport) bool dll_registerAccount(bool spot, unsigned char* Key,int Length, unsigned char* Source, unsigned char* Target);



2-



2-

__declspec(dllexport) unsigned char MD5(unsigned char *InPut,uint4 Input_Length,unsigned char *OutPut);




我已经完成了dllimport声明:

1-




I have done this dllimport declaration:

1-

[DllImport("nvsreg.dll", CallingConvention = CallingConvention.Cdecl)]

public static extern bool dll_registerAccount(bool spot, [MarshalAs(UnmanagedType.LPStr)]string Key, int Length, [MarshalAs(UnmanagedType.LPStr)]string Source, [MarshalAs(UnmanagedType.LPStr)]string Target);



2-



2-

[DllImport("nvsreg.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern string MD5([MarshalAs(UnmanagedType.LPStr)]string InPut,long Input_Length, [MarshalAs(UnmanagedType.LPStr)]string OutPut);





我的DllImport是否等效于c ++?

请告诉我什么是dllimport声明.

非常感谢您提供任何建议,





Would my DllImport be the equivalent to the c++ ?

please tell me what would be dllimport declaration.

Many thanks for any advice,

推荐答案

您在C#端声明了调用约定为Cdecl.这是C ++的默认调用约定,但是,您也可以使用对其进行声明. __cdecl 关键字(在C ++中).

You declared (in the C# side) that the calling convention is Cdecl. This is the default calling convention for C++ but, you can also declare it using the __cdecl keyword (in the C++ side).

(对于C ++函数)实际入口点的名称与函数的名称不同,以便启用关键字声明函数.

The actual entry-point''s (for C++ functions) name is different than the function''s name, in order to enable Function Overloading. If you want the entry-point''s name to be as same as the function''s name you can declare the function with the extern "C" keyword.

类似的东西:

Something like:

extern "C" __declspec(dllexport) bool __cdecl dll_registerAccount(bool spot, unsigned char* Key,int Length, unsigned char* Source, unsigned char* Target);

另一个问题:声明第二个函数(MD5)返回unsigned char,它不是C#端的string ...

Another issue: The second function (MD5) is declared to return unsigned char which is not a string in the C# side...


这篇关于C#.net中的dllimport,(C ++ DLL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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