这段代码在调用strcpy时会崩溃。我在代码的许多地方都使用了这种方法来创建路径。但是这个代码总是只在一个特定的函数中出错。这段代码的问题是什么
char updaterPath[1024];
if(GetModuleFileName(NULL, updaterPath, 1024)==0)
{
return 0;
}
char * temp=strrchr(updaterPath,'\');
strcpy(temp,"\ru.exe");
我找到了解决方案。但它很蹩脚,没有意义。我的原始代码是这样的
char updaterPath[1024];
if(GetModuleFileName(NULL, updaterPath, 1024)==0)
{
return 0;
}
if(RegCreateKeyEx(HKEY_CURRENT_USER,"Software\ddddd",0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,NULL)==ERROR_SUCCESS)
{
long res1=RegQueryValueEx(hKey,"version", NULL, NULL, (LPBYTE)regVersion, ®VersionLen);
if(res1==ERROR_FILE_NOT_FOUND||strcmp(regVersion,AutoVersion::FULLVERSION_STRING)) //check for version mismatch and go in
{
char * temp = strrchr(updaterPath,'\');
strcpy(temp+1,"Downloads\ru.exe");
我把它改成了这个,现在它工作得很好
char updaterPath[1024];
if(RegCreateKeyEx(HKEY_CURRENT_USER,"Software\ddddd",0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,NULL)==ERROR_SUCCESS)
{
long res1=RegQueryValueEx(hKey,"version", NULL, NULL, (LPBYTE)regVersion, ®VersionLen);
if(res1==ERROR_FILE_NOT_FOUND||strcmp(regVersion,AutoVersion::FULLVERSION_STRING)) //check for version mismatch and go in
{
if(GetModuleFileName(NULL, updaterPath, 1024)==0)
{
return 0;
}
char * temp = strrchr(updaterPath,'\');
strcpy(temp+1,"Downloads\ru.exe");