等价的char *在C# [英] equivalent char* in C#

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

问题描述

我有一个用C ++编写的DLL。而且我P /调用到调用的函数。

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

我有这个C ++声明。

I have this c++ declaration.

int dll_registerAccount(char* username, char* password);



我已经这样做了dllimport的声明:

I have done this dllimport declaration:

[DllImport("pjsipDlld")]
static extern int dll_registerAccount(IntPtr username, IntPtr password);



请问我的DllImport是等同于C ++使用的IntPtr?

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

任何意见非常感谢,

推荐答案

这样做的C#方法是让封送处理的char * 的东西,而你用字符串工作:

The C# way of doing this is by letting the marshaler handle the char* stuff while you work with a string:

[DllImport("pjsipDlld")]
static extern int dll_registerAccount(
    [MarshalAs(UnmanagedType.LPStr)]string username,
    [MarshalAs(UnmanagedType.LPStr)]string password);



替换 LPSTR LPWSTR 如果你使用宽字符的工作。

Replace LPStr with LPWStr if you're working with wide chars.

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

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