INFO: Class Library Functions to Handle Visual Basic StringsID: Q102147
|
The Microsoft Foundation Classes library provides three functions to
manipulate Visual Basic strings (otherwise known as HLSTRs). Normally,
an application designed with the Microsoft Foundation Classes receives
an HLSTR from an event parameter. Technical note 27 provides
additional information on receiving these parameters in its section
titled "VBX Event-Handling Function Parameters." To view technical
notes, choose the MFC Tech Notes icon in the Visual C++ program group
in Program Manager.
To make the functions available from any module in your program, add
the following statements to a global header file, such as STDAFX.H:
// Visual Basic string handling declaration section
typedef LPVOID HLSTR;
#define ERR USHORT
#define VBAPI FAR PASCAL
LPSTR VBAPI _AfxVBDerefHlstr(HLSTR);
ERR VBAPI _AfxVBGetHlstrLen(HLSTR);
ERR VBAPI _AfxVBSetHlstr(HLSTR FAR *, LPVOID, USHORT);
// End of declaration section
NOTE: These functions are only available in the static versions of the MFC
library. They are not supported in MFC250.DLL.
LPSTR VBAPI _AfxVBDerefHlstr(HLSTR hlstr);This function returns a pointer to the string data of a Visual Basic string. The returned pointer becomes invalid as soon as the string moves in memory; any call to a function of the Visual Basic application programming interface (API) may have that effect. When the string moves, it must be dereferenced again to obtain a valid pointer.
Parameter Type Description
------------------------------------------------------------------
hlstr HLSTR Handle to the Visual Basic string.
LPSTR VBAPI _AfxVBGetHlstrLen(HLSTR hlstr, USHORT FAR * pcbLen);
This function returns a pointer to the string data of a Visual Basic
string and the length of the string. The returned pointer value
becomes invalid as soon as the string moves in memory; any call to a
function of the Visual Basic API may have that effect. When the string
moves, it must be de-referenced again to obtain a valid pointer.
Parameter Type Description
------------------------------------------------------------------
hlstr HLSTR Handle to the Visual Basic string.
pcbLen USHORT FAR * A far pointer to an unsigned integer that
contains the length of the returned
string data.
ERR VBAPI _AfxVBSetHlstr(HLSTR FAR *phlstr, LPVOID pb, USHORT cbLen);
This function assigns a new string value to an existing Visual Basic string
(HLSTR). The new string data may be shorter or longer than the existing
string. Because the string is managed in the Visual Basic string space, it
automatically moves in memory as necessary.
Parameter Type Description
------------------------------------------------------------------
phlstr HLSTR far * Pointer to an HLSTR (a memory location
that stores a handle to a Visual Basic
string).
pb LPVOID Pointer to the string data to assign to
the Visual Basic string. If this pointer
is NULL, then the string is uninitialized
and the existing data is not preserved.
cbLen USHORT Length of the new string in bytes. If
this argument is 0, the pb argument is
ignored. If this argument is -1, then pb
is assumed to be an HLSTR.
Additional query words:
Keywords : kb16bitonly kbnokeyword kbMFC kbVC
Version : 1.0 1.5
Platform : WINDOWS
Issue type :
Last Reviewed: August 8, 1999