永发信息网

c++中char * 转换为c#该转成什么类型?

答案:6  悬赏:40  手机版
解决时间 2021-11-12 09:49
  • 提问者网友:却不属于对方
  • 2021-11-11 20:50
c++中char * 转换为c#该转成什么类型?
最佳答案
  • 五星知识达人网友:不甚了了
  • 2021-11-11 22:24
c#代码
class CITICs
{
[DllImport("CITICs_HsT2Hlp.dll", EntryPoint = "_CITICs_HsHlp_BizCallAndCommit@20")]
public static extern int CITICs_HsHlp_BizCallAndCommit(IntPtr hlpHandle, int iFunc, byte szParam);

}
///
/// Interaction logic for MainWindow.xaml
///

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
LoadConfig();
}
public void LoadConfig()
{

try
{
IntPtr hconfig = new IntPtr();
IntPtr hlpHandle = new IntPtr();
byte[] szParam = new byte[1024];

string str = "identity_type:2,op_branch_no: ,op_entrust_way:5,";
Encoding.ASCII.GetBytes(str, 0, str.Length, szParam, 0);
int iFunc=33301;
int rst = CITICs.CITICs_HsHlp_BizCallAndCommit(hlpHandle, iFunc, szParam);
int dss = rst;
}
catch (Exception ex)
{

}
}
全部回答
  • 1楼网友:洎扰庸人
  • 2021-11-12 02:47
IntPtr
  • 2楼网友:孤老序
  • 2021-11-12 01:17
答:string

C++ 声明一个字符串有好多种方式 char* CString 等等好多 我不是搞C++的
  • 3楼网友:零点过十分
  • 2021-11-12 00:32
char 是8位, int 是32位,可以传 int 但是要确保 你的 int 变成8位后没有位数损失,
char* 一般是一个 byte[] 数组,先要用 Marshal.Copy 函数将数组复制到一个 IntPtr 中,任意指针在C#中都表示为 IntPtr ,将IntPtr 传入你的方法就行
  • 4楼网友:詩光轨車
  • 2021-11-12 00:06
用StringBuilder就可以,我这几天正好在用这个.
  • 5楼网友:酒醒三更
  • 2021-11-11 22:58
用 void* 可以,需要的时候再转换回来 (char*)转换
举个我用过的例子
unsafe public extern static void* VirtualAlloc(void* lpAddress, int dwSize, int flAllocationType, int flProtect);
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