Jeff Webb, Mike McKelvy, Ronald Martinsen, Taylor Maxwell, Michael Regelski September 1995 Special Edition Using Visual Basic 4 - Chapter 16 1-56529-998-1 Computer Programming computer programming Visual Basic OLE database applications ODBC VB VBA API This book is an all-in-one reference that provides extensive coverage of every topic and technique for creating optimized and customized applications with Visual Basic.

Chapter 16

Distributing OLE Container Applications


OLE container application often have special requirements not normally handled by installation programs, such as those generated by the Setup Wizard. This chapter explains those special requirements.

In this chapter, you learn how to do the following:

Using the Setup Wizard

Ordinarily, you can use the Setup Wizard shipped with Visual Basic to create distribution disks for your application. The Setup Wizard takes care of these installation tasks:

OLE container applications have additional requirements, however. To correctly install an OLE container application, you may add the following tasks to the installation process:

Updating the System Registry

The .LST file generated by the Setup Wizard contains information about how to register each file it installed. A typical entry in the .LST file looks like this:

File1=2,,COMDLG16.OC_,COMDLG16.OCX,$(WinSysPath), _
$(DLLSelfRegister),8/23/94,69904,4.0.12.10

The sixth argument, $(DLLSelfRegister), indicates what action the Setup program takes when registering the file. Possible values for the sixth argument are as follows:

Value Meaning
None. File is not registered.
$(DLLSelfRegister) Use the DllSelfRegister function to register the file.
$(EXESelfRegister) Use the ExeSelfRegister function to register the file.
filename Use the Registration Info Editor (REGEDIT.EXE) to merge the file with the system registration database.

If your application uses a .REG file, be sure to edit the .LST file to register the application at setup. For example, the following lines copy the .REG file and registers the OLESTORE application:

File3=2,,OLESTORE.RE_,OLESTORE.REG,$(APPPATH),,9/22/94,2364
File4=2,,OLESTORE.EX_,OLESTORE.EXE,$(APPPATH),OLESTORE.REG, _
9/27/94,18192,1.0.0.0

Visual Basic applications that expose OLE Automation objects are automatically flagged as $(EXESelfRegister). If these applications provide a .REG file as well, save the registration information that Visual Basic creates into the application’s .REG file, then use that file to register the application at setup.

Checking for Installed OLE Objects

Applications that rely on other applications for objects can be a nightmare to maintain. You should never assume that users have all the object applications required by your application. To check for installed OLE object applications, query the system registration database before you install your application.

The GetRegisteredList procedure (listing 16.1) returns an array containing the names of all the installed OLE applications from the target system’s system registration database:

Listing 16.1 Checking for Installed OLE Objects

‘ 16LIST01.TXT
Const HKEY_CLASSES_ROOT = 1
#Const Win32 = 1
#If Win16 Then
Declare Function RegOpenKey Lib "Shell" _
(ByVal HKeyIn As Long, ByVal LPCSTR As String, _
HKeyOut As Long) As Long
Declare Function RegCloseKey Lib "Shell" _
(ByVal HKeyIn As Long) As Long
Declare Function RegEnumKey Lib "Shell" _
(ByVal HKeyIn As Long, ByVal SubKeyIn As Long, _
ByVal KeyName As String, ByVal KeyNameLen As Long) As Long
Declare Function RegQueryValue Lib "Shell" _
(ByVal HKeyIn As Long, ByVal SubKey As String, _
ByVal KeyValue As String, KeyValueLen As Long) As Long
#ElseIf Win32 Then
Declare Function RegOpenKey Lib "Shell32" _
(ByVal HKeyIn As Long, ByVal LPCSTR As String, _
HKeyOut As Long) As Long
Declare Function RegCloseKey Lib "Shell32" _
(ByVal HKeyIn As Long) As Long
Declare Function RegEnumKey Lib "Shell32" _
(ByVal HKeyIn As Long, ByVal SubKeyIn As Long, _
ByVal KeyName As String, ByVal KeyNameLen As Long) As Long
Declare Function RegQueryValue Lib "Shell32" _
(ByVal HKeyIn As Long, ByVal SubKey As String, _
ByVal KeyValue As String, KeyValueLen As Long) As Long
#End If
Function GetRegisteredList() As Variant
Dim hkroot As Long, x As Long, lLen As Long
ReDim strInstalled(99) As String
Dim strKeyID As String * 80, strKeyDesc As String * 80, _
iKeyCount As Integer
x = RegOpenKey(HKEY_CLASSES_ROOT, "", hkroot)
lLen = 80
Do
strKeyID = String(lLen, 0)
If RegEnumKey(hkroot, iKeyCount, strKeyID, lLen) = 0 Then
lLen = 80
If Mid(strKeyID, 1, 1) <> "." Then
strKeyDesc = String(lLen, 0)
x = RegQueryValue(hkroot, strKeyID, strKeyDesc, _
lLen)
strInstalled(iKeyCount) = strKeyDesc
lLen = 80
End If
iKeyCount = iKeyCount + 1
If iKeyCount > UBound(strInstalled) Then
' Add elements if the array gets full.
ReDim Preserve strInstalled _
(UBound(strInstalled) + 100)
End If
Else
Exit Do
End If
Loop
' Trim off excess array elements.
ReDim Preserve strInstalled(iKeyCount)
x = RegCloseKey(hkroot)
End Function

To verify that the OLE object applications you need are installed, search for the name of the required application in the array returned by GetRegisteredList. The CheckInstalled procedure (listing 16.2) checks a list of required applications against the list of installed applications.

Listing 16.2 The CheckInstalled Procedure

‘ 16LIST02.TXT
Function CheckInstalled(RequiredList, strNotFound As String) _
As Variant
Dim InstalledList As Variant
Dim InstalledName, RequiredName
Dim bFound As Boolean
Dim AppName As String
InstalledList = GetRegisteredList()
For Each RequiredName In RequiredList
For Each InstalledName In InstalledList
If InStr(InstalledName, RequiredName) Then
bFound = True
Exit For
End If
bFound = False
Next InstalledName
' Build list of application that weren't found.
If bFound = False Then
strNotFound = strNotFound & ", " & RequiredName
End If
Next RequiredName
If Len(strNotFound) Then
strNotFound = Right(strNotFound, Len(strNotFound) - 2)
CheckInstalled = False
Else
CheckInstalled = True
strNotFound = ""
End If
End Function

The following Main procedure shows how to use the GetRegisteredList and CheckInstalled procedures together:

Sub Main()
Dim strNotFound As String
Dim bWorked As Boolean
bWorked = CheckInstalled(Array("Microsoft Excel", _
"Microsoft Word"), strNotFound)
If bWorked Then
' All required applications available -- continue.
Else
MsgBox _”The following required applications & _
were not found: " & strNotFound
End If
End Sub

Determining Required Files

Depending on the size and complexity of your application, it is quite possible that the Visual Basic support files you must distribute are several times the size of your actual .EXE on disk. Usually, these files are already found on the user’s system. However, you must always distribute these files along with your .EXE in case your user’s files are out of date or not already installed.

OLE container applications require the following files:

Required byFile NameDescription
Visual Basic VB40016.DLL
VB40032.DLL
Visual Basic run-time library.
VB4EN16.DLL
VB4EN32.DLL
Visual Basic English-language object library. This file name will be different for other national languages.
SCP.DLL
SCP32.DLL
Code page translation library.
OLE DDEML.DLL Dynamic data exchange manager.
COMPOBJ.DLL OLE support for component objects.
OLE2.DLL General OLE functions.
OLE2.REG Registration file for OLE.
OLE2CONV.DLL Supports converting OLE data types.
OLE2DISP.DLL Supports OLE Automation.
OLE2NLS.DLL Supports OLE national language support and localization features.
OLE2PROX.DLL Supports cross-process invocations.
STDOLE.TLB The OLE object library.
STORAGE.DLL Supports creating OLE compound documents.
TYPELIB.DLL Supports access and creation of object libraries.
Setup Toolkit SETUP.EXE Bootstrap setup program. Decompresses the Visual Basic run-time and support files, and launches the Setup1 or Setup32 program.
SETUP.LST Listing of files to install.
SETUP1.EXE Setup program that installs files.
SETUPKIT.DLL Support functions for Setup Wizard and Setup Toolkit.
VER.DLL Checks file versions during installation.
VSHARE.386 Permits file sharing under Windows.
Custom controls ??????16.OCX
??????32.OCX
As used by your application.
OC25.DLL Run-time DLL for OLE custom controls (.OCX).

