gpt4 book ai didi

c# - 在c#中将结构转换为char指针

转载 作者:行者123 更新时间:2023-11-28 03:19:56 25 4
gpt4 key购买 nike

<分区>

下面是一段用c++写的代码,我如何在c#中转换它。如果您检查 pams_get_msgw 函数,第一个参数是 (char*),我如何在 c# 中传递相同的参数。

                struct 
{
short m_nStatus;
short m_nReg_Id;
short m_nNumber_Reg;
} oRegReply;

short nBufSize = sizeof(oRegReply);
q_address oSenderQueue;
nMsgType = MSG_TYPE_SBS_REG_REPLY;
cPriority = 0;
lTimeout = 300; // 30 seconds

//Wait for reply telegram from SBS server
lStatus = pams_get_msgw((char *) &oRegReply, &cPriority, &oSenderQueue,
&nMsgClass, &nMsgType, &nBufSize, &nMsgLen,
&lTimeout, NULL, NULL, NULL, NULL,
NULL, NULL, NULL);

我的 pams_get_msgw 函数的 C# 声明是这样的

  [DllImport("DmqCl32.dll")]
public static extern int pams_get_msgw(StringBuilder msg_area, string priority, out q_address source,
out short clas, out short type,
ref short msg_area_len, out short len_data, ref int timeout,
ref int sel_filter, out PSB psb, out ShowBuffer show_buffer,
ref int show_buffer_len, ref int large_area_len, out int large_size,
[MarshalAs(UnmanagedType.LPStr)] string nullarg_3);

和实际的c++声明

typedef long (CALLBACK* PAMSGETMSGW)(char *,char *,q_address *, short *, short *, short *,
short *, long *, long *, struct PSB *,
struct show_buffer *, long *, char *, char *, char * );

我如何将结构传递给第一个参数,就像在 C++ 中做的那样?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com