Visual C++ Byte *
I just switched from Dev C++ to Visual C++ and I'm getting an error in my code that I wasn't getting when using Dev C++. The error is:
------ Build started: Project: badman_flex, Configuration: Debug Win32 ------
main.cpp
c:\documents and settings\administrator\my documents\visual studio 2010\projects\badman_flex\badman_flex\main.cpp(49): error C2664: 'RegSetValueExA' : cannot convert parameter 5 from 'char *' to 'const BYTE *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The code around that line is:
RegOpenKeyEx(HKEY_LOCAL_MACHINE, regPath, 0, KEY_ALL_ACCESS, &hKey);
RegQueryValueEx(hKey,"Userinit", 0, 0, (BYTE*)buff, &dwBufSize);
if(!strstr(buff, "myapp.exe")) {
char *filepath = strcat(windowsDir, filename);
char *newRegValue = strcat(buff, filepath);
RegSetValueEx(hKey, "Userinit", 0, REG_SZ, newRegValue, strlen(newRegValue));
What is a开发者_StackOverflow中文版 byte and why is VC++ causing an error?
Thanks
Edit I typecast and it worked :D
The RegSetValueEx() API accepts different kind of data to be written to the registry. Its 5th argument is a pointer to that data, declared as BYTE*. You are passing it a char*, wrong type. Note that you are doing it right a few lines back in the RegQueryValueEx() call. Fix:
RegSetValueEx(hKey, "Userinit", 0, REG_SZ, (BYTE*)newRegValue, strlen(newRegValue));
from windef.h
typedef unsigned char BYTE;
So either include windef.h or define this yourself
精彩评论