The information in this article applies to:
SUMMARYThis sample demonstrates how a Visual Basic 4.0 application calls Fortran and Visual C DLL's. Specifically, it shows how to pass fixed length strings to and from those DLL's. MORE INFORMATIONThe following file is available for download from the Microsoft
Download Center. Click the file name below to download the file: Vbstring.exeRelease Date: Jan-01=1997 For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address http://www.microsoft.com/downloads/search.aspand then click How to use the Microsoft Download Center. Visual Basic 4.0 replaced the string management system used by previous versions of Visual Basic with a more robust string management system. Visual Basic 4.0 relies on the OLE automation data types, such as BSTR and safe arrays, to manage string usage. However, passing arrays of numeric types, integers, or reals were not changed. For instance, before passing an array of strings to a DLL, the strings must be converted to an array of bytes, 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 file because 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 a message box and abort the operation. Please note that the new Fortran DLL's cannot use the syntax described in VB4DLL.TXT because they have no direct access to the correct API functions. The sample also demonstrates different methods you can use to resolve the function symbol within the DLL. A mismatch in the function symbol results in a Visual Basic runtime error, "Specified DLL function not found (Error 453)." The sample includes two methods to resolve C function symbols and three 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 either the C or Fortran DLL. This sample shows how to pass the following:
Sample Files
Building DLLsThis sample assumes you are using the following development environments:
Notes on Arrays in Different LanguagesGiven an upper bound of n, note that in Visual Basic all of the array ranges 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.
REFERENCES
For information on passing Strings from Visual Basic 5.0 or Visual Basic 6.0 to C DLLs, please see the following article in the Microsoft Knowledge Base: Q187912 HOWTO: Pass a String Between Visual Basic and Your C DLL Additional query words: kbstream
Keywords : kbfile kbsample kbCompiler kbFL32 kbFortranPS kbLangFortran vbwin |
Last Reviewed: December 10, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |