Solved

library keyword in IDL

Posted on 2000-03-16
5
705 Views
Last Modified: 2008-03-06
I have a simple IDL file which declares one interface and one source dispinterface.
The dispinterface definition is in the library block. The interface definition is out.
I tryed to move the interface definition within the library block and it worked fine. The tbl and lib files generated where the same as before
Then I tryed to do the contrary moving both definitions out of the library brackets.

Then the idl file compiled well.(ie. no error) But when compiling the full project I got the error "DIID_<<dispinterface name>> not found". Along with a bunch of warnings.

Can anyone tell me why?
What does exactly the library keyword mean to the MIDL compliler?
I use VC5.0 with MIDL v.3.01.75.
0
Comment
Question by:Yo081699
5 Comments
 
LVL 3

Expert Comment

by:mnewton022700
ID: 2626048
The library statement contains all the information that the MIDL compiler uses to generate a type library.

Statements inside the library block can use elements that are declared inside or outside of the library block.

The MIDL compiler will create a type library that includes definitions for every element inside the library block, plus definitions for any elements defined outside and referenced from within the library block.

So when you moved both interfaces outside the library block, they were no longer referenced from within it and so didn't make it into the type library.
0
 
LVL 5

Accepted Solution

by:
Wyn earned 200 total points
ID: 2626758
->Then the idl file compiled well.(ie. no error) But when compiling the full project I got the error "DIID_<<dispinterface name>> not found". Along with a bunch of warnings.

Can anyone tell me why?
=====================================
Type library's one key usage is for Automation.
Since your code use a dispinterface.There must be one such interface defined into the type library.Then ,when you use it in your program ,complier can find info about it in the .tlb.
But type library for common interfaces are optional.They can go without type library and you can use them through some standard OLE RUNTIME functions,like CoCreateInstance() and so on.But another purpose you write common interfaces into IDL file except Automation is for COM Standard Marshalling,i.e:Let other procosses runing even on different machine can call/use this interface's member functions in a predefined-standard way. i.e,using RPC.
 
The reason you move common interface into library doesnt make difference just because the dispinterface is specific for this common interface in some way(through parameter,thus this interface's definition will always be contained into the type library because dispinterface need it to work.

->What does exactly the library keyword mean to the MIDL compliler?
==============================
It means:
whenever MIDL compiler meet them(maybe they are distributed in a .idl) ,compiler will generate a binary-structured file(like registry file) containing all kinds of info in the library part of idl file.
The kinds are below:
coclass
Describes the interfaces and dispinterfaces implemented on a particular object (identified by a CLSID).
 
interface
Describes a vtable interface (identified by an IID): specifically, the names of member functions, the return types of those functions, and the names and types of the arguments to those functions.
 
dispinterface
Describes a dispatch interface (identified by an IID) used by OLE Automation: specifically, the names, dispIDs, and types of the methods and properties (including return types and argument names and types for methods in the interface).
 
module
Describes a DLL module (identified by a DLL filename), including names and ordinals for exported functions and global variables.
 
typedef
Describes a user-defined data structure, enumeration, or union (identified by a name or an optional GUID).

You can use tools(like ole-com viwer) to have a deeper look.

 


Hope above helpful...

Regards
W.Yinan

0
 

Author Comment

by:Yo081699
ID: 2629251
mnewton
>>  they were no longer referenced from within it.
According to me, that's wrong as I have a coclass statement that refers to both interfaces.

So, where can I find descriptions of the structure of tbl files and lib files?
(What information they are supposed to store)
0
 

Expert Comment

by:yoffe
ID: 2629478
I believe that the midl compiler assumes that source dispinterfaces exists in another type library if not declared in the library block of YOUR IDL.   This is not the case for custom source interfaces.

If you have a source dispinterface and it is NOT defined in another type library (of another DLL or ocx), then you must put the dispinterface definition inside your library statement.   If you do not, the IID (DIID) consts will not be generated.

So, if the dispinterface exists in ANOTHER type type library, try using importlib instead.

For custom or dual (dual cant be used for sourcing interfaces) interfaces you can define them outside of the library block.   They DO NOT become part of the type library (and generate IIDs) UNLESS they are referenced inside the library statement.  

This is not true for dispinterfaces.   If you define a dispinterface outside the library block no DIID const will be defined REGARDLESS of whether or not you reference the interface inside the library block.   Thus, you MUST define the dispinterface inside the library statement or define the DIID by hand.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2630708
->mnewton
>>  they were no longer referenced from within it.
According to me, that's wrong as I have a coclass statement that refers to both interfaces.
==============================
I dont think mnewton is wrong here.If you dont define or reference dispinterface into the libray block and dont use importlib directive to contain another type library or use import a .idl file.The dispinterface will not appear in the type library.
The reason you can see it's there in CoClass is simple.Even you move interfaces out of library statement,but if you leave the a declaration/reference of those interfaces in the CoClass block.It will also appear in the typelibrary.Like you do this:
coclass ServerApp
      {
            [default] interface IServer;
      };

And you move IServer out of library block.It will also be contained into type library.


->So, where can I find descriptions of the structure of tbl files and lib files?
(What information they are supposed to store)
===================================
Tbl is structured as binary file with nested loop struct.
We seldom read it as common file directly in our program.Even we want to do that,we will use system-provided interface to interact with the type libray.Exactly the way we use the registry by using System APIs and we dont know how registry is constructed in details.
Regarding the content it stores,I have already mentioned in my answer and  you can view it by tools.

Regards
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now