COMCallsJava_NET Sample (Expose Managed Components to COM Using .NET Framework Interop)
This sample demonstrates how managed components written in Visual J# can be exposed to COM using the .NET Framework COM-interop semantics. Using .NET Framework semantics is the recommended way for COM inter-op for newly written Visual J# components. In this sample, the managed component written in Visual J# is compiled to a DLL. The DLL is then registered as a COM component using the RegAsm tool, which then allows it to be accessed from clients such as Visual Basic 6.0.
For more information on COM inter-op using .NET Framework semantics please refer to Interoperating with Unmanaged Code.
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.
Building and Running the Sample
To open the sample file in Solution Explorer
Click Download Sample.
The File Download message box appears.
Click Open, and on the left column of the zip folder window, click Extract all files.
The Extraction Wizard opens.
Click Next. You can change the directory that the files will be extracted to, and then click Next again.
Make sure that the Show extracted files check box is selected, and click Finish.
Double-click the sample's .sln file.
The sample solution is displayed in Solution Explorer. You might get a security warning that says the solution location is not trusted. Click OK to continue.
To build this sample
On the Build men, click Build Solution, or press CTRL+SHIFT+B.
From the command line, type BUILD.bat.
For more information, see.
To run this sample
Open the VB6Project.vbp file in Visual Basic 6.0.
From the Project menu, choose References. Then, browse and add a reference to the MyForm.tlb file present in your sample directory, or in the .\bin\debug subdirectory of the project root when building from the IDE.
Once running, click the Visual Basic form's button to create a managed form. Adjust the properties on the Visual Basic form and watch the changes occur on the managed form. The Visual Basic form also allows you to create a button on the managed form and adjust some of its properties. This is all done from unmanaged Visual Basic code.