Problems referencing com dlls in vs 2010 - visual-studio-2010

I'm running a 32 bit ver of win7 in a vm. I am trying to reference 5 com dlls (VB6) in my .net project. These dlls (and their dependencies) are registered ok since I can use them natively as they form a part of another app and that app is working fine.
I try to set a reference to any of them directly in vs and I get the error message - Library not registered (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
However, if I set a reference to another com component (which I don't want to reference but which in turn does reference these libs) I find that the references to these com dlls (which I do want to reference) gets set correctly in vs. I then just need to remove the ref to the unwanted dll and everything seems to be good to go.
If I look at the GUID and version details of one of the successfully referenced component, they appear to be the same as the GUID and version that appears in the caption of the error form, when I unsuccessfully try and set a reference to the same component directly.
BTW I have tried repairing the VS installation to no avail
I was wondering if someone could explain what I am doing wrong.
EDIT: Follow-up following Hans suggestion
So I ran
tlbimp mylib.dll
and it returned a TI1006 error - Output would overwrite the input file. So following suggestions found, I then issued
tlbimp mylib.dll /OUT:interop.mylib.dll
and this then returned the error
TlbImp : warning TI3011 : Type library importer has encountered an interface not derived from IUnknown: '_HiddenInterface'. The interface is skipped.
TlbImp : error TI1033 : Cannot find type 'ADODB._Recordset_Deprecated' in 'ADODB, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. There could be a mismatch between the referenced assembly and the type library.
But I'm not sure if this is a red herring since this lib could be referenced when successfully referencing the different higher level dll. I have tried with a dll which doesn't reference ADODB and that seems to work using tlbimp. So, e.g.
tlbimp myNONADODBlib.dll /OUT:interop.myNONADODBlib.dll
works from the commandline. However
tlbimp myNONADODBlib.dll
still generates the error TI1006 - output file will overwrite input file, and I cannot reference this into my .net project
EDIT:
There seems to be a problem with ADO and Win7 SP1. http://support.microsoft.com/kb/2517589 which would account for the deprecated error message (TI1033) I was getting, but not why VS was failing to create a CCW for the dll I can manually create a CCW via tlbimp.
EDIT (12/03/28 10:40):
So I have rebuilt the com dll with the suggested tlb. I can now successfully run
tlbimp mylib.dll
without getting any error messages and it appears to complete successfully. However, when I try and add a reference to that dll in VS, I still get the same original error message ( Library not registered (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))). I have checked the registry and the registration looks ok i.e. it is pointing to the correct path - I'm wondering if it is a permissions-type issue - but I am running vs as admin.
EDIT (12/03/28 10:15):
So I ended up creating a new completely new vm with the same environment - and it worked ok. So I've no idea what is going on other than some registry corruption perhaps!
Many thx
Simon.

You need to use REGTLIB.exe to register the type library of the DLLs.
Type library registration is separate from component registration - the type library supports the introspection/type explorer functionality, and isn't usually required for running a precompiled application, though it may be required for compilation.

Related

Trying to debug from C# into VB6 yields TYPE_E_CANTLOADLIBRARY?

I have a VB6 DLL being accessed from some C# code.
Using the compiled & registered VB6 DLL there is no problem. But when I load the VB6 source into the VB6 IDE and run the project, the next run of the C# code will fail with the error below.
Stopping the running DLL in the VB6 IDE will again allow the C# program to work from the compiled DLL.
The VB6 DLL is compiled with binary compatibility.
The error message I receive in C# is:
An unhandled exception of type 'System.InvalidCastException' occurred
in appname.exe
Additional information:
Unable to cast COM object of type 'dllname.classnameClass' to
interface type 'dllname._classname'.
This operation failed because the QueryInterface call on the COM
component for the interface with IID
'{D8AB6D65-F5E7-4B9C-A039-67DDC630E5F7}' failed due to the following
error:
Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A
(TYPE_E_CANTLOADLIBRARY)).
Specifically this error occurs when the C# code tries to access any part of the interop object which actually comes from the underlying COM object. But accessing .NET Object-derived things like .ToString() work fine on that object.
Why am I getting this error?
Furthermore:
If I compile the C# code when the VB6 code is NOT running, it builds fine. But compiling when the VB6 code IS running, then I get an error:
BC30002 dllname.classname is not defined.
Thanks
Maybe someone else will have a deeper understanding, but this is what I eventually figured out:
Running either Visual Studio (.NET) or Visual Basic 6 as ADMIN while debugging in this scenario would cause the error. Running BOTH as WITHOUT ADMIN rights then it would work.
The quandary is that admin rights are needed for certain build operations (specifically, registering COM DLLs automatically). So that was the pitfall; ultimately I had to repeatedly switch between admin/non-admin settings for both tools in order to code-test-modify...
Note - when I've debugged in a different scenario where the program is a VB6 EXE debugging into C# code, this was never a problem. Everything could run in as admin no problem.

