Friday 16 September 2011

How do I integrate DLL or OCX files into my Visual Basic 6-created application?

I've written some simple apps to do annoying little tasks (changing processor affinity, handling some files, etcetera) for me and some friends. However, it requires some DLLs and OCX components that I added in Components. Problem is, my friends don't have Visual Studio installed, and the DLLs are OCXs aren't registered on their computers. I tried including the DLLs with the EXE, but it didn't work out most of the time.



I don't want to create an Installer, or use a program like ThInstall to merge them. Is there any native VB6 way to include DLLs and OCXs in the program, much like it does with icons?
How do I integrate DLL or OCX files into my Visual Basic 6-created application?
Merely including COM DLLs and/or OCXs isn't enough, you must also register them, by calling regsvr32.exe



It's surely possible to embed executable objects inside of other executables as custom binary resources, but there's no rational, realistic way to avoid writing them out to separate file[s] at runtime, COM objects would still need to be registered (as there is no VB6 support for SxS) and using early-bound COM would be very risky at minimum.



The LoadLibrary API accepts a file name, and it expects that file to be in correct PE format. There is no way to tell it to start loading at an offset, or to extract some resource from another file, then load it.



COM throws another wrinkle into it: referenced COM objects need to be installed and registered on the user's system before they are first referenced. For OCX controls, that happens when a form that contains an instance is initialized. For early-bound COM objects (usually DLLs) this happens when the first variable of a type exposed by the object is declared.



Ok so say you're willing to deal with all of the above, which includes extracting the executable resources to file and registering any COM objects, all before any of them being noticed as missing causes fatal errors in your app.



What happens when one of those components is updated? Blindly registering an older version could break other apps, which is not conducive to user happiness at all.



Bottom line, there's a reason professional apps are deployed using stable, capable installers: because it greatly increases chances your app will run out of the box that way. More, getting your app to run is not the only concern, it must be done in a way that purposely avoids taking undue risks with the user's system.



Good Luck
  • pc or mac
  • hair coloring
  •