PDA

View Full Version : While changing external function from ANSI to Wide, what to pass as size?



WWGT
5-Jan-2023, 03:53 AM
So we are in the process of converting our 19.1 application to 23.0 and I've hit a problem while converting a call to CryptStringToBinaryA.

It's clear to use WStrings etc but CryptStringToBinaryW expects a pointer to the data AND the size of the data. In the ANSI version it was just the Length() but what to pass for the wide version?
We have SizeOfString() that returns the amount of UTF8 bytes but is there such a thing for WString?


External_Function CryptStringToBinary "CryptStringToBinaryW" Crypt32.dll Pointer pszString DWord cchString ;
DWord dwFlags Pointer pbBinary Pointer pcbBinary Pointer pdwSkip Pointer pdwFlags Returns Boolean


This is what I have currently but have not tested it as I doubt SizeOfString() is correct

Move (CryptStringToBinary(AddressOf(wsBase64),SizeOfStr ing(wsBase64),dwFlags,AddressOf(wsData),AddressOf( dwSize),AddressOf(dwSkip),AddressOf(dwFlags))) to bResult

WWGT
5-Jan-2023, 04:07 AM
Nevermind stupid me, didn't see there was a SizeOfWString function... d'oh.

Harm Wibier
5-Jan-2023, 04:07 AM
Did you see SizeOfWString (https://docs.dataaccess.com/dataflexhelp/#t=mergedProjects%2FLanguageReference%2FSizeOfWStr ing.htm)? This gives the number of code units and it is what API's expecting a wide string usually want.

Harm Wibier
5-Jan-2023, 04:08 AM
No worries, glad you found it.. BTW, I moved this thread to the Unicode and 64-bit forum..