I have the following problem:
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 is a UInt32 how i can cast it to IntPtr?, i try:
IntPtr signal = (IntPtr)data.signal;
but it doesn’t work because i need a pointer to data.signal (UInt32) type and not the int value as an pointer, that will make a memory exception.
An C++ example of what i need:
int signal = 0;
int* psignal = &signal;
You are going to have problems on a 64-bit platform because data.signal is only hanging on to the lower 32-bits of an address. If NetSharedData is yours you should consider changing the type of signal to IntPtr.
If you are trying to get an address to data.signal:
I’m not sure this would properly pin the object (to prevent the memory manager from relocating it), I would do the following:
1) Change the PInvoke signature:
2) use fixed to pin the object