Using Other Setup Tools

Because of the difficulties customizing the disk layout or installation procedure generated by the Setup Wizard, you may choose to use other installation tools, such as PKZIP—a popular shareware program from PKWARE, Inc. in Brown Deer, WI. If you are using these other setup tools, or creating your own, be sure to perform the following tasks before copying any of the Visual Basic run-time or OLE support files to users’ systems:

Comparing File Versions

The VER.DLL (16-bit) and VERSION.DLL (32-bit) support files included in the Setup Toolkit provide functions for comparing file version information. The file COMMON.BAS in the Setup Toolkit provides declarations for the functions in these two .DLLs and demonstrates how to use those functions to compare file versions. Table 16.1 lists the functions you use when comparing file versions.

Table 16.1 Version-Comparison Functions in VER.DLL and VERSION.DLL

ProcedureFound inUse to
GetFileVersionInfo VER.DLL (16-bit)
VERSION.DLL (32-bit)
COMMON.BAS (declared)
Retrieve version information from a file.
GetFileVersionInfoSize VER.DLL (16-bit)
VERSION.DLL (32-bit)
COMMON.BAS (declared)
Get the size of the version information to retrieve (required to allocate a string to receive the version information).
lmemcpy SETUP.DLL (16-bit)
STPKIT32.DLL (32-bit)
COMMON.BAS (declared)
Copy information retrieved by VerQueryValue into a Visual Basic variable.
VerQueryValue VER.DLL (16-bit)
VERSION.DLL (32-bit)
COMMON.BAS (declared)
Extract an item of information out of the version information retrieved by GetFileVersionInfo.
VerFindFile VER.DLL (16-bit)
VERSION.DLL (32-bit)
Locate a file on the user's system before installing.
VerInstallFile VER.DLL (16-bit)
VERSION.DLL (32-bit)
COMMON.BAS (declared)
Attempt to install a file based on provided file version information.

The VerFindFile and VerInstallFile are the two main functions you use to install files from distribution disks to a target system. Listing 16.3 show the declarations and constant values used for VerFindFile and VerInstallFile.

Listing 16.3 Declarations for VerFindFile and VerInstallFile

‘ 16LIST03.TXT
#Const Win32 = 1
#If Win16 Then
Declare Function VerInstallFile Lib "VER.DLL" _
(ByVal Flags As Integer, _
ByVal SrcName As String, _
ByVal DestName As String, _
ByVal SrcDir As String, _
ByVal DestDir As String, _
ByVal CurrDir As Any, _
ByVal TmpName As String, _
iTempLen As Integer) As Long
Declare Function VerFindFile Lib "VER.DLL" _
(ByVal iFlags As Integer, _
ByVal strFileName As String, _
ByVal strWinDirectory As String, _
ByVal strAppDir As String, _
ByVal strCurDir As String, _
iCurDirLen As Integer, _
ByVal strDestDir As String, _
iDestDirLen As Integer) _
As Integer
#ElseIf Win32 Then
Declare Function VerInstallFile Lib "VERSION.DLL" _
(ByVal Flags As Integer, _
ByVal SrcName As String, _
ByVal DestName As String, _
ByVal SrcDir As String, _
ByVal DestDir As String, _
ByVal CurrDir As Any, _
ByVal TmpName As String, _
iTempLen As Integer) As Long
Declare Function VerFindFile Lib "VERSION.DLL" _
(ByVal iFlags As Integer, _
ByVal strFileName As String, _
ByVal strWinDirectory As String, _
ByVal strAppDir As String, _
ByVal strCurDir As String, _
iCurDirLen As Integer, _
ByVal strDestDir As String, _
iDestDirLen As Integer) _
As Integer
#End If
' VerFind flag (only one).
Const VFFF_ISSHAREDFILE = 1
' VerFindFile error return codes.
Const VFF_CURNEDEST = 1
Const VFF_FILEINUSE = 2
Const VFF_BUFFTOOSMALL = 4
' VerInstallFile flags.
Const VIFF_FORCEINSTALL% = &h1
Const VIF_TEMPFILE& = &h1
' VerInstallFile error return codes.
Const VIF_SRCOLD& = &h4
Const VIF_DIFFLANG& = &h8
Const VIF_DIFFCODEPG& = &h10
Const VIF_DIFFTYPE& = &h20
Const VIF_WRITEPROT& = &h40
Const VIF_FILEINUSE& = &h80
Const VIF_OUTOFSPACE& = &h100
Const VIF_ACCESSVIOLATION& = &h200
Const VIF_SHARINGVIOLATION = &h400
Const VIF_CANNOTCREATE = &h800
Const VIF_CANNOTDELETE = &h1000
Const VIF_CANNOTRENAME = &h2000
Const VIF_OUTOFMEMORY = &h8000
Const VIF_CANNOTREADSRC = &h10000
Const VIF_CANNOTREADDST = &h20000
Const VIF_BUFFTOOSMALL = &h40000

