这段代码错在哪?????
我做了一个函数用来得到系统路径
struct DEFINE_SYSTEM_PATH
{
AnsiString ProgramFilesPath;
AnsiString DeskTopPath;
AnsiString StartMenuPath;
AnsiString WindowsPath;
AnsiString RunPath;
};
bool __fastcall TDefine_Setup_Function::GetSystemPath(DEFINE_SYSTEM_PATH *SystemPath)
{
LPMALLOC ShellMalloc;
LPITEMIDLIST id;
char Dir[50];
//得到桌面路径
if(FAILED(SHGetMalloc(&ShellMalloc)))
return(false);
if(FAILED(SHGetSpecialFolderLocation(NULL,CSIDL_DESKTOPDIRECTORY,&id)))
return(false);
if(!SHGetPathFromIDList(id,Dir))
{
ShellMalloc->Free(id);
ShellMalloc->Release();
return(false);
}
SystemPath->DeskTopPath = Dir;
//得到程序组路径
if (FAILED(SHGetMalloc(&ShellMalloc)))
return(false);
if (FAILED(SHGetSpecialFolderLocation(NULL,CSIDL_PROGRAMS,&id)))
return(false);
if (!SHGetPathFromIDList(id,Dir))
{
ShellMalloc->Free(id);
ShellMalloc->Release();
return(false);
}
SystemPath->StartMenuPath = Dir;
//得到开始菜单的路径
if (FAILED(SHGetMalloc(&ShellMalloc)))
return(false);
if (FAILED(SHGetSpecialFolderLocation(NULL,CSIDL_STARTUP,&id)))
return(false);
if (!SHGetPathFromIDList(id,Dir))
{
ShellMalloc->Free(id);
ShellMalloc->Release();
return(false);
}
SystemPath->RunPath = Dir;
ShellMalloc->Free(id);
ShellMalloc->Release();
//得到WINDOWS安装路径
GetWindowsDirectory(Dir,50);
SystemPath->WindowsPath = Dir;
//得到程序组路径
TRegistry *Path = new TRegistry;
Path->RootKey = HKEY_LOCAL_MACHINE;
if (Path->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion",false))
{
SystemPath->ProgramFilesPath = Path->ReadString("ProgramFilesDir");
Path->CloseKey();
delete Path;
}
else
{
Path->CloseKey();
delete Path;
return(false);
}
ShowMessage(SystemPath->DeskTopPath);
ShowMessage(SystemPath->StartMenuPath);
ShowMessage(SystemPath->RunPath);
ShowMessage(SystemPath->ProgramFilesPath);
ShowMessage(SystemPath->WindowsPath);
return(true);
}
在WIN98上运行一点问题都没有,可是不能在WIN2000上运行,出现内存错误!!怎么改才可以在WIN98和WIN2000上同时用呀!