FAQ: APIs & DLLs in Visual Basic 3.0

Last reviewed: July 20, 1995
Article ID: Q126727
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, version 3.0

This article covers some of the most Frequently Asked Questions (FAQ) about nontechnical issues for Microsoft Visual Basic for Windows. You can find this and other FAQ articles by querying on the keyword "FAQ." You can find additional general references in the Microsoft Knowledge Base by searching on "article list."

Most of the following information can be found in Chapter 24 "Calling Procedures in DLLs" of the "Professional Features Book 2."

1. Q. How do you pass an LPSTR or LPCSTR string to a DLL or API?

   A. To pass a string to an API or DLL call that expects an LPSTR or
      LPCSTR, you need to declare the parameter as ByVal; that is, ByVal
      lpModuleName As String.

2. Q. Why do I get a GP fault after calling an API/DLL that returns a
      string?

   A. You need to initialize your string buffer before you make the call;
      for example:

      szFileName = Space$(128)      'initialize to 128 spaces
      Call GetFileName(szFileName)  'call the DLL which modifies the string

3. Q. How do I pass numbers to my DLL?

   A. Usually, you want to use ByVal when passing numerics to your DLL.

      For additional information, please see the following article(s) in
      the Microsoft Knowledge Base:

      ARTICLE-ID: Q94960
      TITLE     : How to Pass Numeric Variables to a C DLL

4. Q. How do I pass a User Defined Type or Structure?

   A. User Defined Types or Structures (in C) can be passed by reference.
      Because Visual Basic passes this way by default, all you need to do
      is place the user defined type variable in the argument list. For
      example, if you have the following user defined type and function
      declaration

      Type POINTAPI
        x As Integer
        y As Integer
      End Type
      Declare Function PassUDT Lib "MyLib.DLL" (pt As POINTAPI) As Integer

      you could call the function passing the variable as follows:

      Dim CoOrdinate As POINTAPI
      CoOrdinate.X = 10
      CoOrdinate.Y = 10
      ret% = PassUDT(CoOrdinate)

5. Q. I keep getting "Error Loading DLL" when I try can call my function.
      All the declarations are set up correctly; what else could be going
      wrong?

   A. If you created the DLL, check your .DEF file and make sure the
      LIBRARY name is the same as the filename.

      For additional information, please see the following article(s) in
      the Microsoft Knowledge Base:

      ARTICLE-ID: Q98309
      TITLE     : 'Error in loading DLL' When LIBRARY Name Not Same as
                  Filename

6. Q. How do I manipulate INI files?

   A. Visual Basic can manipulate INI files through the Windows API. These
      calls are documented in several Knowledge Base articles.

      For additional information, please see the following articles in the
      Microsoft Knowledge Base:

      ARTICLE-ID: Q75639
      TITLE     : How to Access Windows Initialization Files Within Visual
                  Basic

      ARTICLE-ID: Q115328
      TITLE     : DOCERR: Write*ProfileString Declaration Incorrect in API

      ARTICLE-ID: Q110826
      TITLE     : DOCERR: GetPrivateProfileString Declaration Incorrect in
                  API

7. Q. How can I find out more about calling the windows API?

    A. There are two useful help files shipped with Visual Basic,
      Professional Edition. The Windows SDK Help file discusses Windows API
      general topics, functions, structures and messages. Its companion
      help file, Windows 3.1 API Help, offers the Visual Basic declare
      statements, type declarations and global constants used to access
      much of the Windows API. In addition, there are the following
      resources:

      Chapter 24 (Call Procedures in DLLs) of the "Programmer's Guide" is a
      good place to start looking at DLL and VB issues.

      For additional information, please see the following article(s) in
      the Microsoft Knowledge Base:

      ARTICLE-ID: Q106553
      TITLE     : How to write C DLL's and Call Them from Visual Basic

      ARTICLE-ID: Q110219
      TITLE     : LONG: How to Call windows API from VB - General
                  Guidelines

      ARTICLE-ID: Q109290
      TITLE     : Popular Windows API Functions Used from Visual Basic 3.0

8. Q. How can I create a transparent bitmap, or layer multiple bitmaps on
      top of each other?

   A. If bitmaps are layered on top of one another, the overlapped regions
      will not show through the bitmaps that are on top unless the upper
      bitmap has transparent regions. Article Q94961 shows how to create a
      transparent bitmap from Visual Basic using Windows APIs.

      For additional information, please see the following article(s) in
      the Microsoft Knowledge Base:

      ARTICLE-ID: Q94961
      TITLE     : How to Create a Transparent Bitmap Using Visual Basic


Additional reference words: 3.00 gpf gp-fault general protection FAQ
KBCategory:
KBSubcategory:


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 20, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.