Object library not registered VB 6

I am trying to open a VB project on Windows 7 64 bit version. I installed VB 6 successfully and registered the required components (.ocx) too. For the application, I use a third party tool called TX - Text Control and need to register that too using the registry server tool as follows:
C:\Windows\SysWOW64>regsvr32 tx4ole.ocx
Upon opening up the project, I get a bunch of errors like "Object Library not registered" even when Ive registered the component as above. Upon pressing "OK" and proceeding, it complains about the texteditor.ocx not registered. But I did register that too. I get a log message in the project directory which has the message as follows:
Line 74: Class Tx4oleLib.TXTextControl of control txEditor was not a loaded control class.
Tried all un-registering all the components, un-installing VB6, fresh-installing using administrator and registering all the above components again with administrative privs but same result. Any idea why that would happen ?
I just encountered the same problem and actually found two issues. The first is "Object library not registered" issue. I solved that using another answer on Stack Overflow.
Basically I ran the command regtlibv12.exe msdatsrc.tlb from C:\Windows\Microsoft.NET\Framework\v4.0.30319.
The second issue was that I couldn't compile because of a missing reference. To fix that, I clicked project->References and then unchecked all references. I then reran the project (which failed). Next, I added back the necessary references using project->References. For missing references I used the browse button to find and add the missing references.

createObject in VB6 does fails when running exe

I have a VB6 program which tries to run a DLL written in C#.
This DLL has a COM interface so I can create an object of a class in it with "CreateObject".
The problem is that it runs and works well when I run it from the VB6 IDE, but when I make an EXE and try to run it, it throws the exception:
"Automation error. The system cannot find the file specified (-2147024894)."
Why is it happening and how can i solve it?
Look at Project, References in the IDE and look which dll or ocx file belongs to the object you are referencing with CreateObject (the Object Manager might also help to find out).
This dll file must be available when the exe is compiled, too. Usually, you need to have it registered with regsvr32.exe.
A technique I use to figure issues of this type is to open the add reference dialog in Visual Basic 6. I scroll the list of available COM Libraries and see if the problem DLL is listed. If it is then CreateObject should work, you should be able to assign it do a variant variant and use late binding to access it's members.
In addition try temporally set a reference to the variable and instead of using CreateObject use the = New and see what error messages, if any, it gives you. Generally I found them to be more informative then the ones thrown by CreateObject.
Finally it would help if you post the reason why you are choosing to use CreateObject instead of setting of a reference. If the DLL is a known object that will be continually used by the program then a reference should be set and early binding generally used.
Finally it may be that the error is resulting from a dependency of the C# COM DLL not the DLL itself. If for example I was to take a Com Library and properly register it but it relies on the COM Library Widget2000 and it NOT registered then it will throw the automation error. Especially if you are testing the EXE in it's installed environment and not the environment in which you complied it.
For example suppose I have a CAD program written in VB6 and I have source tree that begins with MyCAD. THe exe is in MyCAD/MainEXE and the shape library is in MyCAD/ShapeLibrary. I run the IDE everything is fine. Then I make my setup and goto my test machine and install it and it error on the creation of shapelibrary.
The first thing I would do it check if MainEXE will run straight out of the MainEXE directory of my source tree. That test will eliminate whether it is a install issue or a quirk of the IDE vs complied version. Then I would look at the setup and see what not being registered. Also look at either the source for the C# library or the setup for the library and see what dependencies it needs. Since it a complied COM DLL you should be able to use a dependency walker tool to see what COM references it needs. Finally make sure the correct version of the .NET framework is installed.
If you are compiling the C# DLL on your test machine - make sure you have ticked the register for COM Interop setting. If you are not compiling on the same machine you need to run RegAsm with the /codebase option.
try compiling it as an installer and include the dll/com that you use in the compilation of the installer package so that the dll/com that you use will be include in the compilation of your exe.., and install it in the windows not just copy past it.

Access violation when compiling in debug

