Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

JavaCallsCOM_NET Sample (Expose COM Objects to Managed Components Using .NET Framework Interop) 

Visual Studio 2005

Download sample

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.

Security noteSecurity Note

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

  1. Click Download Sample.

    The File Download message box appears.

  2. Click Open, and on the left column of the zip folder window, click Extract all files.

    The Extraction Wizard opens.

  3. 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.

  4. 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.

    -or-

    From the command line, type BUILD.bat.

    NoteNote

    For more information, see Building from the Command Line (Visual J#).

    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.

    -or-

    From the command line, type Client.exe.

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft