HOW TO: Upgrade Visual J++ Components to Visual J# .NET (818429)



The information in this article applies to:

  • Microsoft Visual J# .NET 2002
  • Microsoft Visual J++ 6.0

SUMMARY

You can compile and run Visual J++ 6.0 Java-language or Microsoft COM components that are used from COM clients.

The steps in the "More Information" section describe how to manually upgrade Java-language or COM components by using a command-line tool. When you upgrade Visual J++ projects in Microsoft Visual Studio .NET, the Microsoft Visual J# Upgrade wizard automates the upgrade process for Visual J++ components.

MORE INFORMATION

Important If the Java-language or COM component was implemented by using the templates that are generated by the JActiveX tool, or your Java-language component implements a type library interface, you must do steps a and b before you do the numbered steps in these instructions:
  1. Use the Tlbimp.exe command-line tool that is included with the Microsoft .NET Framework SDK and Visual Studio .NET to generate managed wrappers from the type library that you used to generate the JActiveX templates. For example, type the following at a command prompt, and then press ENTER:

    tlbimp.exe /keyfile:interopKey.snk COMComponent.tlb

  2. In step 1 of the numbered steps, reference the managed wrapper assemblies that you generated in step a when you compile the Java-language or COM component. For example, type the following at a command prompt, and then press ENTER:

    vjc /r:TlbimpGeneratedWrappers JavaSources

When you upgrade Visual J++ 6.0 Java-language or COM applications to Visual J# .NET, do not manually edit the wrappers that the JActiveX tool generated to add the .NET Framework COM interop attributes or APIs. If you manually edit these wrappers, you may experience unexpected runtime issues. Microsoft does not support the mixing of such attributes as @com and @dll with the .NET Framework COM interop attributes in Visual J++ 6.0. Microsoft strongly discourages this practice both in upgraded Visual J++ Java-language or COM applications and in new applications that are written by using Visual J# .NET.
  1. Compile the Java-language or COM component by using the Visual J# .NET command-line compiler (Vjc.exe). For example, type the following at a command prompt, and then press ENTER to compile the code:

    vjc /target:library JavaSources

  2. Sign the assembly before you register it by using the /codebase option of the Regasm tool. To sign an assembly, attach the AssemblyKeyFile attribute that is located in the System.Reflection namespace to one of the files in your project, as in the following example:
    /** @assembly System.Reflection.AssemblyKeyFile("myKey.snk") */
    where myKey.snk is a key pair file that the .NET Framework SDK tool Sn.exe generates.
  3. If a COM client gains access to the Java-language or COM component by using the type library that the VJReg.exe tool generates, the COM client uses the dispinterface that is exposed on the component and . The dispIds of the class members are not guaranteed to be the same in Visual J#. If the dispIds of the class members are different from what they were in the Visual J++ version, the existing COM clients may fail. To avoid this problem, verify the following if a type library exists for the Java-language or COM component:
    1. The type library is registered on the computer.
    2. The GUID of the type library is specified by using the typelib parameter in the @com.register directive for the component.
    In such case, a warning message appears in the Visual J# compiler. For more information, visit the following Microsoft Web site:
  4. Register the generated DLL file or EXE file by using the Regasm.exe command-line tool. (This tool is included with the Microsoft .NET Framework SDK and Visual Studio .NET.) To do this, type the following at a command prompt, and then press ENTER:

    Regasm /codebase generated_DLL_or_EXE

REFERENCES

For more information about how to upgrade Visual J++ components, visit the following Microsoft Web site:

Modification Type:MinorLast Reviewed:8/15/2005
Keywords:kbhowto kbUpgrade kbJava kbDLL kbCompiler KB818429 kbAudDeveloper