convert std::string to const BYTE* for RegSetValueEx()

后端 未结 4 985
深忆病人
深忆病人 2021-01-19 07:54

I have a function that gets a std::string. That function calls

RegSetValueEx

the 5th parameter is the value of the registry value and expects a variable of t

4条回答
  •  执笔经年
    2021-01-19 08:14

    You could also copy the unicode string into a byte array:

    LPWSTR pData = L"SampleGrabber";
    int dwSize = wcslen(pData)*sizeof(TCHAR);
    BYTE slump[256];
    memset((void*) slump, 0, 256*sizeof(BYTE));
    memcpy((void*) slump, (const void *) pData, dwSize*sizeof(BYTE));
    
    globit = RegSetValueEx(hKey, NULL, 0, REG_SZ, (const BYTE*) slump, dwSize);
    

    If you had the misfortune to be writing code for a WINCE 5.0 device and it lacked part of the regedit API.

提交回复
热议问题