PC Review


Reply
Thread Tools Rate Thread

Calling C# from unmanaged C++

 
 
Fernando Cacciola
Guest
Posts: n/a
 
      5th Jan 2005
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


 
Reply With Quote
 
 
 
 
Jeff Louie
Guest
Posts: n/a
 
      5th Jan 2005
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/de.../en-us/cpguide
/html/cpconusingcallbackfunctions.asp

Regards,
Jeff
>I have an unmanaged processing class and "all I want" is a way to give

progress feedback into the C# client code.<


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Fernando Cacciola
Guest
Posts: n/a
 
      5th Jan 2005

"Jeff Louie" <(E-Mail Removed)> escribió en el mensaje
news:(E-Mail Removed)...
> 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/de.../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


 
Reply With Quote
 
Fredrik Wahlgren
Guest
Posts: n/a
 
      5th Jan 2005

"Fernando Cacciola" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
Sahil Malik
Guest
Posts: n/a
 
      5th Jan 2005
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

"Fernando Cacciola" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Fredrik Wahlgren
Guest
Posts: n/a
 
      5th Jan 2005

"Sahil Malik" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
Fernando Cacciola
Guest
Posts: n/a
 
      6th Jan 2005

"Fredrik Wahlgren" <(E-Mail Removed)> escribió en el
mensaje news:(E-Mail Removed)...
>
> "Sahil Malik" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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.
>

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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling unmanaged C++ dll from C# app =?Utf-8?B?Q2hyaXM=?= Microsoft C# .NET 8 25th Jan 2005 03:01 AM
Re: Calling unmanaged dll from C# Nicholas Paldino [.NET/C# MVP] Microsoft C# .NET 0 31st Aug 2004 03:24 PM
ASP.Net c# calling c++ unmanaged DLL will Microsoft C# .NET 1 16th Feb 2004 07:43 AM
calling unmanaged c++ Jacob Gladish Microsoft C# .NET 6 3rd Nov 2003 03:02 PM
Calling .Net from C++ (unmanaged) Paul Microsoft Dot NET Framework 1 30th Oct 2003 09:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:13 PM.