FAQ: APIs & DLLs in Visual Basic 3.0

ID: Q126727


The information in this article applies to:

This article covers some of the most Frequently Asked Questions (FAQ) about non-technical 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:

    Q94960 : 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:

    Q98309 : '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:

    Q75639 : How to Access Windows Initialization Files Within Visual Basic

    Q115328 : DOCERR: Write*ProfileString Declaration Incorrect in API

    Q110826 : 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:

    Q106553 : How to write C DLL's and Call Them from Visual Basic

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

    Q109290 : 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:

    Q94961 : How to Create a Transparent Bitmap Using Visual Basic


Additional query words: 3.00 gpf gp-fault general protection FAQ


Keywords          : 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: June 11, 1999