CoCreateInstanceEx Sample

This sample is located in \Samples\Com\CCIEx.

Note   It is recommended that you have Microsoft® Visual C++® version 5.0 or higher installed.

Description
Using the Sample
Key Project Files
Technologies Demonstrated

Description

The CoCreateInstanceEx (CCIEx) sample uses a Java-implemented COM object through a custom interface to pass a string, array, and the client as a COM object. The interfaces are defined in IDL (Interface Definition Language), and used by the client and the server through the Java wrappers generated by jactivex. A Microsoft® J/Direct™ call to CoCreateInstanceEx creates instances of the in-process COM object, forms a local server, and forms a remote client.

Using the Sample

To compile the remote client

Edit \Samples\Com\CCIEx\Sample\Dcom\RemoteClient.java as follows:

  1. Change
    public final String serverName = null;
    

    to the following:

    public final String serverName=<this machine name>;
    
  2. Change
    public final String userName = null; 
    

    to the following:

    public final String userName=<the login name for the user that will be identified for security>;
    
  3. Change
    public final String domainName = null; 
    

    to the following:

    public final String domainName=<domain that the user is from>;
    
  4. Change
    public final String password = null; 
    

    to the following:

    public final String password=<password for the user on the specified domain>;
    
  5. Use Nmake.exe to compile the makefile in the \Samples\Com\CCIEx directory. Type the following command:

    Nmake

To install the server sample

In \Samples\Com\CCIEx, run Register.bat.

This displays two dialog boxes indicating that the COM object and the proxy/stub were registered correctly.

To install the client sample

In \Samples\Com\CCIEx, run Clientreg.bat.

This displays a message stating that the proxy/stub was registered correctly.

To uninstall the server sample

In \Samples\Com\CCIEx, run Remove.bat.

This displays two messages stating that the COM object and the proxy/stub were removed correctly.

To uninstall the client sample

In \Samples\Com\CCIEx, run Clientrem.bat.

This displays a message stating that the proxy/stub was removed correctly.

To run the inproc sample

From \Samples\Com\CCIEx, run the following command:

jview sample.dcom.InprocClient

If successful, this displays the output from the COM object and the Client. The last message will be InprocClient - Done.

To run the local server sample

From \Samples\Com\CCIEx, run the following command:

jview sample.dcom.OutprocClient

If successful, this displays the output from the COM object and the Client. The last message will be OutprocClient - Done.

Note   The local server case may fail with an RPC error (HRESULT = 800706BE).

This is because in Microsoft® Windows NT®, version 4, the main thread of Dllhost.exe waits for COM to tell it to shut down. COM signals a shutdown whenever the total proxy count in the process is 0 (zero). The Microsoft virtual machine cocreates an MDM process to ask if the object should be debugged and then immediately released. That triggers the proxy count to reach 0 (zero) and the process goes away in the middle of an otherwise successful run.

You can avoid the debug check by removing the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Java VM\MSDEBUG registry key that is automatically added by Visual J++. Note that VJ will continue to add this key each time VJ is run.

Changing the threading model for the Hub2 Java/COM object in the registry to ThreadingModel=Apartment makes this work, probably because you end up with a proxy out of an STA COM worker thread to one of the surrogate's MTA worker threads. With ThreadingModel=Both, you end up directly on the MTA worker thread and don't create a proxy.

To run the remote client sample from the remote machine

From \Samples\Com\CCIEx, run the following command:

jview sample.dcom.RemoteClient

If successful, this displays the output from the COM object and the Client. The last message will be RemoteClient - Done.

Key Project Files

clientreg.bat

This batch file contains the client registration information for adding the Proxystub.dll file into the local registry. This is required for marshaling the custom interface on the Java/COM object.

clientrem.bat

This batch file removes the Proxystub.dll file from the registry of the client registry.

register.bat

This batch file registers the Java/COM object and Proxystub.dll.

Hub2.java

This class contains the implementation of the Java/COM object.

InprocClient.java

This class contains the implementation of the in-process client.

OutprocClient.java

This class contains the implementation of the local-server client.

RemoteClient.java

This class contains the implementation of a remote client.

Technologies Demonstrated

COM

This sample shows how to:

DCOM

© 1999 Microsoft Corporation. All rights reserved. Terms of use.