The InstallFile procedure in listing 16.3 demonstrates how to use VerFindFile and VerInstallFile during setup. First, VerFindFile checks the user’s system for the file to install. If the file is not found, InstallFile copies the file to the destination directory using VerInstallFile. If the file is found, then VerInstallFile compares the file’s version numbers, preserving the more up-to-date file.

Listing 16.4 Using VerFindFile and VerInstallFile

‘ 16LIST04.TXT
Sub InstallFile(strSrcFile, strSrcDir, strDestFile, strDestDir)
Dim strWinDir As String, strCurDir As String, _
strAppDir As String, strTmpFile As String
Dim iWorked As Integer, iLen As Integer
Dim lWorked As Long
strSrcDir = "b:\"
strWinDir = GetWinDir
strAppDir = "c:\olestore"
strCurDir = CurDir$
strDestDir = Space(144)
iLen = Len(strDestDir)
iWorked = VerFindFile(VFFF_ISSHAREDFILE, strDestFile, _
strWinDir, strAppDir, strCurDir, Len(strCurDir), _
strDestDir, iLen)
Select Case iWorked
' File not found, so OK to install.
Case VFF_CURNEDEST
' Install file (0& indicates no pre-existing file)
lWorked = VerInstallFile(0, _
strSrcFile, _
strDestFile, _
strSrcDir, _
strDestDir, _
0&, _
strTmpFile, _
iLen)
' File is locked and can't be overwritten.
Case VFF_FILEINUSE
GoTo errInstallFile
' Destination directory string not big enough.
Case VFF_BUFFTOOSMALL
GoTo errInstallFile
' File was found, so compare versions.
Case Else
If iLen Then
strTmpFile = Space(144)
iLen = Len(strTmpFile)
lWorked = VerInstallFile(0, _
strSrcFile, _
strDestFile, _
strSrcDir, _
strDestDir, _
strDestDir, _
strTmpFile, _
iLen)
If lWorked And VIF_SRCOLD Then
'Source file was older, not copied
ElseIf lWorked And (VIF_DIFFLANG Or _
VIF_DIFFCODEPG Or VIF_DIFFTYPE) Then
' Retry and force installation.
' May want to prompt here in your code...
lWorked = VerInstallFile(VIFF_FORCEINSTALL, _
strSrcFile, _
strDestFile, _
strSrcDir, _
strDestDir, _
strDestDir, _
strTmpFile, _
iLen)
Else
GoTo errFileInstall
End If
End Select
Exit Sub
errInstallFile:
' Error handler for installation errors.
' These lines left in template form
‘ for the save of brevity here.
' VerFindFile errors.
If iWorked = VF_FILEINUSE Then
' Notify user to close application.
Else
' Internal problem (buffer too small).
Debug.Print “buffer too small”
End If
' VerInstallFile errors.
If lWorked And VIF_WRITEPROT Then
ElseIf lWorked And VIF_FILEINUSE Then
ElseIf lWorked And VIF_OUTOFSPACE Then
ElseIf lWorked And VIF_ACCESSVIOLATION Then
ElseIf lWorked And VIF_SHARINGVIOLATION Then
ElseIf lWorked And VIF_OUTOFMEMORY Then
Else
' For these cases, report the error
‘ and do not install the file
If lWorked And VIF_CANNOTCREATE Then
ElseIf lWorked And VIF_CANNOTDELETE Then
ElseIf lWorked And VIF_CANNOTRENAME Then
ElseIf lWorked And VIF_CANNOTREADSRC Then
ElseIf lWorked And VIF_CANNOTREADDST Then
ElseIf lWorked And VIF_BUFFTOOSMALL Then
End If
End If
End Sub

