Hi i'm using VS2010 and MBCS. Can anyone tell me how to convert an unsigned char to LPCSTR? Sorry i'm only new to c++...:) Thanks
This is the code it is failing on:
hr = MsiSetProperty(hInstall, "LOCKCODE", szLockCode);
ExitOnFailure(hr, "failed to set LOCKCODE");
szLockCode
is the variable that needs to be converted.
An unsigned char array ( unsigned char szLockCode[10]
for instance) is technically already an LPCSTR. If you're using an array already then conversion is not the issue, if not, then you need an array. If you want a single character string, then you need an array of length 2. The character goes in the first position ( szLockCode[0]
) and the value 0 goes in the second position ( szLockCode[1]
).
You probably get error message like:
cannot convert parameter 3 from 'const char *' to 'LPCWSTR'
To avoid it you should either do type convertion:
hr = MsiSetProperty(hInstall, "LOCKCODE", (LPCSTR)szLockCode);
or use L prefix before string:
LPCSTR szLockCode = L"Some error";
hr = MsiSetProperty(hInstall, "LOCKCODE", szLockCode );
Here is a good explanation of what LPCSTR stand for:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.