Link to home
Start Free TrialLog in
Avatar of aossdev
aossdev

asked on

fatal error C1084: Cannot read type library file, Error loading type library/DLL.

I am developing on Vista and Visual Studion 2008.

I have a simple ATL application which imports one COM dll "xyz.dll"

#import "C:\abc\xyz\xyz.dll" named_guids rename_namespace("UTL") rename("DeleteFile", "XYZDeleteFile")

But I get an error :
1>d:\test\temp\temp\stdafx.h(25) : fatal error C1084: Cannot read type library file: 'C:\abc\xyz\xyz.dll': Error loading type library/DLL.

I am able to open 'xyz.dll' in OLE Viewer. It opens fine and shows all interfaces and coclasses.

Avatar of Deepu Abraham
Deepu Abraham
Flag of United States of America image

check your dll is registered using Regsvr32?
Avatar of aossdev
aossdev

ASKER

I had tried registering/build that COM dll. It did not  help.
I had seen the above link, It did not help.
If you have the IDL-file. You can use mktyplib or midl to generate the tlb-file.

So, if you only have a COM dll, you need to get an idl-file from it:

1. Visual Studio, start it and go to the meny Tools->OLE/COM Object Viewer

2. In that application, select meny File->View Typelib..

3. Select the COM dll and you will see the Typelib.

4. Select the meny File->Save as. Save it with an appropriate name. For example "mycom.idl"

5. start midl.exe or mktyplib.exe with the idl-filname as the argument. "midl mycom.idl"

Read MSDN for more info about midl and mktyplib

then try importing the tlb
Avatar of aossdev

ASKER

Have a COM dll, you need to get an idl-file from it:

1. Visual Studio, start it and go to the meny Tools->OLE/COM Object Viewer

2. In that application, select meny File->View Typelib..

3. Select the COM dll and you will see the Typelib.

4. Select the meny File->Save as. Save it with an appropriate name. For example "mycom.idl"

5. start midl.exe with the idl-filname as the argument. "midl mycom.idl"
I get an error :
: error MIDL2025 : syntax error : expecting a type specification near "LogMessageType"
: error MIDL2026 : cannot recover from earlier syntax errors; aborting compilation
 LogMessageType is enum defined some where down in IDL file. When I open this COM dll (xyz.dll) in OLE Viewer it opens up nice and also shows the enum defined.
Avatar of aossdev

ASKER

If I am correct it is not able to find the definition any ENUMs. As one by one it is complaining about all the ENUM for type specification. We can resolve this by moving the ENUM definition to the interface definition in IDL file.
But:
1. Is this the right approach?
2. What if two interfaces shares one ENUM. Defining the ENUMs in both the interfaces is just not sounding good.
Thanks,
Avatar of aossdev

ASKER

Coming back to main problem:
But I get an error :
1>d:\test\temp\temp\stdafx.h(25) : fatal error C1084: Cannot read type library file: 'C:\abc\xyz\xyz.dll': Error loading type library/DLL.


If I run my VS 2008 IDE not as an administrator then this compiles fine. And xyz..tlh/.tli  gets generated correctly. Problem is If I don't run my IDE as an adminsitrator then I get an error:-
1>Performing registration
1>Project : error PRJ0019: A tool returned an error code from "Performing registration"
ASKER CERTIFIED SOLUTION
Avatar of aossdev
aossdev

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial