1

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.

Natalie Carr
  • 3,707
  • 3
  • 34
  • 68

2 Answers2

3

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

CrazyCasta
  • 26,917
  • 4
  • 45
  • 72
-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:

LPCSTR, LPCTSTR and LPTSTR

Community
  • 1
  • 1
blackbada_cpp
  • 422
  • 4
  • 11