How to use a C# ControlLibrary in VC6

W

Wayne Gibson

Hi,
I have developed a C# Control Library with a number of window forms
controls.
I would now like to start using them in any old project written in VC6 using
MFC.

I have tried adding inserting components and controls to project, but it
doesn't list it there.
If in VC6, I right click on the dialog and select insert ActiveX it does
actually list it here.
But I have have a number of methods/functions that I want to be able to
invoke from the VC6 side.

So was wondering if anybody had done this before and if they could give me
an pointers or sample code to see where I'm going wrong.

Thanks

Wayne
 
G

Guest

Yeah, what you have to do is expose the .NET code to COM, then, import them
into the VC6. To do this, you need to create a Type Library (.TLB) using the
..NET tool TlbExp.exe and using the #import directive. When referencing a type
library from C++, you must either specify the raw_interfaces_only option or
import the definitions in the base class library, Mscorlib.tlb. It would look
like this:

#import "..\app\app.tlb" raw_interfaces_only

or like this:

#import "mscorlib.tlb"
#import "..\LoanLib\LoanLib.tlb"

COM developers can call methods on the .NET object the same way they call
methods on any unmanaged type. For example, the COM CoCreateInstance API
activates .NET objects. Calling the code would look like this:

IObjPtr pObj(__uuidof(TypeClass));
pObj->WhateverMethod();

Hopefully that helps.
 

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