Calling C# from unmanaged C++

  • Thread starter Fernando Cacciola
  • Start date
F

Fernando Cacciola

Calling C# from unmanaged C++:

Is there any way to do this without COM?

I have an unmanaged processing class and "all I want" is a way to give
progress feedback into the C# client code.

I basically just need to call an "Inc()" method into some managed progress
bar
(And to consult a "IsUserAborted" too)

Any idea on how to do this? May be using something not language related,
like a windows message or so... I don't know

TIA

Fernando Cacciola
SciSoft
 
F

Fernando Cacciola

Jeff Louie said:
Fernando... My understanding is that you can implement a C++ callback
using a delegate in C#. Watch for word wrap

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide
/html/cpconusingcallbackfunctions.asp
Great, thanks.. that's a start....
I actualy need to pass down a class member...
But maybe I just need to add the hidden "this" in the 'C' version...
OK, I'll play with it...
In any event, I have the basic mechanism.

Thank you!

Fernando Cacciola
SciSoft
 
F

Fredrik Wahlgren

Fernando Cacciola said:
Calling C# from unmanaged C++:

Is there any way to do this without COM?

Sure you can. You can use SendMessage to send something to a window.

/ Fredrik
 
S

Sahil Malik

Multiple ways to do this -- SendMessage is one, but uhhh .. not my favorite
!! :) because it could get confused if it can't find the right window (which
it finds by window title and window classname).

Anyway, look at Kernel32.dll->MoveMemory
Kernel32.dll->CreateFileMapping
Kernel32.dll->OpenFileMapping

These guys allow two processes to intercommunicate.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
F

Fredrik Wahlgren

Sahil Malik said:
Multiple ways to do this -- SendMessage is one, but uhhh .. not my favorite
!! :) because it could get confused if it can't find the right window (which
it finds by window title and window classname).

Anyway, look at Kernel32.dll->MoveMemory
Kernel32.dll->CreateFileMapping
Kernel32.dll->OpenFileMapping

These guys allow two processes to intercommunicate.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

You are absolutely right. Generally speaking, it may get confused. In this
case, I think it makes sense since Fernando said:
"I have an unmanaged processing class and "all I want" is a way to give
progress feedback into the C# client code."
I assume there is an open window. It's not one of my favorites either but I
think it comes in handy every once in a while.

/ Fredrik
 
F

Fernando Cacciola

Fredrik Wahlgren said:
You are absolutely right. Generally speaking, it may get confused. In this
case, I think it makes sense since Fernando said:
"I have an unmanaged processing class and "all I want" is a way to give
progress feedback into the C# client code."
I assume there is an open window. It's not one of my favorites either but
I
think it comes in handy every once in a while.
Indeed, in my case I do have a window, the one holding the progress bar
control, so this works fine.
Using a Memory Mapped File, as Sahil suggested can also work.
And of course, a plain callback as Jeff mentioned

Well, I'll see which on is better in my case, thanks to you all.

Fernando Cacciola
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top