Visual Basic Q&A

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries for the ‘exception’ Category

INFO: Translating Automation Errors for VB/VBA (Long)

Symptoms
This article describes several methods you can use to obtain the messagetext for an error code. This article also contains a list of error codesand descriptions as found in Winerror.h.
NOTE: When errors are raised when working with the Automation in VisualBasic or with VBA (Visual Basic for Applications), the error does notalways include the message text for the error.
Resolution
Refer to Winerror.hWhen automating another application with Visual Basic or VBA, you mayreceive an error similar to the following:

Run-time error ‘-2147418094 (80010012)’:
Automation Error.The value -2147418094 corresponds to the decimal representation of theerror code; 80010012 corresponds to the hexadecimal representation of thesame code. This code is documented in the Microsoft Visual C++ header fileWinerror.h. To locate the error code, search for the hexadecimalrepresentation of the error code (that is, 80010012). The following is anexcerpt from Winerror.h, which describes this error:

//// MessageId: RPC_E_SERVER_DIED_DNE//// MessageText:////The callee (server [not server application]) is not available//and disappeared; all connections are invalid.The call did not//execute.//#define RPC_E_SERVER_DIED_DNE_HRESULT_TYPEDEF_(0×80010012L) Winerror.h is included with Microsoft Visual C++ and is also provided withthe Microsoft Developer Network (MSDN) Library.
NOTE: Automation errors that are specific to a server application are notlisted in Winerror.h. If you do not find the error code in Winerror.h,check the documentation for the server application. Usually, withapplication-specific errors, the last 4 digits of the hexadecimalrepresentation of the error code refer to the application specific error.
Use FormatMessageYou can use the FormatMessage API function to determine the message textassociated with an automation error code. The sample function belowillustrates how you can use FormatMessage to obtain the message text:

Option ExplicitConst FORMAT_MESSAGE_FROM_SYSTEM = &H1000Private Declare Function FormatMessage Lib “kernel32″ Alias _”FormatMessageA” ( ByVal dwFlags As Long, lpSource As Long, _ByVal dwMessageId As Long, ByVal dwLanguageId As Long, _ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Any) _As LongPrivate Function MessageText(lCode As Long) As StringDim sRtrnCode As StringDim lRet As LongsRtrnCode = Space$(256)lRet = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0&, lCode, 0&, _sRtrnCode, 256&, 0&)If lRet >0 ThenMessageText = Left(sRtrnCode, lRet)ElseMessageText = “Error not found.”End IfEnd Function The next example illustrates how you can use this function with yourautomation code. In this example, Microsoft Excel is the serverapplication. Referencing a workbook object once it is destroyed (or closed)generates the error. To illustrate how to use the MessageText function,this example purposely generates an automation error by referencing aworkbook object after the workbook has been closed:

Dim xl As ObjectDim book As ObjectDim sMsg As StringSet xl = CreateObject(“excel.application”)Set book = xl.workbooks.Addbook.Close FalseOn Error Resume NextDebug.Print book.Name’<-Generates an automation error because the’workbook referenced by the book object has’been closed.If Err.Number <>0 ThensMsg = MessageText(Err.Number)MsgBox “Automation Error ” & vbCr & Err.Number & _” (” & Hex(Err.Number) & “)” & vbCr & sMsgEnd IfOn Error GoTo 0Set xl = Nothing Referencing the book object after the workbook is destroyed generates therun-time error -2147418094 (80010012). This is the message text returned byFormatMessage for this particular error:

The callee (server [not server application]) is not available anddisappeared; all connections are invalid. The call did not execute.NOTE: The FormatMessage function does not return errors that are specificto an application.
Use “Error Lookup”Microsoft Visual C++ version 5.0 includes a utility called “Error Lookup”that provides the message text for error codes.
To use this utility, start Microsoft Visual C++ and click Error Lookup onthe Tools menu. Type the error code and click Lookup. As an example, if youhad received the previously described error, -2147418094 (80010012), youwould type the following text in “Error Lookup” and then click Lookup:
0×80010012
Error List from WINERROR.HThe following table describes the error codes contained in Winerror.hincluded with Microsoft Visual C++ version 5.0:

