我正在尝试从服务程序调用二进制文件。二进制文件的路径是从注册表项中获取的。当我将缓冲区分配给字符串时,路径仅包含“C”。我在哪里犯了错误。我正在使用visual studio 2010这里是代码:
std::string path;
getPathFromKey(path);
path = path+"\\myapp.exe";
argument = "start \"\" \""+path+"\"";
system(argument.c_str());
/ *检索密钥* /
void getPathFromKey(std::string &path)
{
HKEY hKey = 0;
char buf[512];
DWORD dwType = 0;
DWORD dwBufSize = sizeof(buf);
if( RegOpenKey(HKEY_LOCAL_MACHINE,L"SOFTWARE\\MYAPP\\MyApp",&hKey) == ERROR_SUCCESS)
{
dwType = REG_SZ;
if( RegQueryValueEx(hKey,L"InstallPath",0, &dwType, (LPBYTE)buf, &dwBufSize) == ERROR_SUCCESS)
{
for(int i=0;buf[i];i++)
path[i]=buf[i];
return;
}
else
{
RegCloseKey(hKey);
return;
}
}
else if( RegOpenKey(HKEY_LOCAL_MACHINE,L"Software\\Wow6432Node\\MYAPP\\MyApp",&hKey) == ERROR_SUCCESS)
{
dwType = REG_SZ;
if( RegQueryValueEx(hKey,L"InstallPath",0, &dwType, (BYTE*)buf, &dwBufSize) == ERROR_SUCCESS)
{
for(int i=0;buf[i];i++)
path[i]=buf[i];
return;
}
else
{
RegCloseKey(hKey);
return;
}
}
}
我收到以下错误:
Windows cannot find "C"