Home : Using PROGIDs to Access COM Objects
Q48988 - HOWTO: Using PROGIDs to Access COM Objects

Using PROGIDs to Access COM Objects

 

The com2java-generated Java proxies always access COM objects via their CLSIDs, but a few customers have requested a way to access COM objects via their PROGIDs instead.

The attachment, hostlib.zip, contains a simple VB EXE which, given a PROGID, will return an object reference to the requested object. Place this on your COM server machine and double-click on it to register it (or use "Hostlib /regserver"). Using the com2java tool, generate the proxies for this EXE with the package name "hostlib", and place them into a "hostlib" subdirectory. Compile the generated proxies on the client machine. You can then use the proxies as in the example below (which creates an Excel "Application" object).

  hostlib.Host host = new hostlib.Host("localhost");
  excel.Application app = new excel.Application(host.objectFromProgID("Excel.Application"));

Here are the contents of the "Host" class in HostLib.exe. As you can see, it is very simple:

  Public Function ObjectFromProgID(ByVal progid As String) As Object
    Set ObjectFromProgID = CreateObject(progid)
  End Function
Related Articles
No Related Articles Available.

Article Attachments
hostlib.zip

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 6/23/2006.
Last Modified on 7/12/2006.
Last Modified by No Author Name Available!.
Article has been viewed 7295 times.
Rated 5 out of 10 based on 10 votes.
Print Article
Email Article