AutomationAutomationErrorErrorin Decimalin HexError Description-2147418113 (8000FFFF)Catastrophic failure.-2147942413 (8007000D)The Data is invalid.-2147467263 (80004001)Not implemented.-2147024882 (8007000E)Ran out of memory.-2147024809 (80070057)One or more arguments are invalid.-2147467262 (80004002)No such interface supported.-2147467261 (80004003)Invalid pointer.-2147024890 (80070006)Invalid handle.-2147467260 (80004004)Operation aborted.-2147467259 (80004005)Unspecified error.-2147024891 (80070005)General access denied error.-2147483647 (80000001)Not implemented.-2147483646 (80000002)Ran out of memory.-2147483645 (80000003)One or more arguments are invalid.-2147483644 (80000004)No such interface supported.-2147483643 (80000005)Invalid pointer.-2147483642 (80000006)Invalid handle.-2147483641 (80000007)Operation aborted.-2147483640 (80000008)Unspecified error.-2147483639 (80000009)General access denied error.-2147483638 (8000000A)The data necessary to complete this operationnot yet available.-2147467258 (80004006)Thread local storage failure.-2147467257 (80004007)Get shared memory allocator failure.-2147467256 (80004008)Get memory allocator failure.-2147467255 (84009)Unable to initialize class cache.-2147467254 (8400A)Unable to initialize RPC services.-2147467253 (8000400B)Cannot set thread local storage channel control.-2147467252 (8000400C)Could not allocate thread local storage channelcontrol.-2147467251 (8000400D)The user supplied memory allocator isunacceptable.-2147467250 (8000400E)The OLE service mutex already exists.-2147467249 (8000400F)The OLE service file mapping already exists.-2147467248 (80004010)Unable to map view of file for OLE service.-2147467247 (80004011)Failure attempting to launch OLE service.-2147467246 (80004012)There was an attempt to call CoInitialize asecond time while single threaded.-2147467245 (80004013)A Remote activation was necessary but was notallowed.-2147467244 (80004014)A Remote activation was necessary but the servername provided was invalid.-2147467243 (80004015)The class is configured to run as a security iddifferent from the caller.-2147467242 (80004016)Use of Ole1 services requiring DDE windows isdisabled.-2147467241 (80004017)A RunAs specification must be A RunAsspecification must be<domain name>\<user name> or simply<user name>.-2147467240 (80004018)The server process could not be started. Thepathname may be incorrect.-2147467239 (80004019)The server process could not be started as theconfigured identity. The pathname may beincorrect or unavailable.-2147467238 (8000401A)The server process could not be started becausethe configured identity is incorrect. Check theusername and password. -2147467237 (8000401B)The client is not allowed to launch this server. -2147467236 (8000401C)The service providing this server could not bestarted. -2147467235 (8000401D)This computer was unable to communicate with thecomputer providing the server. -2147467234 (8000401E)The server did not respond after being launched. -2147467233 (8000401F)The registration information for this server isinconsistent or incomplete. -2147467232 (80004020)The registration information for this interfaceis inconsistent or incomplete. -2147467231 (80004021)The operation attempted is not supported. -2147221504 (80040000)Invalid OLEVERB structure.-2147221503 (80040001)Invalid advise flags.-2147221502 (80040002)Can’t enumerate any more, because the associateddata is missing.-2147221501 (80040003)This implementation doesn’t take advises.-2147221500 (80040004)There is no connection for this connection ID.-2147221499 (80040005)Need to run the object to perform this operation.-2147221498 (80040006)There is no cache to operate on.-2147221497 (80040007)Uninitialized object.-2147221496 (80040008)Linked object’s source class has changed.-2147221495 (80040009)Not able to get the moniker of the object.-2147221494 (8004000A)Not able to bind to the source.-2147221493 (8004000B)Object is static; operation not allowed.-2147221492 (8004000C)User cancelled out of save dialog.-2147221491 (8004000D)Invalid rectangle.-2147221490 (8004000E)compobj.dll is too old for the ole2.dllinitialized.-2147221489 (8004000F)Invalid window handle.-2147221488 (80040010)Object is not in any of the inplace active states.-2147221487 (80040011)Not able to convert object.-2147221486 (80040012)Not able to perform the operation because objectis not given storage yet.-2147221404 (80040064)Invalid FORMATETC structure.-2147221403 (80040065)Invalid DVTARGETDEVICE structure.-2147221402 (80040066)Invalid STDGMEDIUM structure.-2147221401 (80040067)Invalid STATDATA structure.-2147221400 (80040068)Invalid lindex.-2147221399 (80040069)Invalid tymed.-2147221398 (8004006A)Invalid clipboard format.-2147221397 (8004006B)Invalid aspect(s).-2147221396 (8004006C)tdSize parameter of the DVTARGETDEVICE structureis invalid.-2147221395 (8004006D)Object doesn’t support IViewObject interface.-2147221248 (80040100)Trying to revoke a drop target that has not beenregistered.-2147221247 (80040101)This window has already been registered as a droptarget.-2147221246 (80040102)Invalid window handle.-2147221232 (80040110)Class does not support aggregation (or classobject is remote).-2147221231 (80040111)ClassFactory cannot supply requested class.-2147221184 (80040140)Error drawing view.-2147221168 (80040150)Could not read key from registry.-2147221167 (80040151)Could not write key to registry.-2147221166 (80040152)Could not find the key in the registry.-2147221165 (80040153)Invalid value for registry.-2147221164 (80040154)Class not registered.-2147221163 (80040155)Interface not registered.-2147221136 (80040170)Cache not updated.-2147221120 (80040180)No verbs for OLE object.-2147221119 (80040181)Invalid verb for OLE object.-2147221088 (800401A0)Undo is not available.-2147221087 (800401A1)Space for tools is not available.-2147221056 (800401C0)OLESTREAM Get method failed.-2147221055 (800401C1)OLESTREAM Put method failed.-2147221054 (800401C2)Contents of the OLESTREAM not in correct format.-2147221053 (800401C3)There was an error in a Windows GDI call whileconverting the bitmap to a DIB.-2147221052 (800401C4)Contents of the IStorage not in correct format.-2147221051 (800401C5)Contents of IStorage is missing one of thestandard streams.-2147221050 (800401C6)There was an error in a Windows GDI call whileconverting the DIB to a bitmap. -2147221040 (800401D0)OpenClipboard Failed.-2147221039 (800401D1)EmptyClipboard Failed.-2147221038 (800401D2)SetClipboard Failed.-2147221037 (800401D3)Data on clipboard is invalid.-2147221036 (800401D4)CloseClipboard Failed.-2147221024 (800401E0)Moniker needs to be connected manually.-2147221023 (800401E1)Operation exceeded deadline.-2147221022 (800401E2)Moniker needs to be generic.-2147221021 (800401E3)Operation unavailable.-2147221020 (800401E4)Invalid syntax.-2147221019 (800401E5)No object for moniker.-2147221018 (800401E6)Bad extension for file.-2147221017 (800401E7)Intermediate operation failed.-2147221016 (800401E8)Moniker is not bindable.-2147221015 (800401E9)Moniker is not bound.-2147221014 (800401EA)Moniker cannot open file.-2147221013 (800401EB)User input required for operation to succeed.-2147221012 (800401EC)Moniker class has no inverse.-2147221011 (800401ED)Moniker does not refer to storage.-2147221010 (800401EE)No common prefix.-2147221009 (800401EF)Moniker could not be enumerated.-2147221008 (800401F0)CoInitialize has not been called. -2147221007 (800401F1)CoInitialize has already been called. -2147221006 (800401F2)Class of object cannot be determined.-2147221005 (800401F3)Invalid class string.-2147221004 (800401F4)Invalid interface string.-2147221003 (800401F5)Application not found.-2147221002 (800401F6)Application cannot be run more than once.-2147221001 (800401F7)Some error in application program.-2147221000 (800401F8)DLL for class not found.-2147220999 (800401F9)Error in the DLL.-2147220998 (800401FA)Wrong OS or OS version for application.-2147220997 (800401FB)Object is not registered.-2147220996 (800401FC)Object is already registered.-2147220995 (800401FD)Object is not connected to server.-2147220994 (800401FE)Application was launched but it didn’t register aclass factory.-2147220993 (800401FF)Object has been released.-2146959359 (80080001)Attempt to create a class object failed.-2146959358 (80080002)OLE service could not bind object.-2146959357 (80080003)RPC communication failed with OLE service.-2146959356 (80080004)Bad path to object.-2146959355 (80080005)Server execution failed.-2146959354 (80080006)OLE service could not communicate with the objectserver.-2146959353 (80080007)Moniker path could not be normalized.-2146959352 (80080008)Object server is stopping when OLE servicecontacts it.-2146959351 (80080009)An invalid root block pointer was specified.-2146959344 (80080010)An allocation chain contained an invalid linkpointer.-2146959343 (80080011)The requested allocation size was too large.-2147352575 (80020001)Unknown interface. -2147352573 (80020003)Member not found. -2147352572 (80020004)Parameter not found. -2147352571 (80020005)Type mismatch. -2147352570 (80020006)Unknown name.-2147352569 (80020007)No named arguments. -2147352568 (80020008)Bad variable type. -2147352567 (80020009)Exception occurred. -2147352566 (8002000A)Out of present range. -2147352565 (8002000B)Invalid index. -2147352564 (8002000C)Unknown language. -2147352563 (8002000D)Memory is locked. -2147352562 (8002000E)Invalid number of parameters. -2147352561 (8002000F)Parameter not optional. -2147352560 (80020010)Invalid callee. -2147352559 (80020011)Does not support a collection. -2147319786 (80028016)Buffer too small. -2147319784 (80028018)Old format or invalid type library. -2147319783 (80028019)Old format or invalid type library. -2147319780 (8002801C)Error accessing the OLE registry. -2147319779 (8002801D)Library not registered. -2147319769 (80028027)Bound to unknown type. -2147319768 (80028028)Qualified name disallowed. -2147319767 (80028029)Invalid forward reference, or reference touncompiled type. -2147319766 (8002802A)Type mismatch. -2147319765 (8002802B)Element not found. -2147319764 (8002802C)Ambiguous name. -2147319763 (8002802D)Name already exists in the library. -2147319762 (8002802E)Unknown LCID. -2147319761 (8002802F)Function not defined in specified DLL. -2147317571 (800288BD)Wrong module kind for the operation. -2147317563 (800288C5)Size may not exceed 64K. -2147317562 (800288C6)Duplicate ID in inheritance hierarchy. -2147317553 (800288CF)Incorrect inheritance depth in standard OLEhmember. -2147316576 (80028CA0)Type mismatch. -2147316575 (80028CA1)Invalid number of arguments. -2147316574 (80028CA2)I/O Error. -2147316573 (80028CA3)Error creating unique tmp file. -2147312566 (80029C4A)Error loading type library/DLL. -2147312509 (80029C83)Inconsistent property functions. -2147312508 (80029C84)Circular dependency between types/modules. -2147287039 (80030001)Unable to perform requested operation. -2147287038 (80030002)%1 could not be found. -2147287037 (80030003)The path %1 could not be found. -2147287036 (80030004)There are insufficient resources to open anotherfile. -2147287035 (80030005)Access Denied. -2147287034 (80030006)Attempted an operation on an invalid object. -2147287032 (80030008)There is insufficient memory available tocomplete operation. -2147287031 (80030009)Invalid pointer error. -2147287022 (80030012)There are no more entries to return. -2147287021 (80030013)Disk is write-protected. -2147287015 (80030019)An error occurred during a seek operation. -2147287011 (8003001D)A disk error occurred during a write operation. -2147287010 (8003001E)A disk error occurred during a read operation. -2147287008 (80030020)A share violation has occurred. -2147287007 (80030021)A lock violation has occurred. -2147286960 (80030050)%1 already exists. -2147286953 (80030057)Invalid parameter error. -2147286928 (80030070)There is insufficient disk space to completeoperation. -2147286800 (800300F0)Illegal write of non-simple property to simpleproperty set. -2147286790 (800300FA)An API call exited abnormally. -2147286789 (800300FB)The file %1 is not a valid compound file. -2147286788 (800300FC)The name %1 is not valid. -2147286787 (800300FD)An unexpected error occurred. -2147286786 (800300FE)That function is not implemented. -2147286785 (800300FF)Invalid flag error. -2147286784 (80030100)Attempted to use an object that is busy. -2147286783 (80030101)The storage has been changed since the lastcommit. -2147286782 (80030102)Attempted to use an object that has ceased toexist. -2147286781 (80030103)Can’t save. -2147286780 (80030104)The compound file %1 was produced with anincompatible version of storage. -2147286779 (80030105)The compound file %1 was produced with a newerversion of storage. -2147286778 (80030106)Share.exe or equivalent is required foroperation. -2147286777 (80030107)Illegal operation called on non-file basedstorage. -2147286776 (80030108)Illegal operation called on object with extantmarshallings. -2147286775 (80030109)The docfile has been corrupted. -2147286768 (80030110)OLE32.DLL has been loaded at the wrong address. -2147286527 (80030201)The file download was aborted abnormally. Thefile is incomplete. -2147286526 (80030202)The file download has been terminated. -2147418111 (80010001)Call was rejected by callee. -2147418110 (80010002)Call was canceled by the message filter. -2147418109 (80010003)The caller is dispatching an intertaskSendMessage call and cannot call out viaPostMessage. -2147418108 (80010004)The caller is dispatching an asynchronous calland cannot make an outgoing call on behalf ofthis call. -2147418107 (80010005)It is illegal to call out while inside messagefilter. -2147418106 (80010006)The connection terminated or is in a bogus stateand cannot be used any more. Other connectionsare still valid. -2147418105 (80010007)The callee (server [not server application]) isnot available and disappeared; all connectionsare invalid. The call may have executed. -2147418104 (80010008)The caller (client) disappeared while the callee(server) was processing a call. -2147418103 (80010009)The data packet with the marshalled parameterdata is incorrect. -2147418102 (8001000A)The call was not transmitted properly; themessage queue was full and was not emptied afteryielding. -2147418101 (8001000B)The client (caller) cannot marshal the parameterdata – low memory, etc. -2147418100 (8001000C)The client (caller) cannot unmarshal the returndata – low memory, etc. -2147418099 (8001000D)The server (callee) cannot marshal the returndata – low memory, etc. -2147418098 (8001000E)The server (callee) cannot unmarshal theparameter data – low memory, etc. -2147418097 (8001000F)Received data is invalid; could be server orclient data. -2147418096 (80010010)A particular parameter is invalid and cannot be(un)marshalled. -2147418095 (80010011)There is no second outgoing call on same channelin DDE conversation. -2147418094 (80010012)The callee (server [not server application]) isnot available and disappeared; all connectionsare invalid. The call did not execute. -2147417856 (80010100)System call failed. -2147417855 (80010101)Could not allocate some required resource(memory, events, …) -2147417854 (80010102)Attempted to make calls on more than one threadin single threaded mode. -2147417853 (80010103)The requested interface is not registered on theserver object. -2147417852 (80010104)RPC could not call the server or could not returnthe results of calling the server. -2147417851 (80010105)The server threw an exception. -2147417850 (80010106)Cannot change thread mode after it is set. -2147417849 (80010107)The method called does not exist on the server. -2147417848 (80010108)The object invoked has disconnected from itsclients. -2147417847 (80010109)The object invoked chose not to process the callnow. Try again later. -2147417846 (8001010A)The message filter indicated that the applicationis busy. -2147417845 (8001010B)The message filter rejected the call. -2147417844 (8001010C)A call control interfaces was called with invaliddata. -2147417843 (8001010D)An outgoing call cannot be made since theapplication is dispatching an input-synchronouscall. -2147417842 (8001010E)The application called an interface that wasmarshalled for a different thread. -2147417841 (8001010F)CoInitialize has not been called on the currentthread. -2147417840 (80010110)The version of OLE on the client and servermachines does not match. -2147417839 (80010111)OLE received a packet with an invalid header. -2147417838 (80010112)OLE received a packet with an invalid extension. -2147417837 (80010113)The requested object or interface does not exist. -2147417836 (80010114)The requested object does not exist. -2147417835 (80010115)OLE has sent a request and is waiting for areply. -2147417834 (80010116)OLE is waiting before retrying a request. -2147417833 (80010117)Call context cannot be accessed after callcompleted. -2147417832 (80010118)Impersonate on unsecured calls is not supported. -2147417831 (80010119)Security must be initialized before anyinterfaces are marshalled or unmarshalled. Itcannot be changed once initialized. -2147417830 (8001011A)No security packages are installed on thismachine or the user is not logged on or there areno compatible security packages between theclient and server. -2147417829 (8001011B)Access is denied. -2147417828 (8001011C)Remote calls are not allowed for this process. -2147417827 (8001011D)The marshalled interface data packet (OBJREF) hasan invalid or unknown format. -2147352577 (8001FFFF)An internal error occurred. -2146893823 (80090001)Bad UID. -2146893822 (80090002)Bad Hash. -2146893821 (80090003)Bad Key. -2146893820 (80090004)Bad Length. -2146893819 (80090005)Bad Data. -2146893818 (80090006)Invalid Signature. -2146893817 (80090007)Bad Version of provider. -2146893816 (80090008)Invalid algorithm specified. -2146893815 (80090009)Invalid flags specified. -2146893814 (8009000A)Invalid type specified. -2146893813 (8009000B)Key not valid for use in specified state. -2146893812 (8009000C)Hash not valid for use in specified state. -2146893811 (8009000D)Key does not exist.-2146893810 (8009000E)Insufficient memory available for the operation. -2146893809 (8009000F)Object already exists. -2146893808 (80090010)Access denied. -2146893807 (80090011)Object was not found. -2146893806 (80090012)Data already encrypted. -2146893805 (80090013)Invalid provider specified. -2146893804 (80090014)Invalid provider type specified. -2146893803 (80090015)Provider’s public key is invalid. -2146893802 (80090016)Keyset does not exist. -2146893801 (80090017)Provider type not defined. -2146893800 (80090018)Provider type as registered is invalid. -2146893799 (80090019)The keyset is not defined. -2146893798 (8009001A)Keyset as registered is invalid. -2146893797 (8009001B)Provider type does not match registered value. -2146893796 (8009001C)The digital signature file is corrupt. -2146893795 (8009001D)Provider DLL failed to initialize correctly. -2146893794 (8009001E)Provider DLL could not be found. -2146893793 (8009001F)The Keyset parameter is invalid. -2146893792 (80090020)An internal error occurred. -2146893791 (80090021)A base error occurred. -2146762751 (800B0001)The specified trust provider is not known on thissystem. -2146762750 (800B0002)The trust verification action specified is notsupported by the specified trust provider. -2146762749 (800B0003)The form specified for the subject is not onesupported or known by the specified trustprovider. -2146762748 (800B0004)The subject is not trusted for the specifiedaction. -2146762747 (800B0005)Error due to problem in ASN.1 encoding process. -2146762746 (800B0006)Error due to problem in ASN.1 decoding process. -2146762745 (800B0007)Reading / writing Extensions where Attributes areappropriate, and visa versa. -2146762744 (800B0008)Unspecified cryptographic failure. -2146762743 (800B0009)The size of the data could not be determined. -2146762742 (800B000A)The size of the indefinite-sized data could notbe determined. -2146762741 (800B000B)This object does not read and write self-sizingdata.-2146762496 (800B0100)No signature was present in the subject. -2146762495 (800B0101)A required certificate is not within its validityperiod. -2146762494 (800B0102)The validity periods of the certification chaindo not nest correctly.-2146762493 (800B0103)A certificate that can only be used as anend-entity is being used as a CA or visa versa.-2146762492 (800B0104)A path length constraint in the certificationchain has been violated.-2146762491 (800B0105)An extension of unknown type that is labeled’critical’ is present in a certificate.-2146762490 (800B0106)A certificate is being used for a purpose otherthan that for which it is permitted.-2146762489 (800B0107)A parent of a given certificate in fact did notissue that child certificate.-2146762488 (800B0108)A certificate is missing or has an empty valuefor an important field, such as a subject orissuer name.-2146762487 (800B0109)A certification chain processed correctly, butterminated in a root certificate which isn’ttrusted by the trust provider.-2146762486 (800B010A)A chain of certs didn’t chain as they should in acertain application of chaining.

INFO: Subclassing Support in Visual Basic

Symptoms
Subclassing intercepts messages that the operating system sends to specific windows. Subclassing allows you to process messages that are not handled natively by a control or form.
Subclassing requires that you use the AddressOf operator, which provides callback functionality. For more information about how to use this operator, visit the following MSDN Web site:
AddressOf Operator
http://msdn.microsoft.com/en-us/library/aa242738.aspx(http://msdn.microsoft.com/en-us/library/aa242738.aspx)NOTE: The AddressOf operator provides callback functionality when it calls Windows APIs that require this feature. This functionality is also known as a function pointer. The AddressOf operator was not designed or tested for subclassing purposes. Subclassing can have disastrous results if you use it incorrectly.
Microsoft supports the demonstration of subclassing in Visual Basic. Some controls may experience problems if they are made into a subclass, because their intended behavior is modified beyond the original design. Therefore, subclassing in Visual Basic does not always work. Microsoft does not guarantee that subclassing in Visual Basic will produce the results that you want.
Resolution
The limitations and risks of function pointers in Visual Basic include the following:
Debugging: If your application fires a callback function while it is in break mode, the code is executed, but any breaks or steps are ignored. If the callback function generates an exception, you can catch it, and then return the current value. Resets are prohibited in break mode when a callback function is on the stack.
Thunks: Windows enables relocatable code by using thunking. If you delete a callback function in break mode, the thunk is modified to return a zero value. This value is typically correct, but not always. If you delete a callback function in break mode, and then you type the callback function again, it is possible that some call recipients will not know about the new address.
Thunks are not used in the compiled executable. The pointer is passed directly to the entry point.
Passing a function with the wrong signature: If you pass a callback function that takes a different number of arguments than the caller expects, or if you pass a callback function that mistakenly calls an argument by using ByRef or ByVal, your application may fail. You must pass a function with the correct signature.
Passing a function to a Windows procedure that no longer exists: When you make a window into a subclass, you pass a function pointer to Windows as the Windows procedure (WindowProc). However, when you run your application in the IDE, the WindowProc function may be called after the underlying function is destroyed. This may cause a general protection fault, and may cause the Visual Basic development environment to fail.
Visual Basic to Visual Basic function pointers are not supported: Pointers to Visual Basic functions cannot be passed in Visual Basic. Only pointers from Visual Basic to a DLL function are supported.
Containing errors in a callback procedure: Any errors in a callback procedure must not be propagated back to the external procedure that initially called. Therefore, put the On Error Resume Next statement at the beginning of the callback procedure.

INFO: Identifying the Jet Database Engine Components

Symptoms
DAO is a COM wrapper around the Jet Engine, which is used by MicrosoftAccess, Excel, Project, Visual Basic, and the Microsoft Foundation Classes(among others). It can be confusing which version of Jet you are usingbecause so many applications may distribute Jet onto your machine. Thetables and explanations in this article are intended to help you identifythe version and components of Jet that you are using for the givenapplication.
Resolution
This table displays which version of Jet is shipped with each of thefollowing products.

ApplicationMicrosoft JET version———————————————————————–Microsoft Access 1.01.0Microsoft Access 1.11.1Microsoft Access 2.02.0Microsoft Access 2.02.5 with Microsoft Access Service PackMicrosoft Access 7.03.0Microsoft Access 973.5 with Office 97Microsoft Access 97 SR13.5 with Office 97SR1Visual Basic 3.01.1Visual Basic 3.02.0 with Visual Basic CompatibilityLayerVisual Basic 3.02.5 with Microsoft Access Service PackVisual Basic 4.0 16-bit2.5Visual Basic 4.0 32-bit3.0Visual Basic 5.0 32-bit3.0Visual Basic 5.0 32-bit3.5Visual C++ 4.X3.0Visual C++ 5.03.5Jet 3.51 (web download)3.51 (Latest, 3.5 Binary compatible)
Compatibility Among VersionsWith each new version of Microsoft Jet, enhancements in functionality andchanges to the structure of the database file cause problems with backwardcompatibility. Wherever possible, efforts have been made to ensure an easymigration path among versions. However, incompatibilities do exist. Thefollowing table illustrates how you can use database files and objectsamong different versions of Microsoft Jet.

Jet Version——————————–1.01.12.02.53.03.5———————————————-MDB Version———–1.0YYYYYY1.1NYYYYY2.0NNYYYY3.0NNNNYY
A “Y” indicates that you can use the database without conversion; “N”indicates that you cannot use or convert the database. With DAO code, youcan open any version of any database up to the same version of MicrosoftJet. Microsoft Access is an exception to this rule because it can open onlythose databases with the same version as itself. However, it can link totables with the same or earlier version. In other words, if you upgrade toMicrosoft Jet 3.0, you will still be able to read version 2.x databases.
There is no version 2.5 or 3.5 of an .mdb file (just 2.0 and 3.0), whichare common to the x.0 and x.5 versions of Jet.
Jet 2.0 and Jet 2.5 use identical database formats in every aspect. Jet 2.0can read databases created with Jet 2.5.
Microsoft Jet 3.5 databases have the same structure as Jet 3.0. MicrosoftJet 3.0 can read data from Microsoft Jet 3.5 tables. The main limitationhere is that Microsoft Jet 3.5 may support additional properties on thedatabase object that aren’t recognized or taken advantage of by MicrosoftJet 3.0, but there aren’t any data incompatibilities.
Notice that Visual Basic 3.0 is capable of using three different versionsof Jet each requiring a separate set of dynamic link libraries (DLLs). Thiscan cause problems when your Visual Basic application expects to use Jet2.0 for example, and then you install another Visual Basic applicationusing an earlier version of Jet on the same system that replaces some ofthe version 2.0 DLLs with version 1.1. Typically the problem DLL in thissituation is Vbdb300.dll because it determines which version of the Jetengine will be used.
The following table should help you solve any version conflicts, and helpyou identify the version of Jet you are using. You may use the Wps.exeutility shipped with Visual Basic to find out which version of Jet youcurrently have loaded in memory. Wps.exe is located in the \VB\CDKdirectory of Visual Basic 3.0 Professional, and in \TOOLS\PSS directory ofthe Visual Basic 4.0 CD. Pay special attention to the version informationobtained from File Manager (File, Properties) in Visual Basic 3.0, andMicrosoft System Info. in Visual Basic 4.0 32-bit.
The following files are required by Visual Basic to use the Jet DatabaseEngine:

Jet VersionFileVersionDescription———————————————————————1.1VBDB300.DLL3.00.0528VB/JET supportMSAES110.DLL1.10.0000Expression servicesMSAJT110.DLL1.10.0001Jet 1.1 engineXBS110.DLL1.10.0002External xBASE ISAMBTRV110.DLL1.10.0000External Btrieve ISAMPDX110.DLL1.10.0000External Paradox ISAM2.0 (comlyr)VBDB300.DLL3.00.0529VB/JET supportMSAJT112.DLL1.99.1605Jet 2.x comp. loaderMSAJT200.DLL2.00.0000Jet 2.0 engineXBS200.DLL2.00.0000External xBASE ISAMBTRV200.DLL2.00.0000External Btrieve ISAMPDX200.DLL2.00.0000External Paradox ISAM2.5 (accsvc)VBDB300.DLL3.00.0529VB/JET supportMSAJT112.DLL1.99.1605Jet 2.x comp loaderMSAJT200.DLL2.50.1606Jet 2.5 engineMSJETERR.DLL2.50.1108Error servicesMSJETINT.DLL2.50.1108InternationalXBS200.DLL2.50.1108External xBASE ISAMBTRV200.DLL2.50.1108External Btrieve ISAMPDX200.DLL2.50.1108External Paradox ISAM2.5 (VB4 16)VBDB16.DLL4.00.2422VB/JET supportMSAJT200.DLL2.50.1606Jet 2.5 engineMSJETERR.DLL2.50.1111Error servicesMSJETINT.DLL2.50.1111InternationalXBS200.DLL2.50.1117External xBASE ISAMBTRV200.DLL2.50.1117External Btrieve ISAMPDX200.DLL2.50.1117External Paradox ISAMMSXL2016.DLL2.50.1117External Excel ISAMMSTX2016.DLL2.50.1117External Text ISAM3.0MSJT3032.DLL3.0.0.2118Jet 3.0 engineMSJINT32.DLL3.0.0.2118InternationalMSJTER32.DLL3.0.0.2118Error servicesMSXL3032.DLL3.0.0.2001External Excel ISAMMSRD2X32.DLL3.0.0.2118External Jet 2.0 ISAMMSLT3032.DLL3.0.0.2008External Lotus ISAMMSPX3032.DLL3.0.0.2001External Paradox ISAMMSXB3032.DLL3.0.0.2008External xBASE ISAMMSTX3032.DLL3.0.0.2008External Text ISAM
With Jet 3.5x, there have been multiple releases. The following tableindicates which version of Jet applies to a given product:

Access 97Access 97aFileNameOffice 97VB5Office 97aJet 3.51——————————————————–MSEXCL35.DLL3.50.3428.03.50.3602.53.50.3907.0n/aMSJET35.DLL3.50.3428.03.50.3602.43.50.3907.53.51.0623.4MSJINT35.DLL3.50.3428.03.50.3602.53.50.3907.0n/aMSJTER35.DLL3.50.3428.03.50.3602.03.50.3907.0n/aMSLTUS35.DLLn/a3.50.3602.5n/an/aMSPDOX35.DLLn/a3.50.3602.0n/an/aMSRD2X35.DLL3.50.3428.03.50.3602.03.50.3907.0n/aMSREPL35.DLL3.50.3428.03.50.3602.03.50.3907.13.51.0623.0MSTEXT35.DLL3.50.3428.03.50.3602.03.50.3907.0n/aMSXBSE35.DLL3.50.3428.03.50.3602.03.50.3907.0n/aVBAJET32.DLL3.0.0.69085.0.0.71223.0.0.6908n/aVBAR332.DLL3.0.0.69083.0.0.69083.0.0.6908n/a

INFO: How to Use DDE in Visual Basic to Communicate with Other Windows Programs

Symptoms
This article describes how to use Dynamic Data Exchange (DDE) from a Visual Basic program. Although Visual Basic offers more powerful, robust and reliable intercommunication between programs by using OLE, it still supports the older DDE technology. You can use DDE to link to and share data between programs.
Using OLE to communicate with other programs is better than using DDE with Visual Basic. OLE offers you better performance than DDE does. If a program supports OLE automation, it exposes an “Object Model” you can use to manipulate the program (through code) to complete actions for you. DDE is more useful in communicating with older programs that might not support OLE but do support DDE, and many 16-bit programs fall into this category.
Microsoft recommends that you use OLE rather than DDEto communicate with another program when you are developing your Visual Basic program. However, because there are times when you may need or want to use DDE, this article describes how to use DDE from a Visual Basic program.
Resolution
Visual Basic can exchange data, such as information, commands or keystrokes, with any program that supports DDE. A DDE link requires the following three things:Program nameTopicItemThe program name is the executable (.exe) file name of the source program minus the .exe file extension. The topic describes the type of data that is being exchanged. The topic is specific to the DDE source program. However, “System” is the one universal topic that you can use to query what topics are available in a particular program. The item parameter is the actual data that is being transferred. In Visual Basic, a topic could be a form with a textbox as an item. In Microsoft Excel, a topic could be a spreadsheet with a cell as an item. The program name and topic cannot be modified once the DDE link has been established because any modifications break the connection. The item parameter can be modified to any valid item during the DDE conversation without breaking the DDE link.
Specific to Visual Basic, the LinkTopic property supplies a combination of the program name and topic parameters. The LinkTopic property is available for Label, PictureBox, or TextBox controls which can share data through a DDE connection. The program name and topic parameters are combined by using the pipe character (|) as the separator. For example, to create a DDE link with Microsoft Word as the source program and by using the System topic. the LinkTopic property of a textbox would be:
Text1.LinkTopic=”WinWord|System”When Visual Basic is the source program for the DDE link, the LinkTopic of the form which contains the control to be shared is set to a known name. This known name is used in the LinkTopic of the Visual Basic destination program as the topic information. For example, to access data from a form with a LinkTopic that is set to “DDELink”, a Visual Basic destination program would have a matching control with a LinkTopic set to “program name|DDELink”.
The LinkItem property corresponds to the item parameter in a DDE connection, and this property is set to a corresponding item in the source program, for example, the “Total” cell in an Excel spreadsheet. The LinkItem property is set for the control that is used as in a destination program. When a Visual Basic form is the source in a DDE connection, the name of the control on the form can be the item argument in the program|topic|item string that is used by the destination program. When Visual Basic is used as both the source and destination program, the LinkItem property of the destination program would be set to the name of the control in the Visual Basic source program. For example, with Visual Basic used as both the source and destination program and a text box that is named txtSource as the item in the source program, a corresponding txtData text box in the destination program would have its LinkItem property set to txtSource:
txtData.LinkItem = “txtSource”Before a connection can be established, the mechanism to update the information needs to be set. In a DDE connection, there are three types of links:AutomaticManualNotifyAn automatic link updates the destination information whenever the source is modified. A manual link requires that the data be requested by the destination program, and notify informs the destination program that the source data has been changed but doesn’t actually update the information in the destination program. The one exception to an automatic update is the Picturebox control. Visual Basic does not automatically notify a DDE destination program when the Picture property setting of a PictureBox on a source Form changes. Because the amount of data in a graphic can be very large and because it seldom makes sense to update a destination program as each pixel in the picture changes, Visual Basic requires that you use the LinkSend method to explicitly notify DDE destination programs when the contents of a PictureBox change.
Once a DDE link has been established, there are several methods and events in Visual Basic that can be used to control how data is sent between the source and the destination program.
MethodsLinkRequest: Asks the source program to update the contents of a destination item.
LinkExecute: Sends a command string to the source program.
LinkPoke: Transfers the contents of the item control to the source program. Typically, information in a DDE conversation flows from the source to the destination. However, LinkPoke provides a destination object with the ability to supply data to the source.
LinkSend: Transfers the contents of a PictureBox control to the destination program in a DDE conversation.
EventsLinkOpen: Occurs when a DDE link is being initiated.
LinkClose: Occurs when a DDE link terminates. Either program in a DDE conversation may terminate a link at any time.
LinkError: Occurs when there is an error during a DDE conversation. This event is recognized only as the result of a DDE-related error that occurs when no Visual Basic code is being executed. The error number is passed as an argument.
LinkExecute: Occurs when a command string is sent by a destination program in a DDE conversation. The destination program expects the source program to perform the operation described by the string.
LinkNotify: Occurs when the source has changed the data that is defined by the DDE link if the LinkMode property of the destination control is set to Notify.

INFO: How Setup Wizard and PDW Use Dependency Files