I'm trying to profile a C++ project in Embarcadero RAD Studio 2010. To do this I wanted to use AQTime, but I'm running into a bit of a problem.
I can compile and run the application in release mode. But when I compile in debug mode, using the settings mentioned at http://smartbear.com/support/viewarticle/18053/, I get an access violation.
... faulted with message: 'access
violation at 0x062324bd: read of
address 0x62324bd'. Process stopped.
Use Step or Run to continue.
It seems to come when I load a bunch of dll's at the startup. But since it goes well in release mode I can't seem to figure out what could be the cause.
When the access violation occurs I get thrown out into assembly and that isn't one of the languages I'm fluent in ;)
EDIT : When scanning the .exe with Dependency Walker I get a message saying that the following files can't be found
CC32100MT.DLL
INET140.BPL
RTL140.BPL
VCL140.BPL
IESHIMS.DLL
Could this be the problem somehow? Are these debugspecific or is Dependency Walker not giving me correct information? The same files are said to be missing when I try a release compiled version to.
I'm running on Windows 7 x64, if that could be part of the issue. I have had problems before with the symlink-look-alike (user/AppData/Local...) that MS used for some folders. Notably when I ran an apache server and the htdocs folder actually wasn't located where the server thought it was (and where it appeared to be) :)
Have you tried disabling dynamic rtl which can be found in the C++ builder linker options pane?

How to fix "Unexpected error (32801)" when compiling VB 6 program?

I have to maintain an old VB 6 ActiveX DLL called by another third-party program for which I have no sources. This DLL works and compiles fine against the API of said program for about 6 years and 3 major versions.
But now when I try to compile the DLL against a new major version the mentioned error occurs. It seems the error occurs before "my" code is called so there´s no use debugging or logging. The only remedy was to compile w/o binary compatibility which is no real option. My Google search turned up quite some people with the same problem but no solution.
Does anybody here know how to fix this issue ?
I finally figure out how to diagnose VB6 error 32801 in a systemic way.
My theory is When the VB6 compiler is creating a project or binary compatible library, the compiler decompiles the type information from the referenced library. Error 32801 occurs the source code's type information is not the same as the referenced library.
There is a tool called OLEView. This tool can decompile the COM type information into an IDL text. What I do is decompile the referenced library in to IDL and take the last good build of the failing library. Most times it is a build server version but the build does not work on a developer workstation. Decompile the last good build. Use a text comparison tool, like WINMerge, and find the differences between the type libraries. The differences make it easy to track down the problem.
Depending on the difference will determine how to correct. Mitigation can be done by either correcting the reference DLL, or by source code correction, or source code references.
It sounds like one of the types in the interfaces defined in your new DLL is different from one in the previous DLL. I'm deducing you use types defined in the third party program in your public interfaces of your DLL. It sounds to me like the third party has changed the definition of one of the types but kept the name and GUIDs the same. You could use something like OLE/COM Object viewer to check whether that's true. If it is true then you can complain to the publisher of the 3rd party program. Do you have enough political power to succeed?
Bruce McKinney, the guru who wrote Hardcore Visual Basic 6, ran into the same issue with a structure in a type library, where he changed some of the member types. The only fix he could find was (essentially) to break binary compatibility - and that's after some correspondence with the VB6 compiler team, who he knew fairly well. I don't think anyone else could do better.
There is a discussion about this error on devx.com that seems to indicate that the problem stemmed from Microsoft's Scripting Runtime (scrrun.dll).
FileSystemObject compatibility Unexpected error (32810)
Does your DLL reference that library? If so, can you remove the reference (e.g., replace FileSystemObject functionality with intrinsic VB file handling functions and/or API calls).
Are any of the files associated with the core project being compiled marked as Read-Only (i.e. not checked out of SourceSafe or similar repository)?
*.exp
*.vbw
*.lib
---------------------------
Microsoft Visual Basic
---------------------------
Unexpected error (32810)
---------------------------
OK Помощ
---------------------------
This the message I was getting trying to reference in VBIDE an old OCX that has been recompiled recently.
After somewhat long research the offending lines of code causing this error appeared to be
Property Get MouseActivate() As BookmarkEnum
Just changed this to
Property Get MouseActivate() As Boolean
. . . and the error was gone.
BookmarkEnum is an enum from ADO. Our build server is Server 2003 and my dev machine is Win10. The project references ADO 2.8 but apparently this typelib has some differences on Server 2003 vs Win10

Resources