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 / Languages / Managed C++ / June 2007

Tip: Looking for answers? Try searching our database.

Handling callbacks from unmanaged code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kelvin.koogan@googlemail.com - 25 Jun 2007 12:36 GMT
I have an unmanaged DLL which calls my managed C++ app using a
callback (standard C++ function pointer). I can receive the callbacks
OK using a static function with global scope, but I can't find a way
to get hold of a pointer to my Form to pass it the data.

Any ideas?

Application seems to have the only pointer to the form but no way for
me to retrieve it (in VC 2003 anyway). Any attempt to create a static
pointer to the form seems to fail.

Ideas gratefully received.

TIA,
KK
Ben Voigt [C++ MVP] - 25 Jun 2007 18:17 GMT
>I have an unmanaged DLL which calls my managed C++ app using a
> callback (standard C++ function pointer). I can receive the callbacks
> OK using a static function with global scope, but I can't find a way
> to get hold of a pointer to my Form to pass it the data.

In the unmanaged world, a callback (almost) always comes with a extra
parameter to pass application data.

.NET can also make a bound delegate into a function pointer.

If you show the declaration of the callback and the line used to register
it, we can probably help more.
kelvin.koogan@googlemail.com - 26 Jun 2007 08:33 GMT
> <kelvin.koo...@googlemail.com> wrote in message
>
[quoted text clipped - 12 lines]
> If you show the declaration of the callback and the line used to register
> it, we can probably help more.

Definition of callback

typedef void (*CallbackFn)(BYTE*, int);

Function to register callback

Initialise(const char *pPort, CallbackFn callback);

Note this is C++ not C.

KK
Ben Voigt [C++ MVP] - 26 Jun 2007 15:41 GMT
>> <kelvin.koo...@googlemail.com> wrote in message
>>
[quoted text clipped - 22 lines]
>
> Note this is C++ not C.

Then Initialise is a member function of some class?  Does pPort get passed
to the callback as its first parameter?

If not, you'll need a .NET bound delegate created in the usual way, and use
::System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate
to get an unmanaged function pointer from it.

> KK

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.