To use InstallFile to copy a file from your distribution disks to the user’s system, call the procedure with source and destination arguments, as follows:

InstallFile “olestore.ex_”, “b:\”, “olestore.exe”, “c:\olestore”

The VerInstallFile function automatically expands the file if it was compressed on the distribution disk.

The preceding procedure uses the GetWinDir utility function (listing 16.5). GetWinDir is a general-purpose function that simply returns the directory where Windows is installed.

Listing 16.5 The GetWinDir Utility Function

‘ 16LIST05.TXT
#Const Win32 = 1
#If Win16 Then
Declare Function GetWindowsDirectory Lib "Kernel" _
(ByVal lpBuffer As String, _
ByVal nSize As Integer) _
As Integer
#ElseIf Win32 Then
Declare Function GetWindowsDirectory Lib "Kernel32" _
(ByVal lpBuffer As String, _
ByVal nSize As Integer) _
As Integer
#End If
' Returns the Windows directory.
Function GetWinDir() As String
Dim strWinDirectory As String
Dim iWorked As Integer
' Allocate space for the returned path string.
strWinDirectory = Space(144)
' Get the Windows directory.
iWorked = GetWindowsDirectory(strWinDirectory, _
Len(strWinDirectory))
' Trim off the excess space.
GetWinDir = Left(strWinDirectory, iWorked)
End Function

Registering Files

The SETUPKIT.DLL (16-bit) and STPKIT32.DLL (32-bit) support files included in the Setup Toolkit provide functions for registering files with the system registration database. Files may register themselves or provide a .REG file which should be merged with the system registration database.

Table 16.2 Registration Functions in SETUP.DLL and STPKIT32.DLL

ProcedureFound inUse to
FSyncShell COMMON.BAS Start an application and wait for it to finish running.
DLLSelfRegister SETUP.DLL (16-bit)
STPKIT32.DLL (32-bit)
COMMON.BAS (declared)
Merge registration information stored in a DLL into the system registration database.
ExeSelfRegister SETUP.DLL (16-bit)
STPKIT32.DLL (32-bit)
COMMON.BAS (declared)
Merge registration information stored in an .EXE into the system registration database.
RegEdit SETUP1.BAS Merge registration information stored in an .REG file into the system registration database.

Creating Distribution Disks for 16- and 32-Bit Systems

When distributing applications on 16- and 32-bit platforms you have three choices:

The support files for each target system consume about 2M of disk space compressed. Dual-platform installation disks will use at least three disks for support files alone.

Creating Single-Platform Installation Disks

The Setup Wizard comes in 16- and 32-bit versions. Use the 16-bit version to create distribution disks for 16-bit target platforms; and use the 32-bit version to create disks for 32-bit platforms.

Creating Dual-Platform Installation Disks

The Setup Wizard does not directly support creating dual-platform installation disks. In order to create an installation system that automatically switches between 16- and 32-bit file lists, depending on the user’s operating system, you need to perform these tasks.

The problem with distributing 16- and 32-bit applications on the same disks is that the Setup Toolkit is written in Visual Basic and, therefore, requires the Visual Basic run-times and support .DLLs to be installed by SETUP.EXE before you can use Visual Basic code to determine which operating system is running.

You must install the 16-bit run-time and support files on 32-bit systems if you use the Setup Toolkit to create distribution disks that support both platforms. This cost—several megabytes of disk space—may be enough to convince you to use two sets of installation disks. On the other hand, most of your 32-bit target systems may already have the 16-bit Visual Basic run-time and support files installed, so this issue may be moot.

Testing the User’s Operating System During Setup

