下面是一塊用C++編寫代碼,如何可以將它轉換在c#。如果你檢查pams_get_msgw函數,第一個參數是(char *),我怎麼能通過相同的C#。轉換結構爲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);
我的C#聲明pams_get_msgw功能是這樣
[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做++ ?
你可能會傳遞'string',你也很可能不得不改變你的'struct'成'class'並給它一個合適的'的ToString()'方法,根據您的要求 –