vb6 user-defined type not defined error on full compile - vb6

I have some vb6 code I have not compiled in a long time. The last compile is in production. Now I get an error "User-defined type is not defined" when I do a full compile. I'm sure there is a reference missing. But there is no code that is hi-lighted. And I cannot seem to find what reference might be lost.
Any clues as to what I can do to find the missing reference would be very helpful.
Thanks!
Dave

I've had that happen before it drove me crazy!! But then I found this:
 
http://support.microsoft.com/kb/190197
 
Occurs when compiling with binary compatibility on. The above solution suggests turning off binary compatibility and re-compiling - then missing reference will then be highlighted.
Other steps you can try:
Rather than turning off BC for everything look for ones that have
been recently changed
search C: drive and dev folder and delete any
*.oca files
also look in the vbp file for any oca references

You need to ensure that you have the appropriate items checked in the References dialog. This is outside the code and they are listed in the VBP file (text file).
EDIT Corrected reference storage. Thanks MarkJ

Make sure all of your object types are spelled right. A simple error like spelling Variant Varient can cause this error as well.

Are you still using the same machine in which the original compile was made and / or with the same OS
?
If the answer is no, then there is a chance that VB6 or its like linked to a reference which is no longer available in Win7 or later, this may also include the compiler if you are using a modern version of studio.
Since the code is also in VB6, if you are using any outside commercial controls, and again if not on the same machine, you would loose those links as well if you did not port over the library.

Related

Does the VB6 IDE highlight the wrong text when certain errors occur?

I'm pretty sure this is a bug in the VB6 IDE but I haven't found any definitive reference to it before...
Sometimes when I've loaded a project which has some dependency issue (missing reference, etc.) the IDE will show an error like this:
("Compile error: Can't find project or library")
Note the text which it highlighted is a call to the UCase$ function which is essentially built into the language. There's no way its library is actually missing.
Is this a known bug? Is there any rhyme or reason to the text which is selected when this happens?
Update: The standard libraries which include things like UCase() are included so that is not the actual problem. The highlight really seems to be nonsensical.
VB can do some strange things, but... check both the content and order of your References. UCase$() isn't 'built into the language' in the way you might think -- it's not in the VB runtime, but in the VBA runtime, which must be included as a reference.

Where is ERROR_PENDING defined?

The MSDN documentation for CommitTransactionAsync indicates it may produce an ERROR_PENDING error code. However, this error code does not seem to be defined in winerror.h, nor any other header reachable from ktmw32.h or windows.h (using the version of the Windows SDK included in Visual Studio 2010). In fact, I cannot find a single file containing the text ERROR_PENDING anywhere in the Windows SDK 7.1; manually going through the list of System Error Codes doesn't reveal it either. Where can I find the definition of this elusive error code?
Experimentation shows CommitTransactionAsync to produce ERROR_SUCCESS - is this a simple matter of the documentation being wrong?
It's a doc bug. #flashk's guess is correct: it can produce ERROR_IO_PENDING. I am submitting a bug to the doc owner today. Thanks!

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

What is the Reference that we have to add to use the Format function in Visual Basic 6.0?

I'm using VB 6.0 and it gives me:
Compile Error:
Can't Find Project or Library
in this sub:
Private Sub MDITimer_Timer()
Dim textStr As String
textStr = Format(Now, "dd-mm-yyyy hh:mm:ss")
StatusBar.Panels(1).Text = textStr
End Sub
I made it like this and the error still was in the Format function (so it is not a StatusBar problem).
Can you tell me what is the Reference that we have to add to use the Format function? Or if a Reference is not needed, what do we have to do to make this work?
Problem's more likely to be the StatusBar (In the Microsoft Windows Common Controls, MSCOMCTL.ocx). Format is built into the VB6 language, you shouldn't need any reference at all.
EDIT Format is in VBA.Strings. I think this is in the "Visual Basic for Applications" reference, MSVBVM60.dll. I thought the VB6 IDE prevented you from unticking the reference.
You probably overloaded Format() with a declaration of the same name. Have you tried calling VBA.Format() instead?
You should also use Format$() to avoid the unnecessary overhead of working with the Variant result Format() returns.
I know this is old but in case someone else comes down this road...
When I had this issue found the real problem was nothing to do with MSVBVM60.dll which as said cannot be disabled as a reference.
What the error is complaining about is that a reference defined in the project is not resolved. It is not saying that the missing reference necessarily has anything to do with the function it is highlighting. What I assume the compiler is doing is sequentially searching the defined references to find the function. During that search it finds one of the references is not resolved (ie the dll or whatever is missing). This causes it to stop the search and give the error.
Reason using VBA.Format helps is that it tells the compiler where to search avoiding the need to scan through all the references.
Solution: check references defined in the project (Project => References) and make sure they are all resolved.
Usually an unresolved reference will have the word 'MISSING:' in front of it. The path shown for the reference is where the project thinks it should be, it does not mean it is there.

