tlbexp command

G

Guest

Hello everyone,


I find that we can use tlbexp command like *tlbexp <dll name>* to export tlb
file for a C# COM assembly, but can not use it to export tlb file for an
unmanaged C++ COM DLL. Is that correct?

I am wondering how to export tlb file of an unmanaged C++ COM DLL?


thanks in advance,
George
 
B

Brian Muth

George said:
Hello everyone,


I find that we can use tlbexp command like *tlbexp <dll name>* to export tlb
file for a C# COM assembly, but can not use it to export tlb file for an
unmanaged C++ COM DLL. Is that correct?
Correct.


I am wondering how to export tlb file of an unmanaged C++ COM DLL?

Not all COM DLL's have a type library. If one exists, it might be a separate file or it may be embedded as a resource. You can find
out by using Oleview. Click on "File", "View Typelib..." and opening the DLL.

Brian
 
G

Guest

Thanks Brian,


When using OLEView to open the native unmanaged COM DLL, there is an error
message.

LoadTypeLib (c:\temp\foo.dll) failed.

Error loading type library/DLL.

TYPE_E_CANTLOADLIBRARY ($80029C4A)

Do you know what is wrong?


regards,
George
 
B

Ben Voigt [C++ MVP]

George said:
Thanks Brian,


When using OLEView to open the native unmanaged COM DLL, there is an error
message.

LoadTypeLib (c:\temp\foo.dll) failed.

Error loading type library/DLL.

TYPE_E_CANTLOADLIBRARY ($80029C4A)

Do you know what is wrong?

Looks like the type library is not embedded in the DLL. To verify, open the
DLL in Visual Studio's resource editor, if there are any type libraries they
will show up as custom resources of class "TYPELIB".
 
G

Guest

Thanks Ben,


I have followed your approach and I think there is no typelib embedded in
the DLL. I am not using ATL and MFC, and developing unmanaged native C++ COM
DLL from scratch.

In my situation, how to generate type library? I am using Visual Studio 2005.


regards,
George
 
C

Carl Daniel [VC++ MVP]

George said:
Thanks Ben,


I have followed your approach and I think there is no typelib
embedded in the DLL. I am not using ATL and MFC, and developing
unmanaged native C++ COM DLL from scratch.

In my situation, how to generate type library? I am using Visual
Studio 2005.

You have to build a type library using the MIDL compiler. You can then
embed that type library as a resource, or keep it as a separate file.

-cd
 
S

SvenC

Hi George,
I have followed your approach and I think there is no typelib embedded in
the DLL. I am not using ATL and MFC, and developing unmanaged native C++
COM
DLL from scratch.

Do you use an idl file to specify your library, coclasses and interfaces?
If yes, that idl must be compiled with midl.exe which will create the type
library.
In my situation, how to generate type library? I am using Visual Studio
2005.

If you are using Visual Studio, why don't you use ATL and its wizards for
creating COM objects?
 
G

Guest

Thanks cd,


I think I should use MIDL compiler and use the COM DLL as input to generate
type lib, right?

Do you have any reference materials about how to use MIDL compiler to
generate type lib and embedded it into COM DLL?


regards,
George
 
G

Guest

Thanks SvenC,


I am using Visual Studio 2005 and I can not find any idl file in the project
directory. Could you let me know how to generate type lib through MIDL
compiler please?

BTW: for some legacy reasons to maintain some code, I can not use ATL or MFC.


regards,
George
 
S

SvenC

Hi George,
I am using Visual Studio 2005 and I can not find any idl file in the
project
directory. Could you let me know how to generate type lib through MIDL
compiler please?

BTW: for some legacy reasons to maintain some code, I can not use ATL or
MFC.

You could create an ATL test project which does create an idl and will also
create/configure the necessary midl compiler settings. That should help you
to build the necessary idl for your legacy project.

You will find information about IDL files and the midl compiler in the MSDN.
 
G

Guest

Thanks SvenC,


I am a little confused. You mean I convert my current project into an ATL
project? Or using the new empty ATL project to build IDL for my current
project?

Could you provide more information about how to generate IDL for my current
project by using an ATL test project please?


regards,
George
 
S

SvenC

Hi George,
I am a little confused. You mean I convert my current project into an ATL
project? Or using the new empty ATL project to build IDL for my current
project?

The ATL project gives you an initial IDL file, just to see how a minimal IDL
file looks. You can also look at a wizard generated COM object where the
corresponding coclass and interface elements are add to that IDL file.
I think that such an idl file might help you to understand how to build your
own.

So: No, you don't need to convert your legacy project to an ATL project. It
might just help to figure out which parts of the IDL file and your COM
objects must match. Typically its the GUIDs of the library, the coclasses,
interfaces, dispinterfaces and dispids which you should find in your legacy
C++ project
Could you provide more information about how to generate IDL for my
current
project by using an ATL test project please?

Just use Project->Add new item and select "Visual C++ / Code / Midl file".
That adds the idl and sets up a midl compiler step. You will then have to
define your coclasses, interfaces and library in that idl file. Check your
test project how an idl file needs to be filled with content.
 
G

Guest

Thanks SvenC,
Just use Project->Add new item and select "Visual C++ / Code / Midl file".
That adds the idl and sets up a midl compiler step. You will then have to
define your coclasses, interfaces and library in that idl file. Check your
test project how an idl file needs to be filled with content.

I think I can only use the functions you mentioned above in an ATL project,
right?

(e.g. in normal Visual C++ project which I used to create COM DLL, I can not
use this function)

For the reference IDL file generated automatically by ATL project, I find it
is useful, but I still need to manually write something. :)

I have also researched that MIDL compiler could help to generate IDL file
automatically, right?


regards,
George
 
S

SvenC

Hi George
I think I can only use the functions you mentioned above in an ATL
project,
right?
(e.g. in normal Visual C++ project which I used to create COM DLL, I can
not
use this function)

What is a normal Visual C++ project? Did you check if the Project->Add new
item menu is available? I would expect it to be.
For the reference IDL file generated automatically by ATL project, I find
it
is useful, but I still need to manually write something. :)

Of course, if you have a project without ATL support you have no ATL
wizards, so you have to write code manually.
I have also researched that MIDL compiler could help to generate IDL file
automatically, right?

No, the midl compiler parses IDL files and produces a tlb file which is your
binary file representation of a type library.
 
G

Guest

Thanks SvenC,


From your reply, I think I have to write IDL manually since I am not using
ATL. Could you refer some tutorial for me please?


regards,
George
 
S

SvenC

Hi George,
From your reply, I think I have to write IDL manually since I am not using
ATL. Could you refer some tutorial for me please?

I have learnt COM from books. Inside OLE from Kraig Brockschmidt is a
classic:

http://www.amazon.de/Inside-Microsoft-Programming-Kraig-Brockschmidt/dp/1556158432

But as mentioned before: create an ATL project (not attributed, as that
hides the IDL and it hides it badly!!!) add simple ATL objects. Add methods
to those objects and you will have an IDL sample to look at. It is really
dead simple. A library block which includes your coclass which can list the
interfaces they expose. And the interface definitions itself. You might want
some enums and that should be it.

Also use the MSDN for further details:
http://msdn2.microsoft.com/en-us/library/aa367061.aspx
 
G

Guest

Thanks Carl,


I have read through the link before. But it does not contain a sample of how
to write an IDL file, only concepts. Could you recommend some tutorials
containing samples?


regards,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top