Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8772569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:03:56+00:00 2026-06-13T18:03:56+00:00

I was looking at the P/Invoke declaration of RegOpenKeyEx when I noticed this comment

  • 0

I was looking at the P/Invoke declaration of RegOpenKeyEx when I noticed this comment on the page:

Changed IntPtr to UIntPtr: When invoking with IntPtr for the handles, you will run into an Overflow. UIntPtr is the right choice if you wish this to work correctly on 32 and 64 bit platforms.

This doesn’t make much sense to me: both IntPtr and UIntPtr are supposed to represent pointers so their size should match the bitness of the OS – either 32 bits or 64 bits. Since these are not numbers but pointers, their signed numeric values shouldn’t matter, only the bits that represent the address they point to. I cannot think of any reason why there would be a difference between these two but this comment made me uncertain.

Is there a specific reason to use UIntPtr instead of IntPtr? According to the documentation:

The IntPtr type is CLS-compliant, while the UIntPtr type is not. Only the IntPtr type is used in the common language runtime. The UIntPtr type is provided mostly to maintain architectural symmetry with the IntPtr type.

This, of course, implies that there’s no difference (as long as someone doesn’t try to convert the values to integers). So is the above comment from pinvoke.net incorrect?

Edit:

After reading MarkH’s answer, I did a bit of checking and found out that .NET applications are not large address aware and can only handle a 2GB virtual address space when compiled in 32-bit mode. (One can use a hack to turn on the large address aware flag but MarkH’s answer shows that checks inside the .NET Framework will break things because the address space is assumed to be only 2GB, not 3GB.)

This means that all correct virtual memory addresses a pointer can have (as far as the .NET Framework is concerned) will be between 0x00000000 and 0x7FFFFFFF. When this range is translated to signed int, no values would be negative because the highest bit is not set. This reinforces my belief that there’s no difference in using IntPtr vs UIntPtr. Is my reasoning correct?

Fermat2357 pointed out that the above edit is wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:03:58+00:00Added an answer on June 13, 2026 at 6:03 pm

    UIntPtr and IntPtr are internal implemented as

    private unsafe void* m_value;
    

    You are right both simply only managing the bits that represent a address.

    The only thing where I can think about an overflow issue is if you try to perform pointer arithmetics. Both classes support adding and subtracting of offsets. But also in this case the binary representation should be ok after such an operation.

    From my experience I would also prefer UIntPtr, because I think on a pointer as an unsigned object. But this is not relevant and only my opinion.

    It seems not make any difference if you use IntPtr or UIntPtr in your case.

    EDIT:

    IntPtr is CLS-compliant because there are languages on top of the CLR which not support unsigned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I am looking for a win32 method to invoke in C# to set
Looking to do a bit of refactoring... Using NHibernate I have this query currently
Looking for a perl one-liner what will find all words with the next pattern:
Looking for best advice on how to do this: I have an insert like
I'm looking to run some powershell scripts via automation. Something like: IList errors; Collection<PSObject>
I am looking at Yahoo's YUI compressor executable jar and they have this class,
I'm looking to invoke a Java program from RPG running on Iseries V5r4. The
I'm looking for solution to invoke backbone action for particular route in my app.
After looking at stackoverflow and many other forums, decided to ask this question. The
By looking at this link i tried to implement Adwhirl in android https://www.adwhirl.com/doc/android/AdWhirlAndroidSDKSetup.html I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.