Strange VB6 build problems (related to nlog)

This I think is related to my use of the nlog C++ API (and my question on the nlog forum is here); the purpose of my asking this question here is to get a wider audience to my problem and perhaps to also get some more general ideas behind the VB6 IDE's failure to build in my particular scenario.
Briefly, the problem that I am having is that I am having trouble building VB6 components which reference unmanaged C++ components which have calls to nlog's C\C++ API (which is defined in NLogC.DLL). The build problems are not occurring during compile time, they are occurring when the binary is being built which suggests to me that it's some kind of linker type problem? Don't know enough about how VB6 binaries are produced to tell. The VB6 binary is produced, but it is corrupted and crashes shortly after it is invoked.
Has anyone had any similar experiences with VB6 (doesn't have to be related to nlog or C++)?
edit: Thanks for all the responses to this rather obscure problem. Still no headway unfortunately; my findings since I posted this:
'Tweaking' the compile options doesn't appear to help in this problem.
Adding a reference to the nlog-enabled C++ component from a 'blank' VB6 project doesn't crash it or cause weird build problems. So it isn't a 'native' VB6 issue, possibly an issue with the interaction between nlog and the various components and 3rd party libraries used by other referenced components?
As for C++ calling conventions: the nlog-enabled C++ component is - as far as I can see - compliant to these conventions and indeed works fine when referenced by VB6 as long as it is not making any nlog API calls. Not sure if the nlogc.DLL itself is VB6 compliant but I would have thought that that is immaterial since the API calls are being made from the C++ component; VB6 shouldn't know or care about what the C++ component is referencing (that's as far as my understanding on this goes...)
edit2: I should also note that the error message obtained during build is: "Errors during load. Please refer to "xxx" for details". When I bring up the log file, all that there is in there is: "Cannot load control xxx". Interestingly, all references to that particular control disappears from that particular project resulting in compile errors if I were to try to build again.
Got around the problem by using NLog's COM interface (NLog.ComInterop.DLL) from my unmanaged C++ code. Not as easy to do as the C\C++ API but at least it doesn't crash my VB6 components.
I would try tweaking some of the Compile options found in the Project, Properties menu, Compile panel to see if they yield any additional hints as to what is going wrong.
For example if you compile the executable to p-code rather than native code does it still crash on startup.
What error message do you get when you run your compiled binary?
I doubt the compiler/linker is the problem: project references in a VB6 project are not linked into the final executable. A project reference in VB6 is actually a reference to a COM type library (which may or may not be embedded in a .dll or other binary file type). Project references primarily serve two purposes:
The IDE extracts type information from the referenced type libraries which it then displays in the Object Browser (and in the Intellisense drop-down)
At compile-time, the compiler extracts the type information stored in the referenced libraries, including the CLSID of each class that you instantiate, and embeds this data into the executable. This allows your executable to create instances of classes contained in the libraries that you referenced.
Note that the compiled binary doesn't link to any code in the referenced libraries, and it doesn't even contain the filenames of the referenced libraries. The final executable only contains the CLSID's and other type information that it needs to instantiate COM objects at run-time.
It is much more likely that the issue is with NLog, or with how you are calling it from your code, rather than something gone awry in the VB6 compile process.
If you think it might be a linker problem, this should crash it the same way:
create a new standard project (of any kind)
add a new module and copy the "declare"-statements into it
compile
If it doesn't crash it is something else.
It would help an exact description of the error or a screenshot of what going on.
One thing to check is wherever NLogC.DLL or the C++ DLL you built have the correct calling convention defined. Basically you can't have the DLL function names mangled or use anything but the STDCALL calling convention. If the C++ DLL has not been created with those two things in mind then it will fail to work with VB6.
MSDN Article on Calling convention.
"Cannot load control xxx" errors can be caused by .oca files which were created from a different version of an .ocx than currently used. If that is the case, deleting the .oca files helps.

Resources