In the SETUP1.VBP project, make these modifications:

  1. In the file COMMON.BAS, change the constant gstrFILE_SETUP$ to a Public variable, as follows:

    ' Old declaration.
    ' Global Const gstrFILE_SETUP$ = "SETUP.LST
    ' New declaration.
    Public gstrFILE_SETUP$

  2. In the file SETUP1.FRM, add a call to the CheckOperatingSystem procedure in the form’s Load event procedure, as follows:

    Private Sub Form_Load()
    ' New line.
    CheckOperatingSystem
    ' Remaining lines omitted here...

  3. Add a module the project containing the CheckOperatingSystem procedure. CheckOperatingSystem and other support procedures are shown after this procedure.
  4. Build the project in the 16-bit version of Visual Basic.

The CheckOperatingSystem procedure sets the setup file list to use, based on which operating system the target system is running:

Option Explicit
Declare Function GetVersion Lib "Kernel" () As Long
' Lauches the correct 16- or 32-bit Setup .EXE,
‘ depending on the user’s operating system.
Sub CheckOperatingSystem()
Dim lWinInfo As Long, strWinVer As String
' Retrieve Windows version information.
lWinInfo = GetVersion()
' Parse the Windows version number from the returned
' Long integer value.
strWinVer = LoByte(LoWord(lWinInfo)) & "." & _
HiByte(LoWord(lWinInfo))
' Parse the DOS version number from the returned
' Long integer value (shown here for informational purposes
‘ -- not used).
' strDOSversion = HiByte(HiWord(lWinInfo)) & "." _
& LoByte(HiWord(lWinInfo))
'
' If the version is less than 3.5 (Win NT 3.5)...
If Val(strWinVer) < 3.5 Then
gstrFILE_SETUP$ = “setup.lst” ' Use the 16-bit list.
Else ' Otherwise,
gstrFILE_SETUP$ = “setup32.lst” ' use the 32-bit list.
End If
End Sub

The CheckOperatingSystem procedure uses four utility functions to parse version information from the long integer returned by the GetVersion API function. These utility functions are also useful for parsing flags—in fact, the Windows header file (WINDOWS.H) defines C macros with equivalent names.

Function LoWord(lArg As Long) As Integer
LoWord = lArg Mod (lArg And &hffff0000)
End Function
Function HiWord(lArg As Long) As Integer
HiWord = (lArg And &hffff0000) \ &h10000
End Function
Function HiByte(iArg As Integer) As Byte
HiByte = (iArg And &hff00) \ &h100
End Function
Function LoByte(iArg As Integer) As Byte
LoByte = iArg Mod (iArg And &hff00)
End Function

Building the 16- and 32-Bit Distribution Disks

To create the distribution disks for both 16- and 32-bit platforms, follow these steps:

  1. Run the 16-bit Setup Wizard for your 16-bit application, in step 5 of the Wizard, add the all of the files used by your 32-bit application (including the Visual Basic 32-bit run-time and support files).
  2. Create the distribution disks.
  3. Copy the generated SETUP.LST file back to your hard disk.
  4. Copy the SETUP.LST file again to the new file name SETUP32.LST.
  5. Edit both files, removing the 32-bit application files from SETUP.LST and removing the 16-bit application files from SETUP32.LST. Data files that are common to both installation procedures should appear on both files.
  6. Copy both .LST files back to Disk 1 of your distribution disks. You may need to move another file from Disk 1 to another disk in order to create enough space for both .LST files—be sure to edit the appropriate .LST file to accomodate this change (if necessary).

Programming OLE for 16-Bit and 32-Bit Platforms

Visual Basic can create applications that run under the Windows 3.1 (16-bit) operating system, Windows NT 3.5 (32-bit) operating system, or Windows 95 (32-bit) operating system. Visual Basic itself comes in two versions: 16-bit and 32-bit.

For the most part, the same Visual Basic code will compile and run in either version of Visual Basic. However, you must use the appropriate version of Visual Basic for the operating system you are using (16- or 32-bit). You can’t run Visual Basic 16-bit under Windows 95, or Visual Basic 32-bit under Windows 3.1. Table 16.3 shows the compatibility between Visual Basic and widely installed Windows operating systems.

