path - C++ conversion from char * to unsigned char? -
hello i'm trying create take program path , put in in registry file, keep on having error. here code:
#include <iostream> #include <windows.h> #include <winuser.h> #include <tchar.h> #include <limits> using namespace std; void reg() { char buffer[max_path]; getmodulefilename(null,buffer,sizeof(buffer)); const unsigned char path[ max_path ] = {buffer}; ::hkey handle_key = 0; ::regsetvalueex( handle_key, "my directory", 0, 1, path, sizeof path ); };
the error i'm getting says
invalid conversion 'char*' 'unsigned char' [-fpermissive]
i have spent hours looking solution, can't find one.
the problem, i'm guessing, line
const unsigned char path[ max_path ] = {buffer};
the problem here try create array of single characters character pointer.
you use variable temporary regsetvalueex
call, don't need it. instead call function buffer
directly.
also, should not use sizeof
here, since put all of buffer in registry, , not actual string. use strlen
.
like:
::regsetvalueex( handle_key, "my directory", 0, 1, reinterpret_cast<unsigned char*>(buffer), strlen(buffer));
Comments
Post a Comment