Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

Translating 64-bit API functions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robert Jacobson - 01 Sep 2003 01:59 GMT
Hi,

According to MSDN, I should be using the 64-bit compatible SetWindowsLongPtr
function instead of SetWindowsLong.  SetWindowsLongPtr is defined as:

LONG_PTR SetWindowLongPtr(HWND hWnd,
   int nIndex,
   LONG_PTR dwNewLong
);

What is the best way to call this function (and similar 64-bit API
functions) with .Net data types?

Specifically, MSDN defines a LONG_PTR as being a signed 64-bit integer.
Does this map directly to a Long (Int64) data type, or is it preferable (or
necessary) to use an IntPtr data type instead?

Are there any other "gotchas" about calling a 64-bit compatable API
function?

Thanks,
Robert Jacobson
Mattias Sj?gren - 01 Sep 2003 06:52 GMT
Robert,

>According to MSDN, I should be using the 64-bit compatible SetWindowsLongPtr
>function instead of SetWindowsLong.  SetWindowsLongPtr is defined as:
[quoted text clipped - 3 lines]
>    LONG_PTR dwNewLong
>);

On Win32, SetWindowLongPtr is just an alias for SetWindowLong, so you
have to call the latter function.

Public Declare Function SetWindowLongPtr Lib "user32" Alias
"SetWindowLong" (ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal
dwNewLong As IntPtr) As IntPtr

>Specifically, MSDN defines a LONG_PTR as being a signed 64-bit integer.

Not on Win32 it isn't. The size of LONG_PTR is 32-bit on Win32, and
64-bit on Win64.

>Does this map directly to a Long (Int64) data type, or is it preferable (or
>necessary) to use an IntPtr data type instead?

Use (U)IntPtr for any pointer-sized integers.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Robert Jacobson - 01 Sep 2003 21:08 GMT
Thanks Mattias.  For what it's worth, I was getting an error message with
your definition --
"Unable to find an entry point named SetWindowLong in DLL user32."  It
worked after I inserted an "Auto" into the declaration:

Public Declare Auto Function SetWindowLongPtr Lib "user32" Alias
"SetWindowLong" (ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal
dwNewLong As IntPtr) As IntPtr

(I don't know why the "Auto" should matter, since I'm not passing strings.)

However, this just brings back to using SetWindowLong.  Does this mean that
I need to have two separate declarations, one for 32-bit OS's, and another
for 64-bit?  (And with some sort of compiler or JIT switch to choose the
correct one?)  For future compatibility, I'd like to ensure that my program
will run correctly on either platform.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.