473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Handling callbacks from unmanaged code

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

Jun 25 '07 #1
3 2179

<ke***********@googlemail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
>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.
Jun 25 '07 #2
On 25 Jun, 18:17, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
<kelvin.koo...@googlemail.comwrote in message

news:11**********************@k79g2000hse.googlegr oups.com...
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.
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

Jun 26 '07 #3

<ke***********@googlemail.comwrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
On 25 Jun, 18:17, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
><kelvin.koo...@googlemail.comwrote in message

news:11**********************@k79g2000hse.googleg roups.com...
>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.

Definition of callback

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

Function to register callback

Initialise(const char *pPort, CallbackFn callback);

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::GetFu nctionPointerForDelegate
to get an unmanaged function pointer from it.
>
KK

Jun 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: vijaya | last post by:
I've to invoke a unmanaged dll fucntion in C# which uses a callback fucntion.The unmanaged dll fucntion returns a pointer to a structure to its callback fucntion.The user should collect those...
1
by: vijaya | last post by:
I've to invoke a unmanaged dll fucntion in C# which uses a callback fucntion.The unmanaged dll fucntion returns a pointer to a structure to its callback fucntion.The user should collect those...
23
by: Brian | last post by:
I am very new to C# programming and have run into a problem. I apologize for the repost of this article. For some reason, my news reader attached it to an existing thread. First off, I have...
11
by: Fabien Penso | last post by:
Hi. I am trying to make this work but I got a weird behavior. I got a very basic system, I call a unmanaged "dllimported" function and give it a structure of callback functions. Sometimes,...
4
by: R. MacDonald | last post by:
Hello, all, I have a .NET application (VB) that passes the address of a delegate to unmanaged code in a DLL. The unmanaged code then uses the delegate as a call-back. This seems to work...
2
by: cada0310 | last post by:
Hi there, I'm new to C# (but not to C++), and I'm trying to create a web service that calls some of our older software, located in a DLL. I'm getting most the calls to work ok, but one of them...
6
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls...
8
by: DavidT | last post by:
Hello, at first, exuse if the following question is simple to solve, but i normaly coding with C# and now have to use C++/CLI for one project. My Problem is that i have to use a native c++ sdk...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.