JavaCallsCOM_NET Sample (Expose COM Objects to Managed Components Using .NET Framework Interop)
This sample demonstrates how Visual J# applications can access COM DLLs using the .NET Framework COM inter-op semantics. Using .NET Framework semantics is the recommended way for COM inter-op for newly written Visual J# applications. Managed wrappers are generated for the COM DLL using the .NET Framework tool TlbImp. The managed wrappers are then imported into the Visual J# program. Using the new operator on the appropriate wrappers then creates an instance of the COM coclass. The developer can then invoke methods on the COM DLL by calling methods on the wrapper. Unlike inter-op using JActiveX® wrappers the wrappers generated by TlbImp extend from System.Object and take .NET Framework data types as parameters and return types.
For more information on COM inter-op using .NET semantics please refer Exposing .NET Framework Components to COM.
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 menu, click Build Solution, or press CTRL+SHIFT+B.
From the command line, type BUILD.bat.
For more information, see.
A prebuilt COM DLL is included in the sample. If you do not want to rebuild the COM server, you need to register the existing DLL by typing regsvr32 COMServer.dll before using it. In case you rebuild the COM server no explicit registration is required, as the build process does this.
To run this sample
From the development environment, open the Client.vjsproj file (from the \Client directory) and press F5 to build and run the sample.
From the command line, type Client.exe.