.NET Forum / Languages / Managed C++ / September 2007
tlbexp command
|
|
Thread rating:  |
George - 11 Sep 2007 07:42 GMT 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
Brian Muth - 11 Sep 2007 17:31 GMT > 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
George - 12 Sep 2007 12:24 GMT 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
> > Hello everyone, > > [quoted text clipped - 10 lines] > > Brian Ben Voigt [C++ MVP] - 12 Sep 2007 14:49 GMT > Thanks Brian, > [quoted text clipped - 8 lines] > > 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".
> regards, > George [quoted text clipped - 17 lines] >> >> Brian George - 13 Sep 2007 04:56 GMT 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
> > Thanks Brian, > > [quoted text clipped - 34 lines] > >> > >> Brian Carl Daniel [VC++ MVP] - 13 Sep 2007 06:26 GMT > Thanks Ben, > [quoted text clipped - 4 lines] > 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
George - 13 Sep 2007 08:20 GMT 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
> > Thanks Ben, > > [quoted text clipped - 9 lines] > > -cd SvenC - 13 Sep 2007 06:31 GMT 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?
-- SvenC
George - 13 Sep 2007 08:26 GMT 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
> Hi George, > [quoted text clipped - 15 lines] > -- > SvenC SvenC - 13 Sep 2007 09:11 GMT Hi George,
> I am using Visual Studio 2005 and I can not find any idl file in the > project [quoted text clipped - 3 lines] > 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.
-- SvenC
George - 13 Sep 2007 10:20 GMT 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
> Hi George, > [quoted text clipped - 14 lines] > -- > SvenC SvenC - 13 Sep 2007 10:40 GMT 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.
-- SvenC
George - 13 Sep 2007 10:56 GMT 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
> Hi George, > [quoted text clipped - 25 lines] > -- > SvenC SvenC - 13 Sep 2007 11:39 GMT Hi George
>> Just use Project->Add new item and select "Visual C++ / Code / Midl >> file". [quoted text clipped - 9 lines] > 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.
-- SvenC
George - 15 Sep 2007 17:32 GMT 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
> Hi George > >> Just use Project->Add new item and select "Visual C++ / Code / Midl [quoted text clipped - 29 lines] > -- > SvenC Carl Daniel [VC++ MVP] - 15 Sep 2007 17:48 GMT > 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? http://msdn2.microsoft.com/en-us/library/aa367091.aspx
is a good place to start.
-cd
George - 16 Sep 2007 09:36 GMT 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
> > Thanks SvenC, > > [quoted text clipped - 6 lines] > > -cd SvenC - 15 Sep 2007 17:56 GMT 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
-- SvenC
George - 16 Sep 2007 09:38 GMT Thanks for all of your help all the way!
have a good weekend, George
> Hi George, > [quoted text clipped - 18 lines] > -- > SvenC
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|