Back to the WFC main page
wfc_convert_lpcwstr_to_cstring
$Revision: 15 $
Declaration
void wfc_convert_lpcwstr_to_cstring( LPCWSTR& unicode_string, CString& string )
Description
This eliminated a lot of code in the networking classes.
Microsoft (even in Visual C++ version 4.2) has the networking API header files all screwed up.
The string parameters are mis-typed. I used to have a lot of code in the classes to detect and
fix this but it was real ugly (and prevented const correctness). Adding this function allowed
me to fix Microsoft's mistake in one function.
Example
void print_machine_name( WKSTA_INFO_102 * information_p )
{
WFCTRACEINIT( TEXT( "print_machine_name()" ) );
// We were passed a pointer, do not trust it
try
{
CString machine_name;
// The wki102_computername field of the WKSTA_INFO_102 structure is
// of type LPTSTR. This is wrong. The correct type is LPWSTR. Why?
// LPTSTR is #define'd differently for different builds. In ANSI builds,
// LPTSTR equates to LPSTR, in UNICODE builds LPTSTR equates to LPWSTR.
// The LanMan data structures are always UNICODE regardless of the
// build type. It would seem Microsoft's own programmers don't
// understand the difference. Most of the LanMan API data structures
// suffer from this problem.
wfc_convert_lpcwstr_to_cstring( information_p->wki102_computername, machine_name );
_tprintf( TEXT( "Machine Name is " ), (LPCTSTR) machine_name );
}
catch( ... )
{
return;
}
}
Copyright, 2000, Samuel R. Blackburn
$Workfile: wfc_convert_lpwstr_to_cstring.cpp $
$Modtime: 1/17/00 9:33a $