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 / CLR / June 2004

Tip: Looking for answers? Try searching our database.

Must you really pin delegates when marshalling them as function pointers?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bern McCarty - 22 Jun 2004 17:43 GMT
Using the May CTP of VS 2005 I read an article "How to: Marshal Unicode
Strings using C++ Interop".  That article talks about the need to pin the
delegate prior to marshaling it out to native code as a function pointer.
But then in the 2nd example it proceeds to NOT pin it and to instead simply
do a GCHandle.Alloc(delegate) on it.

So, the question is, do you have to pin them or is it enough to make sure
that they remain referenced?

Bern McCarty
Bentley Systems, Inc.
David Mortenson [MSFT] - 30 Jun 2004 22:42 GMT
As long as the CLR Interop layer is the one marshalling the delegate to a function pointer then you don't need to pin it, you just need to ensure it stays
referenced.

So when passing out the delegate to native code as a function pointer using the following P/Invoke:

[DllImport(...)]
void GiveFunction(MyDelegate d);

You don't need to pin the delegate

Thanks,
David Mortenson
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Bern McCarty" <bern.mccarty@bentley.com>
>Subject: Must you really pin delegates when marshalling them as function pointers?
[quoted text clipped - 22 lines]
>Bern McCarty
>Bentley Systems, Inc.

Rate this thread:







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.