Table 16.3 Visual Basic Windows Operating System Compatability

ItemRuns Under This Operating System

Windows 3.1 Windows NT 3.1/3.5 Windows NT 3.51 Windows 95
Visual Basic 16-bit development environment YNYY
Visual Basic 32-bit development environment NNYY
Visual Basic 16-bit applications YYYY
Visual Basic 32-bit applications NNYY

As table 16.3 shows, you can run 16-bit applications created with Visual Basic on some 32-bit platforms. However, you can’t run 32-bit applications on any 16-bit platform.

Sharing Code between 16- and 32-Bit .EXEs

To create a 16-bit application in Visual Basic, you must use the 16-bit version of the Visual Basic development environment. Similarly, you must use the 32-bit development environment to create 32-bit .EXEs. You can use the same project (.VPJ) and source files on both platforms, with the exceptions shown in table 16.4.

Table 16.4 Compatibility Problems and Solutions When Sharing Visual Basic Code between 16- and 32-Bit Platforms

ProblemSolution
Old-style custom controls (.VBX) are not supported in Visual Basic 32-bit. Resource files (.RES) are 16-bit and 32-bit specific. Use OLE custom controls (.OCX). Create duplicate 16- and 32-bit resource files and separate project files for 16- and 32-bit.
Windows API library names and functions names may be different between operating systems. Use the Alias keyword and/or conditional compilation when declaring Windows API functions.
The API function names are case-sensitive on 32-bit systems; they are case-insensitive on 16-bit systems. Use the Alias keyword when declaring Windows API functions.
Window handles (hWnd) are the Integer data type in 16-bit operating systems and the Long data type in 32-bit systems. Use conditional compilation statements for all API functions that take hWnd arguments or return hWnd values.
Compiled support file names (.OCX, .DLL, .EXE) are usually different between 16-bit and 32-bit systems. Support files usually embed "16" or "32" in their names to identify their target operating system. Create separate .VPJ files for 16- and 32-bit and use conditional compilation statements when declaring API functions in DLLs. Create separate 16- and 32-bit Setup disks when distributing applications.
You cannot use the Visual Basic StrConv function in 32-bit Visual Basic. Therefore, you can't access Unicode text strings in data files. Use only ANSI data files when doing file I/O in code.

Calling between 16- and 32-Bit Executables

When using OLE objects in Visual Basic, you may not know whether the application providing the object is a 16- or 32-bit executable. The OLE DLLs support calling between 16- and 32-bit executables any which-way. However, you need to be aware of conversions that may occur as a result.

Container (.EXE) Object (.EXE) Automatic OLE Conversion
16-bit 16-bit None. All strings are ANSI.
16-bit 32-bit Call: ANSI strings converted to Unicode. Return: Unicode strings converted to ANSI
32-bit 16-bit Call: Unicode strings converted to ANSI. Return: ANSI strings converted to Unicode.
32-bit 32-bit None. All strings are Unicode.

Calling between 16- and 32-Bit DLLs

When using OLE objects that are contained in DLLs, a Visual Basic application uses the DLL that matches the mode that the application was compiled in. 16-bit applications use only 16-bit OLE object DLLs; and 32-bit applications use only 32-bit OLE object DLLs.

All Windows DLLs (16- or 32-bit) use ANSI character strings. Visual Basic 32-bit uses Unicode strings internally, but uses ANSI characters when passing or receiving strings from API functions declared in code. If you are using the 32-bit version of Visual Basic, Visual Basic automatically converts arguments to ANSI from Unicode and return values to Unicode from ANSI.

Container (.EXE) DLL Automatic Conversion
16-bit API 16-bit None. All strings are ANSI.
16-bit OLE 16-bit None. All strings are ANSI.
32-bit API 32-bit Call: Aguments converted from Unicode to ANSI. Return: Arguments converted from ANSI to Unicode.
32-bit OLE 32-bit None. All strings are Unicode.

From Here...

For more information on related topics, see Chapter 23, “Building and Distributing OLE Objects,” explains how to install OLE server applications.


© 1996, QUE Corporation, an imprint of Macmillan Publishing USA, a Simon and Schuster Company.