HOWTO: Pass a NULL String to a Windows API from Visual Basic

Last reviewed: March 26, 1997
Article ID: Q162622

The information in this article applies to:
  • Microsoft Visual Basic Control Creation, Learning, Professional, Enterprise Editions for Windows, version 5.0
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic for Windows, version 4.0

SUMMARY

This article describes how to pass NULL as a parameter to any Windows API function that requires a pointer to a string from a Visual Basic 4.0 or 5.0 application.

MORE INFORMATION

Many Windows APIs have pointers to strings (for example, LPSTR or LPCSTR) in their parameter lists. The documentation often indicates that special processing occurs if a NULL is passed (instead of a pointer to a string). With earlier versions of Visual Basic, you could accomplish this by using 0& for the parameter. However, Visual Basic 4.0 and 5.0 include a special constant, vbNullString, that you can use when you need to pass NULL to a Windows API.

For example, here's the declaration for the Win32 function FindWindow that accepts two pointers to strings:

      HWND FindWindow(
          LPCTSTR lpClassName,   // pointer to class name
          LPCTSTR lpWindowName   // pointer to window name
          );

If NULL is passed as the second parameter, FindWindow locates any window of the specified class name. In a C or C++ program, the call might look like this:

      hRet = FindWindow("MyWindowClass", NULL);

If you make the same call from Visual Basic, it looks like this:

      hRet = FindWindow("MyWindowClass", vbNullString)

Note that using vbNullString is equivalent to passing NULL as the parameter. This is not the same as passing an empty string ("").

REFERENCES

Visual Basic Help file, versions 4.0, 5.0; Topic: "Declare Statement"


Keywords : kbusage PrgOther VB5All vb5howto kbhowto
Version : 4.0 5.0
Platform : WINDOWS
Issue type : kbhowto


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: March 26, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.