none
DWORD_PTR in C# RRS feed

  • Question

  • How to use DWORD_PTR in C#? I used google but couldn't find any solution. It throws error:

    error CS0246: The type or namespace name 'DWORD_PTR' could not be found (are you missing a using directive or an assembly reference?)

    Wednesday, April 11, 2018 9:57 AM

All replies

  • DWORD_PTR is a c/c++ data type.

    It is equivalent to a uint in C#. Or possibly a IntPtr.

    It depends on what you are trying to do exactly. Is this to call some Windows API or non-NET DLL?

    Wednesday, April 11, 2018 10:03 AM
  • DWORD_PTR is a c/c++ data type.

    It is equivalent to a uint in C#. Or possibly a IntPtr.

    It depends on what you are trying to do exactly. Is this to call some Windows API or non-NET DLL?

    Its a function from dll file which are written in c++ and called in c# dll function has DWORD_PTR definitions.
    • Edited by speed258 Wednesday, April 11, 2018 10:17 AM
    Wednesday, April 11, 2018 10:10 AM
  • Fixed by setting Uint16, everything works as should be.
    Wednesday, April 11, 2018 11:45 AM
  • I would recommend you try it with a uint or Uint32.

    (It may be working with Uint16, but that might just be luck because the number in that argument is low enough. If the number happens to be higher it will overflow a Uint16).

    EDIT: Should be an IntPtr as CoolDadTx mentions below (which I did mention in my original post as well but...I saw you using a Uint16 and panicked :) ).
    • Edited by RJP1973 Wednesday, April 11, 2018 1:52 PM Edited based on other post
    Wednesday, April 11, 2018 12:56 PM
  • DWORD_PTR is an IntPtr in .NET. You don't want to use uint32 or uint64 as you are making an assumption about bitness that could be wrong. In an x86 process DWORD_PTR is 32-bits but in an x64 process it is 64-bit. Hence why you should be using IntPtr. That type handles the conversion and is explicitly designed for storing pointers.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, April 11, 2018 1:47 PM
    Moderator
  • Hello speed258,

    Is there any update or any other assistance I could provide? You could mark the helpful reply as answer if the issue has been solved :) And if you have any concerns, please do not hesitate to let us know.

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 12, 2018 7:47 AM
    Moderator