Avatar of tomcalef
tomcalef
 asked on

Callback from C# .dll to unmanaged C++

I have a c++ application successfully calling functions in a C# .dll using a COM interface.

How do I setup a callback in the c++ where a function in the C# can call it?
C++C#

Avatar of undefined
Last Comment
evilrix

8/22/2022 - Mon
jkr

That's a lot easer, since you can just use P/Invoke - see http://msdn.microsoft.com/en-us/library/aa288468%28v=VS.71%29.aspx ("Platform Invoke Tutorial"). Right the 1st example should be sufficiant, just specify the function you want to call.
tomcalef

ASKER
I guess the issue with my situation is that the .dll is c#, and it needs to call functions from the application which is in c++. I don't think i can do a dll import from that application can i?
jkr

Hm, not from an executable, but why not putting the callback inside a DLL that this executable loads?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
tomcalef

ASKER
The way our system architecture is done, this isn't allowed. What the ideal case i would think would be is to pass a function pointer to c# so that I can just call that function when the event happens.
jkr

Hmm, passing a function pointer to managed code won't work. I guess if you can't use a DLL, you'll also have to use a COM interface for that direction.
ASKER CERTIFIED SOLUTION
sarabande

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
evilrix

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.