Using C# Classes in win 32 application

  • Thread starter Thread starter Wayne
  • Start date Start date
W

Wayne

We have some old win32 apps and I still need to support these applications.
I'd like to do new and future enhancements in C#, if at all possible.

Is there a way to use a .net assembly in a normal windows 32 app?

Thanks
Wayne
 
Yeah, probably using the type library exporter, but type libraries i.e your
COM callable wrappers may omit some information. So in essence, you can
drive a car with your feet, but that doesn't mean you should.
 
Wayne said:
We have some old win32 apps and I still need to support these applications.
I'd like to do new and future enhancements in C#, if at all possible.

Is there a way to use a .net assembly in a normal windows 32 app?

There are two main approaches:

1) Turn on managed extensions for your C++ app, and use the IJW features of
MC++.
2) Use a MC++ bridging DLL.

Are we talking just simple functions or .NET controls? Simple functions are
easy; embedding .NET controls in MFC is tricky (but can definitely be done).

Stu
 
Hi nal,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to utilize a model that was
written in C# with managed code in Win32 application written in unmanaged
code. If there is any misunderstanding, please feel free to let me know.

As far as I know, we can expose .NET class interfaces to COM. The link Mark
provided is quite useful. We after written the class, we can use regasm.exe
register the DLL on the machine.

Here is some other useful article which provides more information.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconExposingNETFrameworkComponentsToCOM.asp

http://support.microsoft.com/default.aspx?scid=kb;en-us;817248

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
So from what I can tell this HAS to be done through Com, which results in
the C# Assembly being registered on the machine in question, is this
correct?

I was hoping there may be some LoadLib way of doing this, as the application
I currently have runs from a network share and requires no special installs
on the users machine. I would like to keep this modal going forward,
obviously the frame work would be there.

Thanks
Wayne
 
Hi Wayne,

Yes, you understanding is correct. When we need to load some library that
was written in .NET, we have to have .NET framework installed on the client
machine. And to interop with Win32 app, it seems that we can only achieve
this through COM.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
The link Mark provided is quite useful.

Generally speaking, I find the articles on www.15seconds.com to be really
helpful. I'm not a C# guru by any means, having made a living with VB since
version 3, and it always seems to me that these articles are just at the
level I require. I.e. techie enough for me to understand quickly, but not so
much that I have to spend hours poring over them, so that I can get to grips
with the basic concepts of what I'm looking for, and then delve deeper if I
need to.
 
Wayne said:
So from what I can tell this HAS to be done through Com, which results in
the C# Assembly being registered on the machine in question, is this
correct?

Is your application written in C++ or VB6?

If it's C++ you could go down either the managed C++ route or the COM route.
(NB you wouldn't have to make your application managed to use MC++; you
could use a bridging DLL instead).

If it's VB6 the COM is probably the best route although you could use a C++
bridging DLL and import it, but that wouldn't be pretty.

So no, a registered COM DLL is not your only option.

Here's an example I was involved with recently:

MFC application of about 500 KLOC. Wanted to use a C# component, and embed
it in an MFC view. We first tried turning on managed extensions, but that
increased the link time by about 10 minutes. The approach we are now using
is a partially managed bridging DLL, talking unmanaged to the MFC side, and
managed to C#. Nothing registered at all.

Stu
 
Actually its neither. The application is written in Delphi, Delphi for .net
(D8) allows you to export functions that can be used with Load Library,
however, we don't have D8, nor are we buying it just for this. So I guess I
will start looking at what it will take to get the Com Object registered on
each machine, as it is an internal app this shouldn't be to difficult.

thanks for all the information, and help. It is very appreciative.
Wayne
 
Wayne said:
Actually its neither. The application is written in Delphi, Delphi for ..net
(D8) allows you to export functions that can be used with Load Library,
however, we don't have D8, nor are we buying it just for this. So I guess I
will start looking at what it will take to get the Com Object registered on
each machine, as it is an internal app this shouldn't be to difficult.

thanks for all the information, and help. It is very appreciative.
Wayne

That'll learn me to make assumptions. I tend to forget about non-MS dev
environments...

Stu
 
Back
Top