locked
How to convert UINT_PTR to System::IntrPtr RRS feed

  • Question

  • I have a native C++ socket object which type is UINT_PTR ,

    I just want to convert this type to System::IntPtr in my managed C++ .

    How can I do that ?

     


    Beat Microsoft.
    Thursday, April 28, 2011 8:59 AM

Answers

  • Hello, you can try the following code:

    #include "stdafx.h"
    
    using namespace System;
    
    #define UINT_PTR System::Void*
    
    int main(array<System::String ^> ^args)
    {
      System::UInt32 n = 0;
      UINT_PTR nPtr = &n;
      System::UIntPtr uIntPtr = (System::UIntPtr)nPtr;
      Console::WriteLine(uIntPtr);
      System::IntPtr intPtr = (System::IntPtr)nPtr;
      Console::WriteLine(intPtr);
      return 0;
    }
    

    Hope this helps,

    Miguel.


    • Proposed as answer by Paul Zhou Friday, May 6, 2011 3:14 AM
    • Marked as answer by Paul Zhou Tuesday, May 10, 2011 10:00 AM
    Thursday, April 28, 2011 11:10 AM

All replies

  • Hello, you can try the following code:

    #include "stdafx.h"
    
    using namespace System;
    
    #define UINT_PTR System::Void*
    
    int main(array<System::String ^> ^args)
    {
      System::UInt32 n = 0;
      UINT_PTR nPtr = &n;
      System::UIntPtr uIntPtr = (System::UIntPtr)nPtr;
      Console::WriteLine(uIntPtr);
      System::IntPtr intPtr = (System::IntPtr)nPtr;
      Console::WriteLine(intPtr);
      return 0;
    }
    

    Hope this helps,

    Miguel.


    • Proposed as answer by Paul Zhou Friday, May 6, 2011 3:14 AM
    • Marked as answer by Paul Zhou Tuesday, May 10, 2011 10:00 AM
    Thursday, April 28, 2011 11:10 AM
  •  

    Hi,

     

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?

     

    If you have got answers, please remember to mark answer and close this thread.

     

    Have a nice day!


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, May 6, 2011 3:13 AM
  • Thanks for your reply .

    I am working on preparing the test project . If your answer works ,I will mark it as answer .

    By the way , if I just convert the SOCKET to System.IntPtr , does it work ?

    Cause socket object is just a UINT .

     


    Beat Microsoft.
    Friday, May 6, 2011 3:57 AM
  •  

    Hi,

     

    Has your issue been resolved? Would you mind letting us know the result of the suggestions?

     

    Now I will mark an answer, you can mark others that you think to be so useful to your issue.

    You could “Unmark As Answer” if it doesn’t make sense.

     

    Have a nice day!


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 10, 2011 10:00 AM