Symptoms
A dependency (.DEP) file contains information about the run-timerequirements of an application or component; it contains informationregarding which files are needed, how the files are to be registered, andwhere they should be installed on the target computer. You can createdependency files for standard Visual Basic projects, ActiveX controls,ActiveX documents, and other ActiveX components.
When a component is used in another project, the dependency information forthe component is incorporated into the project’s dependency information.This dependency information is used by the Setup Wizard (known as thePackage and Deployment Wizard or PDW in Visual Basic 6.0). When you use theSetup Wizard or PDW to generate a setup for your project, the wizard refersto the project’s dependency information to determine which files should bedistributed with your project and how those files should be installed.
All of the ActiveX controls that ship with Visual Basic have a companiondependency file. It is strongly recommended that you generate a dependencyfile for your component, especially if you intend that the component beused in other Visual Basic projects. The Setup Wizard and PDW give you theoption to generate a dependency file for your project or component. Thedependency file may also be generated using a text editor if you cannot usethe Setup Wizard or PDW to create one. The remainder of this articledescribes the syntax for a dependency file.
Resolution
A dependency file is a standard Windows .INI file and can be read andwritten to using the standard Windows APIs (GetPrivateProfileString andWritePrivateProfileString).
There are a few items to note for dependency files:
Dependency files may have multiple sections. The section orderis not significant.Entries are not case-sensitive.Comments are allowed when preceded by a semi-colon (;).The dependency file name is important. The file name prefixmust match the file name of the component it describes. Forexample, a dependency file MyOCX.DEP would correspond to acomponent, such as MyOCX.OCX or MyOCX.DLL.Each section in a .DEP file uses the following syntax:

[Component File Name]Dest=<Destination>UsesN=<Dependent File>Register=<Method of Registration>Version=<Component version>Date=<Component Date>Time=<Component Time>ProgramIconTitle=<Title for Shortcut>ProgramIconCmdLine=<Command Line for Shortcut>
Dest=The Dest= key indicates the destination folder for the component. Thisvalue may be a relative path, a full path, or a path based on any of thefollowing macros (for example, it may be simply a macro, or it may be amacro followed by a backslash and a relative path):

$(AppPath)Indicates the path the user selectsduring setup. $(WinSysPath)Indicates the \Windows\System or\Winnt\System32 folder. $(WinPath)Indicates the \Windows or \Winnt folder. $(ProgramFiles)Indicates the folder specified atHKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir. $(CommonFiles)Indicates the folder specified atHKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\CommonFilesDir. $(CommonFilesSys)Indicates $(CommonFiles)\System inWindows 95, Windows 98, NT 4.0, and Windows 2000,or the same as $(WinSysPath) in NT 3.51. $(MSDAOPath)The location stored in the registryfor DAO components. The Dest= key applies only to the component to which the section applies.By default, all files dependent on the component will also be placed in thesame location. To override the location for a “child,” you can create asection for the “child” and specify a different destination in thatsection.
UsesN=The UsesN= key (where N is an integer) indicates a dependent file for thecomponent. A file specified by a UsesN= key is required for the componentdefined by that section. In a section, N must be sequential and must startwith 1. For an illustration, refer to the following sample section:

[MyOCX.OCX]Dest=$(WinSysPath)Uses1=MyDLL.DLLUses2=MyOCX.TXT In this example, MyOCX.OCX depends upon (or requires) MyDLL.DLL andMyOCX.TXT.
NOTE: If the UsesN keys are not ordered sequentially, or if a number isskipped, dependent files may not be recognized in the section and may notbe acknowledged by the Setup Wizard or PDW.
Register=The Register= key indicates whether the file should be registered and, ifso, how it should be registered. The valid values for this key are:

NoneIf a value is omitted for this key,the file is not registered.$(DllSelfRegister)The file supports self-registrationand self-unregistration via a DLLentry point.$(ExeSelfRegister)The file is a local server thatsupports self-registration throughthe command-line parameter”/RegServer” and self-unregistrationthrough the command-line parameter”/UnRegServer.”$(TLBRegister)The file is a .TLB file and should beregistered.FilenameThe file is registered by callingRegedit.exe with this filename as aCommand-line parameter.$(Remote)Used only by Visual Basic to indicatethat the file is a .VBR file. If the Register= key is omitted altogether, the file is not registered.
Version=(Optional)
The Version= key indicates the version of the component that is needed. TheSetup Wizard and PDW can detect that a .dep file is out-of-date using theVersion= key. The version is specified in the format a.b.c.d, as in thefollowing example:

Version=4.50.10.11
Date=(Optional)
The Date= key is the date stamp of the component that is needed. The SetupWizard and PDW can detect that a .DEP file is out-of-date using this key.This value must always be in the format d/m/yyyy or dd/mm/yyyy, even whenusing a localized Setup Wizard or PDW. For example:

Date=10/5/1996 -or-

Date=04/03/1997 NOTE: This key is ignored if a value is specified for the Version= key.
Time=(Optional)
The Time= key is the time stamp of the component that is needed. The SetupWizard and PDW can detect that a .DEP file is out-of-date using this key.This value must always be in the 24-hour format hh:mm:ss, even when using alocalized Setup Wizard or PDW. For example:

Time=14:05:32 NOTE: This key is ignored if a value is specified for the Version= key.
ProgramIconTitle= and ProgramIconCmdLine=(Optional)
The ProgramIconTitle= key indicates that a shortcut (or Program Managericon for Windows NT 3.51) should be created if the file is installed. Thevalue for the ProgramIconTitle= key is the title given to the shortcut (oricon). The value may be quoted or unquoted. For example:

ProgramIconTitle=My Program Title If you indicate that a shortcut should be created, you can give the commandline for the shortcut by specifying a value for the ProgramIconCmdLine=key. The path that you use for the command-line value may contain themacros listed for the Dest= key. For example:

ProgramIconCmdLine=$(AppPath)\Readme.txt
Localized ComponentsSome components may have different dependencies based on the language. Toinstall a component based on the language setting for the client’scomputer, you may specify a section with the component name followed by thelanguage ID.
For example, VBRUN500.DLL has a satellite DLL for all languages (with theexception of English):

[VBRUN500.DLL]Dest=$(WinSysPath)[VBRUN500.DLL <000C>];000C = primary language ID for FrenchUses1=VB5FR.DLL[VBRUN500.DLL <0007>];0007 = primary language ID for GermanUses1=VB5DE.DLL In this example, if VBRUN500.DLL is installed and the client’s languagesettings are French, VB5FR.DLL will also be installed. Likewise, ifVBRUN500.DLL is installed and the client’s language settings are German,VB5DE.DLL will be installed.
Sample Dependency FileThe following is a sample .DEP file for a component named MyOCX.OCX. Thisdependency file would be named MyOCX.DEP:

