I was playing around with GetNumberFormatEx and ran into a problem with using Unicode wide strings. Is there a better way to get the size of a uninitialized WSTRINGZ buffer? LEN returns 0 and SIZEOF returns 30. I came up with a macro SizeOfW that divides the SIZEOF by CHRBYTES.
Code:
#COMPILER PBWIN #COMPILE EXE #DIM ALL %UNICODE = 1 #INCLUDE "Win32API.Inc" MACRO SizeOfW(prm1) = SIZEOF(prm1) / CHRBYTES(prm1) '******************************************************************************** FUNCTION PBMAIN() AS LONG '******************************************************************************** LOCAL lDebug AS LONG: TXT.WINDOW "Debug", 10,10,50,75 TO lDebug 'Thanks Dave! LOCAL lpValue, lpNumberStr AS WSTRINGZ * 15 LOCAL cchNumber, lResult AS LONG lpValue = "-12345678.90" TXT.PRINT " Len = " & DEC$(LEN(lpNumberStr)) TXT.PRINT " SizeOf = " & DEC$(SIZEOF(lpNumberStr)) TXT.PRINT "SizeOfW = " & DEC$(SizeOfW(lpNumberStr)) TXT.PRINT cchNumber = SizeOfW(lpNumberStr) TXT.PRINT "cchNumber = " & DEC$(cchNumber) TXT.PRINT lResult = GetNumberFormatEx(BYVAL %NULL, 0, lpValue, BYVAL %NULL, lpNumberStr, cchNumber) IF lResult = 0 THEN lResult = GetLastError() SELECT CASE lResult CASE %ERROR_INSUFFICIENT_BUFFER: TXT.PRINT "Error: Insufficient Buffer" CASE %ERROR_INVALID_FLAGS: TXT.PRINT "Error: Invalid Flags" CASE %ERROR_INVALID_PARAMETER: TXT.PRINT "Error: Invalid Parameter" CASE %ERROR_OUTOFMEMORY: TXT.PRINT "Error: Out of Memory" CASE ELSE END SELECT ELSE TXT.PRINT "lpNumberStr = " & lpNumberStr & " (" & DEC$(lResult) & ")" END IF TXT.PRINT TXT.PRINT "Press any key to exit (just like the old days!)": TXT.WAITKEY$: TXT.END END FUNCTION
Comment