Natalie Carr
Natalie Carr

Reputation: 3807

convert an unsigned char to LPCSTR

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.

Upvotes: 1

Views: 6413

Answers (2)

blackbada_cpp
blackbada_cpp

Reputation: 432

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:

LPCSTR, LPCTSTR and LPTSTR

Upvotes: -1

CrazyCasta
CrazyCasta

Reputation: 28362

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]).

Upvotes: 3

Related Questions