Error 48 loading dll after rebuilding code, MSADO-related - dll

I am getting confusing and seemingly inconsistent results with one ActiveX DLL trying to create an instance of another.
Everything worked until we rebuilt our entire codebase, something which had never done since taking it over a few years ago. We previously just built pieces as we needed them.
The problem is occurring in multiple places, but here is a representative example:
Dim objMid As MiddlePiece.clsMyClass
Set objMid = CreateObject("MiddlePiece.clsMyClass")
This is hitting an error (48: Error in loading DLL) on the CreateObject line. I tried changing around the code and came up with the following results.
Dim objMid As MiddlePiece.clsMyClass
Set objMid = New MiddlePiece.clsMyClass
That gives me error 48 again.
Dim objMid As Object
Set objMid = New MiddlePiece.clsMyClass
That also gives error 48.
Dim objMid As Object
Set objMid = CreateObject("MiddlePiece.clsMyClass")
That one actually works.
Can anyone explain what the real difference is between these, and why only the last one works now, whereas at least the first one was working before?
I think I understand the difference between early and late binding, and that only the last example is an instance of late binding, but I've checked and confirmed that on both the build PC and the test machine, the registry contains the same version of MiddlePiece.dll, so I'm not clear on why this would fail.
The problem seems to stem from the fact that MiddlePiece.dll was built with Microsoft ActiveX Data Objects. There have been numerous issues related to this ever since we moved from Windows XP to Windows 7. The msado26.tlb library no longer worked for us, so we had to change our references to that library to refer to msado60_Backcompat.tlb instead. That seemed to work for a while, but we've since had more trouble with two different versions of msado15.dll. The newest version is breaking code in both VB6 and C++.

We replaced all references to msado60_backcompat.tlb with references to msado26.tlb, essentially undoing a "fix" we first implemented when we transitioned to Windows 7 about two years ago. This is basically all due to problems introduced by Microsoft. A good starting place to research the issue, for those who care to know is here. This allowed us to rebuild everything on the Windows 7 machine and resolve multiple issues.

Related

VBA not assigning object to variable

