UInt32 to IntPtr

Posted by ffenix on Stack Overflow See other posts from Stack Overflow or by ffenix
Published on 2012-11-19T22:42:28Z Indexed on 2012/11/19 23:00 UTC
Read the original article Hit count: 224

Filed under:

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;

© Stack Overflow or respective owner

Related posts about c#