我有以下问题:
public class ListenThread : SocketInvoke
{
[DllImport("Ws2_32", CharSet = CharSet.Auto)]
public unsafe static extern UInt32 WSAWaitForMultipleEvents(UInt32 cEvents, IntPtr hEventObject,
UInt32 fWaitAll, UInt32 dwTimeout, Boolean fAlertable);
public void ListenConnections(NetSharedData data)
{
while (true)
{
unsafe
{
if (WSAWaitForMultipleEvents((UInt32)1, data.signal, (UInt32)0, (UInt32)100, false) != WSA_WAIT_TIMEOUT)
{
}
}
}
}
data.signal 是 UInt32 我如何将其转换为 IntPtr?,我尝试:
IntPtr signal = (IntPtr)data.signal;
但它不起作用,因为我需要一个指向 data.signal (UInt32) 类型的指针,而不是作为指针的 int 值,这将导致内存异常。
我需要的 C++ 示例:
int signal = 0;
int* psignal = &signal;