For Programmers: Free Programming Magazines  


Home > Archive > VC Language > May 2006 > Calling a "C# .Net" functions as callbacks from VC++ 6.0.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Calling a "C# .Net" functions as callbacks from VC++ 6.0.
Haxan

2006-05-26, 7:09 pm

Hi,

I have developed a C# application/dll which has some functions that I would
like to use as callback functions from my VC++ 6.0 application/dll.

I would like to call those C# functions from my VC++ 6.0 application/dll. I
have used Visual Studio 2005 to create the C# application/dll (managed)

Will appreciate any help/suggestions.

Thanks
Haxan

2006-05-26, 7:09 pm

Let me put it more clearly/rephrase it!.

I would like to call a C# function from my VC++ application/dll and pass a
callback function to this function(C#).

Hopefully this is more clear.

Thanks.


"Haxan" wrote:

> Hi,
>
> I have developed a C# application/dll which has some functions that I would
> like to use as callback functions from my VC++ 6.0 application/dll.
>
> I would like to call those C# functions from my VC++ 6.0 application/dll. I
> have used Visual Studio 2005 to create the C# application/dll (managed)
>
> Will appreciate any help/suggestions.
>
> Thanks

William DePalo [MVP VC++]

2006-05-26, 7:09 pm

"Haxan" <Haxan@discussions.microsoft.com> wrote in message
news:EC39CCD7-34B6-4F53-95A4-235CB2EBDFE0@microsoft.com...
> I have developed a C# application/dll which has some functions that I
> would
> like to use as callback functions from my VC++ 6.0 application/dll.


Often the easiset thing to do is to put a shim netween them.

The best thing about the managed versions of C++ (MC++ and C++/CLI) is that
a module written in a managed version of C++ can contain both native and
managed classes. So, your VC6 application can call free functions in a
managed DLL, which then calls managed functions in C++ which can consume
your C# classes because managed versions of C++ and C# share the same object
model.

At some level the problem is reduced to figuring out how you can have a
C-style procedural interface to a C++ class.

Another option is to use COM. The RegAsm (register assembly) utility

http://msdn.microsoft.com/library/d...egasmexe.aspcan be used to create a COM wrapper around your C# class.That done, the problem is reduced to consuming a COM object.Regards,Will

Haxan

2006-05-26, 7:09 pm

Thanks Will. If I wrap COM around my C# class can I still pass VC++ 6.0
callback function(function pointer) to these C# functions? Also does Regasm
also work with regular dlls or does it have to be a web service? Appreciate
your response.

I would prefer not to wrap COM. If there is another way, please let me know.
Thanks.


"William DePalo [MVP VC++]" wrote:

> "Haxan" <Haxan@discussions.microsoft.com> wrote in message
> news:EC39CCD7-34B6-4F53-95A4-235CB2EBDFE0@microsoft.com...
>
> Often the easiset thing to do is to put a shim netween them.
>
> The best thing about the managed versions of C++ (MC++ and C++/CLI) is that
> a module written in a managed version of C++ can contain both native and
> managed classes. So, your VC6 application can call free functions in a
> managed DLL, which then calls managed functions in C++ which can consume
> your C# classes because managed versions of C++ and C# share the same object
> model.
>
> At some level the problem is reduced to figuring out how you can have a
> C-style procedural interface to a C++ class.
>
> Another option is to use COM. The RegAsm (register assembly) utility
>
> http://msdn.microsoft.com/library/d...egasmexe.aspcan be used to create a COM wrapper around your C# class.That done, the problem is reduced to consuming a COM object.Regards,Will
>
>

William DePalo [MVP VC++]

2006-05-26, 7:09 pm

"Haxan" <Haxan@discussions.microsoft.com> wrote in message
news:7F2F71FF-3C8D-4656-8313-04B23B5252C3@microsoft.com...
> Thanks Will. If I wrap COM around my C# class can I still pass VC++ 6.0
> callback function(function pointer) to these C# functions?


I'm not sure I understand you, but if the goal is have the C# code run as a
"callback" then I'd suggest that the real callback be cast in native C++.
That code can use "it just works" or P/Invoke to call a function in a
managed C++ class (MC++ or C++/CLI) which then calls into the C# function in
the canonical way.

That's what I meant by "shim" - something small inserted between two other
"things" to make them "fit".

If that's no what you want to do, then I'm sorry but I'm not sure I know
what you want to do.

> Also does Regasm also work with regular dlls or does it have to be a web
> service?


It "registers" a .Net assembly so that its classes can be used as if they
were COM components in native code.

Regards.
Will


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com