I am, perhaps foolishly, running an old and complex MDB (originally written in Access 2003, where everything worked smoothly for about a decade under good old XP) with lots of VBA in Access 2013 under WINE (well, Crossover Linux). Most things work, surprisingly, but I have a strange problem with automation. The following code launches an instance of Word that can be seen in task manager, but doesn't assign any object to oWord. It fails at oWord.Visible=True with error 91 and oWord is Nothing.
Dim oWord As Word.Application
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
I've tried early binding and late binding and more or less every line of code that can possibly be used to start Word. Using New Word.Application (or New anything) instantly crashes Access and WiNE's crash report is beyond me. I have exactly the same problem with automating Adobe Acrobat Pro, so this isn't about Office: Acrobat starts, but no object is assigned and I get error 91. Both programs launch happily from Shell. CreateObject is not always failing, either: oddly elsewhere in the database I have no problems with
Dim HttpReq As Object
Set HttpReq = CreateObject("MSXML2.XMLHTTP.6.0")
(but it fails without the version number).
I don't think this is to do with references, either, though I can list them if anyone thinks it's worth it.
Sorry this post is all over the place, but, to summarise.
I think my problem is probably with one of the dlls that WINE uses, and the advice I want is about which dll is likely to cause these particular problems if it is corrupt or incorrect. Then I can try different versions, maybe extract a clean copy from a Win 7 ISO (I've tried several copies of oleaut32.dll, which can be a sore subject with WINE, to no effect save that you can't run VBA at all with WINE's builtin version). I don't want to reinstall Office 2013 because it's so twitchy about activation under WINE. I don't want to risk blowing a perfectly valid licence testing it in a new wineprefix/bottle. I have a separate installation on a second workstation that's doing exactly the same thing. I'm running Lubuntu 18.04 LTS with WINE 3.0.5 and Crossover Linux 18; the wineprefixes are emulating Win 7.
Any help would be very, very gratefully received. I know this is a quixotic project, but so much works perfectly that this is really frustrating. Thank you.

Change on Visual basic 6 application, exe crashes

For my customer i had to do a change in a visual basic 6 application running on a windows xp computer.
It's nothing special, just communicating with a plc and functions as a user interface.
My changes work absolute perfect in developer environment(IDE), but when i create the exe it crashes when opening some forms or pressing some buttons. Some stuff works, and some stuff crashes.
Compiler in develop doesn't give any errors even after full compile!
I found some "bugs" by iterating the code and this really is just deleting some variables. (that already existed + It isn't a programmable error) The compiler doesn't give an error, just the exe crashes on it.
An example from bug that crashed:
sub On form_load()
Some code
Global_String_Variabel = "Something"
some code
End sub
By deleting the global string variable just in this form, it didn't crash any more.
It's weird because this peace of code already existed, works perfectly fine in develop but not in .exe
Does somebody have any idea why this could happen?
If I understand your question correctly, the program runs on your development machine both in IDE and compiled in both states, with the string assign and without, yet works only without on the client's machine. Something like this happened to me many years ago, and while it may not be your problem, you might at least be able to rule it out. The client may have a virus scanner that erroneously thinks that a segment of your code is malware. Just adding another line like x = x or something else benign can sometimes fix it.
You may also need to look further into other differences, like other things they have/run that you don't.
Not that it should matter but are you declaring the variable somewhere and using Option Explicit?

visual studio 2013 local variables not showing in debugger

I have a solution written in VB with some C# components. The solution uses some libraries from 2 outside sources. I have been working on this project for several months without issue. I cannot identify anything specific that I did to change my system or configuration. I was just working through the code, transitioning from an old set of library calls to the new library calls. The new library calls require complete rewrite so I change sections of the code and test to that point. Visual Studio 2013 debugger as of Friday morning will no longer recognize or show my local variables in this solution. The only things that appear in the Locals window are under Me. The code does work and I have it writing out to a text log file to confirm the values of variables at certain points, but the debugger has gone blind. When I add any of these local variables to Watch the response is " is not declared. It may be inaccessible due to its protection level."
Steps I've taken so far with no permanent success:
looked online and tried the few matches I found with no success
deleted the bin and obj folders and had the solution rebuild with no
success
recreated solution from scratch, copied over base files and rebuilt
solution and project (which worked for a few hours), until I did a
rebuild project and problem appeared again
updated to pack 5 and no success
I have opened my older projects and checked them. The debugger runs just fine and shows the variables. It is obviously something that happens during the rebuild process.
Any assistance would be greatly appreciated.
Thanks
Update:
Let me try to explain a little more clearly the situation.
I have an application I have built and am selling to some customers. Version 1 is installed and running at several locations. It is written in VB and uses some older COM libraries for a particular integration process.
The vendor is retiring the COM libraries. Their new libraries are in C#.
I created a new copy of my entire application (solution) and imported the new C# libraries. I have been going through and replacing the old code with the code for the new calls.I recompiled the solution and everything ran fine in debug.
The objects used with the new calls are completely different and there is limited documentation so I update a section of code and test to that point. Each time I "Save all Files", rebuild the project and test the changes. Everything worked fine for a few days. On Friday morning I started working on more changes and got an odd error. The system was not getting a proper value for a certain variable. When I went to check it in the WATCH window, debugger said it could not evaluate it. I figured something was hung up so I shut everything down and rebooted my machine. When I tried it again later, the same problem.
After several hours of no success I exited VS, renamed the folder to "OLD" and recreated the solution from the older version. Immediately everything was looking fine. I started making the changes and testing. Each time I did a rebuild, everything looked fine until the last change. Here I am again.
The code works fine up to the point I have updated. The only issue is that the debugger windows are not working correctly. If a variable is declared at the Class level outside the Sub, they can be seen. The only variables the debugger is blind to are the local variables within the running Sub.
I looked for anyone else with this issue and only found a few items. I tried the suggestions but no joy. I am left with having to temporarily define the variables outside the sub so I can see them while debugging.
I am on VS 2013 Update 5.
Do I need to move to VS 2015 to get around this?
Thanks again for your time and assistance.
I am assuming that you haven't changed versions of visual studio since the last time a rebuild worked for you.
recreated solution from scratch, copied over base files and rebuilt solution and project (which worked for a few hours), until I did a rebuild project and problem appeared again
Based on this, you create it from scratch and everything works until you do the rebuild right? But you are copying the base files still and you have new library calls since the last time a rebuild didn't mess up the locals window. So one of those is almost assuredly the culprit.
Since the library calls seem to be the thing that changed based on your post start there. If you go back to the old code and do a rebuild does it fix it? Assuming so, put the library calls back one at a time until it breaks.
If going back to the old code doesn't fix it, create from scratch with the old code and copy over the base files and rebuild. If that fixes it, add new library calls one at a time and rebuild after each until it breaks.
If that doesn't fix it either, then you will need to dig deeper on what else might have changed.
You are copying base files so eliminate those as the problem if you can:
Are you able to use placeholders instead of the base files or something that won't necessarily work as a finished product but that will allow you to debug, rebuild, debug again to see if the problem is related to one of them? Check the dates on the base files and ensure that they haven't changed since the last time a rebuild worked.
Something you could do concurrently could be to have have a colleague do a rebuild on their machine and see if the same issue comes up for them. It would (almost) completely eliminate the possibility that it is a configuration / program corruption issue on yours. Alternately, there are some free vb.net compilers online that you can upload files and code to. I'm not sure if that would be practical for you (due to the components of your program and/or sensitivity of the data) or not and haven't ever tried any where there is C# code in there but I wouldn't think that would be an issue.

VBA in Excel: "Can't find project or library" error when executing in 2007

Using VB for Excel in Excel 2003, I have no problems executing code with some non-declared variables:
numberOfBooks = 0
However, if I try to execute the same code in Excel 2007, I get a "Can't find project or library" error message.
I looked at Tools > Options and I don't have checked "Require Variable declaration". In Excel 2003 I did not use Option Explicit
What am I doing wrong? Thank you very much.
I have seen this advice (check references) a number of times and it makes sense!
However, when the fault: "can't find project or library" develops, you are in run mode and I cannot get out of it?
Waht am I missing?
I'd definitely second Daniel Cook's suggestion of checking your references list; that may be it. However I've come across some situations over the last couple of months where that error will occur in an Excel 2007 even if there is nothing wrong with the references. In part it seems to relate to the security updates that were released in August 12 ( http://technet.microsoft.com/en-us/security/bulletin/ms12-aug ). It caused some breakage in the mscomctl.ocx. The problem and (one) resolution (basically, re-registering the .ocx) is discussed in this IBM link which relates to an Excel add-in for an OLAP product called TM1: http://www-01.ibm.com/support/docview.wss?uid=swg21608271. (The error messages aren't the same as the ones that you've been getting, but I DID get your error messages on another add-in that I wrote which were not missing any references, and it turned out to be the same problem.)
The other thing I'd suggest doing is a purge of your .exd files as discussed here: http://support.microsoft.com/kb/290537 I've also found that those can cause bogus library errors, particularly after a version upgrade.
As for anything else you're doing wrong, well, personally I tend to skin anyone who works for me without using Option Explicit. 8^>
One of our companie's excel-macros (which ran quite frequently without any issues so far) all of a sudden came up with exactly the same error.
We didn't touch the code for like forever. And I honestly have still no idea what actually caused this error. Mistery Microsoft maybe? Anyways.. I finally were able to fix the bug.
Even though "Require Variable declaration" was disabled and Option Exlicit was not set in my case, declaring the variable first did the trick for me:
Dim numberOfBooks As Integer: numberOfBooks = 0
I hope this saves some headaches.

Spurious "User-defined type not defined" error in Microsoft Word VBA

I have a Microsoft Word template with some code and some references, that has been working fine for months but has just started throwing up a spurious "User-defined type not defined" error whenever I open it or try to compile it.
I know it's a spurious error because I haven't made any significant changes to the code. In fact, I've rolled the code back to the last deployed version (which I know works fine) and I still get the error. I've also commented out all the code in the template and I still get the error. I've also removed and re-added all references (same error), and removed all the references and added them back, one by one, until the resultant compile errors are resolved, at which point I'm left with the spurious "User-defined type not defined" error. (I'm going to call this a UDTND error, from now, to avoid driving you all mad.) I think the error started popping up after I rebooted my PC. It only happens with this template, but I don't see how it can be anything to do with this template.
Interestingly, the error is subtly different from a genuine UDTND error in the following ways:
No code is highlighted when the error is displayed.
The dialog is titled "Microsoft Visual Basic", and contains the error message but, unlike a real UDTND error, doesn't contain the text "Compile error:";
It happens when the template is opened, not just when it's compiled (at least, I think that's different from a normal error).
I've tried Googling it but I just get a bazillion results from novice developers asking why they get this error, with responses telling them that they either need to declare the missing type, correct the spelling of the offending variable type, or add a reference to a missing library. I've been banging my head against my screen all afternoon, and that's helped about as much as all the other things I've tried (i.e. not at all). I have a feeling that this is something to do with a messed-up reference, but afaict they're all fine, and I've removed and re-added them, which I would expect to resolve that sort of problem.
Any ideas...?
Your trouble-shooting on References is sound. Once upon a time (and I don't recall the precise error) I was at the same point, and the reference ordering was the key. When you're designating References, you'll notice a "Priority" adjustment feature. Experiment with that and you may solve this.
I have had "User-defined type not defined" problem on several occasions when compiling Microsoft Visual Basic 6 (MSVB6) code that was compiling without a problem earlier. It seems to happen after I have had a long coding session without rebooting the computer. As you can guess, I have been using Microsoft operating systems. I currently am using Windows XP. Rebooting the computer usually fixes the problem as it so often does on Microsoft operating systems.
I have read that fully qualifying declarations also can help, e.g., "Dim oBar as Foo.Bar" instead of "Dim oBar as Bar". I have not tried this approach however.
I had a very similar problem.
My problem appeared (I think) just after I made a Search and Replace that I canceled (Ctrl+Z). There was not highligting of the problem, only the ""User-defined type not defined" error message when I compiled.
I tried:
1) restarting computer
2) changing reference ordering
3) removing functions/procedures, modules one at a time.
Didn't work. My project was written in Excel VBA and here was the solution I found.
THE SOLUTION:
I opened a new Excel file and opened the Visual Basic Editor. I then copied all Forms, Modules, and Class Modules one by one into the new file. I then Copied the Control Objects (3 Commandbuttons) from the old sheet into the new one. Now the new file was identical to the old project - only the ""User-defined type not defined" had gone and problem was solved.
Yea references would be the first step in troubleshooting this problem as already stated, but failing that id start commenting out the code in any event procedures running at start up (my experience is only with Access VBA though)
I had the same problem with Excel 2013.
It started when I did a search and replace on the name of a Custom Class.
I changed the name of the Class after I did the search and replace on all references to it and the spurious error started immediately after that.
I reverted to an earlier version ad confirmed that the problem was not there and then did the same search and replace and re-name and got the exact same behaviour again.
The Custom Class that I changed the name of only had one consumer and it was also a custom class.
I exported, removed and re-loaded the sole consumer class and the problem was fixed.
Check out this link for a Microsoft bug that might be related.
TLDR:
The reference to a package/addin/whatever probably needs to be re-referenced. Check Tools -> References in the Menu.
Also it appears that if you install Microsoft Security Advisory 960715, that certain controls are killed. There are fixes which may or may not work for you. A good article is on this blog:
VSOD Blog