C# subwindow in a Win32 application?

D

digory

Hi

Our product consists of a complex application that is written in C/C++
and uses the old event-based Win32 API (some code has already been in
there in times of Windows 3.11!) We cannot afford a complete
reimplementation of the whole application, so we would like to
gradually port portions of the application to more contemporary
platforms like C#.

Is it possible for a Win32-based application to encapsulate C# code? I
think of a subwindow or sort of control, which I can place in any
window and which is a view of C# code.
 
L

Lasse Vågsæther Karlsen

digory said:
Hi

Our product consists of a complex application that is written in C/C++
and uses the old event-based Win32 API (some code has already been in
there in times of Windows 3.11!) We cannot afford a complete
reimplementation of the whole application, so we would like to
gradually port portions of the application to more contemporary
platforms like C#.

Is it possible for a Win32-based application to encapsulate C# code? I
think of a subwindow or sort of control, which I can place in any
window and which is a view of C# code.

Yes, it is, you need to host the .NET runtime and call into .NET to
obtain IDispatch-compatible objects of your .NET classes.

We've done this from Delphi, and I can probably dig up some example
interfaces, api-functions, etc. that you need to work with.
Unfortunately (for you) since we've done this in Delphi, direct code
examples will likely be unusable to you.

We've had the following experiences with this approach:

1. using a C# control inside a Delphi control is doable, but needs way
more plumbing code in Delphi than we're prepared to do. Specifically, if
you focus a textbox on a .NET control that is placed on a Delphi form,
and hit Tab, focus doesn't move inside the .NET control but just jumps
back to the Delphi code. The Delphi code thus considers the whole .NET
control as something that cannot take focus.

2. Exceptions are tricky, mostly due to the way Delphi hides IErrorInfo
interfaces from us when interfacing with IDispatch-objects the way we
do, so we're a bit thin on cross-world exception handling.

3. Two-way calling is also possible, provided you can give an object to
..NET through an interface implementing callback functions.

In short, it's doable, it works, but could be more polished and isn't
without its problems.

If you google for "hosting .NET runtime c/c++" you'll find a few links,
and if you need more, just send me an email.
 
D

digory

Thanks a lot for your reply! How do I host the .NET runtime? Is there
a special DLL? Do you have a link to a site with further information
about how to do this?
 
B

Benny Skjold Tordrup

What about C++/CLI? Assuming the C++ part can be done in Visual Studio 2008?
 

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