[MyOCX.OCX]Register=$(DLLSelfRegister)Dest=$(WinSysPath)Date=1/23/1996Time=10:15:33Version=1.1.13.6Uses1=MyDLL.DLLUses2=MyServer.EXEUses3=VBRUN500.DLL[MyServer.EXE]Dest=$(WinPath)Date=1/23/1996Time=18:52:48Version=1.0.1.0Uses1=VBRUN500.DLLRegister=$(ExeSelfRegister)ProgramIconTitle=My ProgramProgramIconCmdLine=$(WinSysPath)\MyOCX.OCX[MyDLL.DLL]Register=$(DLLSelfRegister)Version=1.0.1.0[VBRUN500.DLL]Dest=$(WinSysPath);Additional Files for International Support[VBRUN500.DLL <0007>]Uses1=VB5DE.DLL[VBRUN500.DLL <000C>]Uses1=VB5FR.DLL MyOCX.OCX is a self-registering file that is installed in theWindows\System folder (or Winnt\System32 folder on NT or Windows 2000). MyOCX.OCX depends upon (requires) three files: MyDLL.DLL, MyServer.EXE, and VBRUN500.DLL.
MyServer.EXE is a self-registering file that is installed in the Windowsfolder (or Winnt folder on NT or Windows 2000). MyServer.EXE has only one dependent file, VBRUN500.DLL. If MyServer.EXE is installed during setup, a shortcut is created with the title “My Program” and the command lineWindows\System\MyOCX.OCX (or Winnt\System32\MyOCX.OCX on NT or Windows 2000).
MyDLL.DLL is also a self-registering file. A destination for MyDLL.DLL isnot specified; thus, it will be placed in the destination path for itsparent, MyOCX.OCX.
VBRUN500.DLL will not be registered because a Register= key is notspecified in its section. VBRUN500.DLL will be placed in the Windows\System(or Winnt\System32) folder. If VBRUN500.DLL is installed during setup,VB5DE.DLL will be installed if the language setting is German and VB5FR.DLLwill be installed if the language setting is French. If the languagesetting is set to something other than French or German, no additionalfiles will be installed.
How Setup Wizard and PDW Search for Dependency InformationWhen the Setup Wizard and PDW need to find dependency information for afile (for example, MyOCX.OCX), they follow a specific path. The wizards usethe following methods to locate a section entitled [MyOCX.OCX]; when thesection is found, the search ends.
If the file has been located in a .DEP file, it will use theinformation in the .DEP file in which it was first found.The Setup Wizard will look in the default master dependencyfile for Visual Basic 5.0 (VB5DEP.INI). The PDW will look in thedefault master dependency file for Visual Basic 6.0 (VB6DEP.INI).Information that is placed in the default master dependency fileoverrides that which might be found elsewhere.The Setup Wizard and PDW will look for a dependency file namedMyOCX.DEP. If the dependency file is found, the wizard will searchfor the section entitled [MyOCX.OCX].It will search for a .DEP file associated with the parent ofMyOCX.OCX and possibly continue up the parent chain until asection entitled [MyOCX.OCX] is located.

How Visual Basic 4.0 Calls C and Fortran DLLs

Symptoms
This sample demonstrates how a Visual Basic 4.0 application calls Fortranand Visual C DLL’s. Specifically, it shows how to pass fixed lengthstrings to and from those DLL’s.
Resolution
The following file is available for download from the Microsoft Download Center:
Vbstring.exe(http://download.microsoft.com/download/vb40ent/sample40/1/w9xnt4/en-us/vbstring.exe)Release Date: Jan-01-1997
For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591?(http://support.microsoft.com/kb/119591/EN-US/)How to Obtain Microsoft Support Files from Online ServicesMicrosoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.
Visual Basic 4.0 replaced the string management system used by previousversions of Visual Basic with a more robust string management system.Visual Basic 4.0 relies on the OLE automation data types, such as BSTR andsafe arrays, to manage string usage. However, passing arrays of numerictypes, integers, or reals were not changed. For instance, before passing anarray of strings to a DLL, the strings must be converted to an array ofbytes, and then converted back to strings on return from the DLL. Please,refer to VB4DLL.TXT that ships with Visual Basic 4.0 for more information.
All new C DLL’s should use the syntax described in the VB4DLL.TXT filebecause the API calls that are employed allow for improved error handling.The programmer can do something in the event of an error, such as display amessage box and abort the operation.
Please note that the new Fortran DLL’s cannot use the syntax described inVB4DLL.TXT because they have no direct access to the correct APIfunctions.
The sample also demonstrates different methods you can use to resolve thefunction symbol within the DLL. A mismatch in the function symbol resultsin a Visual Basic runtime error, “Specified DLL function not found (Error453).” The sample includes two methods to resolve C function symbols andthree methods to resolve Fortran function symbols.
Each source file contains more information pertinent to that language.
This sample also enables you to choose whether the data is passed to eitherthe C or Fortran DLL.
This sample shows how to pass the following:
Two dimensional array of 4-byte integers.Two dimensional array of 8-byte floating point numbers.String.One dimensional array of strings.Two dimensional array of strings.One dimensional array of 4-byte integers, a one dimensional array of8-byte floating point numbers, and a one dimensional array of strings.
Sample Files

FileNameDescription——————————————————-cdll.cC source file to build 32-bit DLLfordll.forFortran source file for FPS NT 1.0 referencefordll32.f90Fortran source file for the 32-bit DLLvbstring.vbpVisual Basic 4.0 project filevbstring.frmVisual Basic form including event handlers
Building DLLsThis sample assumes you are using the following development environments:
Microsoft Visual C++, version 4.0Microsoft FORTRAN PowerStation for Windows 95 and Windows NT, version 4.0You will need to setup the environment before running BUILDDLL.BAT.At an MS-DOS command-line prompt type:

C:\MSDEV\BIN\VCVARS32.BAT Build the C DLL. At the command-line prompt type:

BUILDDLL C Build the Fortran DLL. At the same prompt type:

BUILDDLL Fortran Start Visual Basic 4.0 and open the project file VBSTRING.VBP.Run the Visual Basic application by creating an executable file (.exe)or running the program from within Visual Basic.IMPORTANT: The DLLs must be in the \WINDOWS\SYSTEM directory, the directory containing the Visual Basic executable file, or one of the environment file paths.

Notes on Arrays in Different LanguagesGiven an upper bound of n, note that in Visual Basic all of the arrayranges are specified as “1 to n”. When a lower bound is not specified,Visual Basic, by default, assumes 0<=index<=n where “n” is inclusive. C array subscripts are assumed to be in the range 0<=index<=n-1. Fortran array ranges are 1<=index<=n. You need to be careful when you assign the index ranges, and make sure that they match. If you exceed them, you will probably get an Access Violation, an Unhandled Exception, or a random run-time error in your Visual Basic Application.

LanguageDeclarationRange# Items in Array—————————————-BasicDim X(10) As Integer0<=index<=1011Basic*Dim X(1 to 10) As Integer1<=index<=1010Cint X[10];0<=index<=910Fortraninteger X(10)1<=index<=1010Fortran*integer X(0:9)0<=index<=910* With lower bound specified. C is always zero-based.