从C#DLL导入的char *指针 [英] DLL import char * pointer from C#

查看:425
本文介绍了从C#DLL导入的char *指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C ++中创建并在DLL中提取的功能。我需要在我的应用程序$ B $使用此函数B的功能如下:
INT SendText(无效* PControl则,字符* STEXT);

I have a function created in C++ and extracted in a DLL. I need to use this function in my application The function is as follows: int SendText(void* pControl, char* sText);

我如何使用这在我的C#代码。

How Can I use this in my C# code.

推荐答案

无效* 你可以使用的IntPtr

字符串将与的MarshalAs 属性工作:

for void* you can just use IntPtr ,
strings will work with the MarshalAs attribute:

[DllImport("MyDll.dll", CharSet = CharSet.Ansi)]
public static extern int SendText(IntPtr pControl, [MarshalAs(UnmanagedType.LPStr)] string sText);

这篇关于从C#DLL导入的char *指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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