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 / July 2003

Tip: Looking for answers? Try searching our database.

IntPtr value type via P/Invoke

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michel Gallant - 05 Jul 2003 17:43 GMT
Probably a simple marshaling question:

.NET value types passed as arguments via P/Invoke must be prototyped
and passed as ref to marshal back changes to the value type. Fine.

According to the .NET MSDN docs,  IntPtr is a value type.
Why then when a prototype is configured (for example to get a returned pointer to a struct) as:
 ManagedProto(.., IntPtr myptr, ...)

and called as  ManagedProto(...,  myptr, ...)

does the value successfully get changed?

(compared to using IntPtr to get a reference handle where  ref IntPtr is
prototyped)?

Thanks,
- Mitch
Michel Gallant - 06 Jul 2003 15:47 GMT
Ok, I think I understand now (please correct if not right):

When an IntPtr myPtr argument is prototyped, one must actually
define the pointer value, usually by a memory allocation like:
 myPtr =  Marshal.AllocHGlobal(bBytesneeded);
When the win32 function is called and returns, the myPtr value
is the same (value type), but the called function changes the data
(buffer, structure ... whatever) pointed to by myPtr.

When used to GET a handle from a function, the function actually
returns the pointer value, so  ref IntPtr   is used.

- Mitch

> Probably a simple marshaling question:
>
[quoted text clipped - 14 lines]
> Thanks,
>  - Mitch

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.