Home : Com2Java: 'Prompt for Names for Imported tlbs' Option
Q30792 - INFO: Com2Java: 'Prompt for Names for Imported tlbs' Option

Com2Java: 'Prompt for Names for Imported tlbs' Option

 

Within a single type library, com2java generates Java proxies for everything in it (you can't pick and choose what gets generated). However, if a type library includes other type libraries, you have the option to 'prompt for names for imported type libraries'. But this doesn't mean you're choosing whether an imported library is being generated or not. Rather, you're simply choosing the type and package names for the imported type library.

Here's how the 'Prompt for names for imported tlbs' works:

1. If checked, once it encounters an import statement, it will prompt you for a new package name. If you choose "Cancel" or leave the name blank, when a type in this library is encountered, what is generated instead is "Object". If you specify an actual package name, what is generated is "package.TypeofObject" where "package" is the package name you chose and "TypeofObject" is the type.

2. If unchecked, this is the basically the same as the scenario above where you've clicked "Cancel" or left the package name blank.

An example might clear things up more. Let's take the Outlook type library for instance (MSOUTL9.OLB). Like all other Office type libraries, it imports MSO9.DLL. If you open up MSO9.DLL, you'll see a coclass definition for CommandBars. The coclass Explorer in MSOUTL9.OLB returns a reference to CommandBars in its method Explorer.getCommandBars. Now going through the above 2 scenarios:

1. If I check the "Prompt for names for imported tlbs" but leave the package name blank or hit "Cancel" when it prompts me, this is the (partial) protoype that com2java generates for getCommandBars in Explorer.java:
 
  public Object getCommandBars() throws etc...

2. If I entered a package name, let's say "mso9", then the (partial) prototype looks like this in Explorer.java:

  public mso9.CommandBars getCommandBars() throws etc...

3. If I don't have the option checked, I would get again:

  public Object getCommandBars() throws etc...

4. The catch here is that MSO9.DLL is *not* generated - only the type library MSOUTL9.OLB is being generated. All that you control here is the *type* that com2java will generate. That means that if you make use of getCommandBars(), you'll need to also generate proxies for MSO9.DLL separately!

The difference between the two methods is also important. In the first case, I would need to "wrap" the return into an actual CommandBars object to use:

  // o is Object returned from Explorer.getCommandBars
  CommandBars cb = new CommandBars(o);

If I actually specified a package name, then I already have a CommandBars object returned and would not need to do this.

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

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/11/2006.
Last Modified by No Author Name Available!.
Article has been viewed 5299 times.
Rated 5 out of 10 based on 9 votes.
Print Article
Email Article