문제

조금 이상합니다. 좋아, 그래서 나는 일부 파일 스트림을 백그라운드에서 열어 두는 "SceneManager"클래스가있는 Ogre 게임 엔진으로 작업하고 있습니다. getopenfilename ()을 사용하기 직전에 해당 스트림을 사용하는 경우 해당 스트림은 제대로 작동하지만 getopenfilename () 이후에 해당 스트림을 사용하려고하면 해당 스트램이 닫힌 것으로 나타났습니다. 누군가가 getopenfilename ()가 내 배경 스트림을 죽이는 이유를 밝힐 수 있습니까?

String Submerge::showFileDialog(char* filters, bool savedialog, char* title)
// need to tweak flags for open/save
{
OPENFILENAME ofn ;
char szFile[255] ;
HWND hwnd = NULL;
//getOgre()->getAutoCreatedWindow()->getCustomAttribute("WINDOW", &hwnd);

ZeroMemory( &ofn , sizeof(ofn) );
ofn.hwndOwner = hwnd;
ofn.lStructSize = sizeof ( ofn );
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof( szFile );
ofn.lpstrFilter = filters ? filters : "All files\0*.*\0";
ofn.nFilterIndex =1;
ofn.lpstrFileTitle = NULL ;
ofn.nMaxFileTitle = 0 ;
ofn.lpstrInitialDir=NULL ;
if(title!=NULL)
    ofn.lpstrTitle=title;
//ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST ;

MeshLoadTest(); // this is where i use background file streams
bool success = false;
if(savedialog)
    success = GetSaveFileName( &ofn );
else
    success = GetOpenFileName( &ofn );
MeshLoadTest(); // this is where i use background file streams

if(!success)
    return "";
String str;
str.append(ofn.lpstrFile);
return str;
return "";
}
도움이 되었습니까?

해결책

주목하십시오 GetOpenFileName() 전체 프로세스의 현재 디렉토리를 변경할 수 있고 변경합니다. 이것은 당신이하고있는 다른 일을 방해 할 수 있습니다.

호출 옵션이 있습니다 OFN_NOCHANGEDIR, 그러나 선적 서류 비치, 비효율적입니다 :

사용자가 파일을 검색하는 동안 디렉토리를 변경하면 현재 디렉토리를 원래 값으로 복원합니다. Windows NT 4.0/2000/xp:이 깃발은 효과가 없습니다 getOpenFilename.

이 호출 전후에 현재 디렉토리를 확인해야합니다. 그것이 바뀌면 이것이 당신의 문제 일 수 있습니다. 이 경우 코드를 추가하여 호출 주변의 현재 디렉토리를 저장하고 복원하십시오. GetOpenFileName().

다른 팁

감사합니다. 또 다른 발견을했습니다.

(이것은 실제로 다른 답변에 대한 답변이며, 현재 디렉토리의 변경에서 문제의 출처가 식별되었습니다)

현재 디렉토리를 저장하려면 :

#define ARRSIZE(arr) (sizeof(arr)/sizeof(*(arr)))

//...

TCHAR curDir[MAX_PATH];
DWORD ret;
ret=GetCurrentDirectory(ARRSIZE(curDir),curDir);
if(ret==0)
{
    // The function falied for some reason (see GetLastError), handle the error
}
else if(ret>ARRSIZE(curDir))
{
    // The function failed because the buffer is too small, implementation of a function that uses dynamic allocation left to the reader
}
else
{
    // Now the current path is in curDir
}

경로를 복원하려면 간단하게하십시오

if(!SetCurrentDirectory(curDir))
{
    // The function failed, handle the error
}

.

팁 : tchars와 일반 텍스트 매핑 함수를 사용하여 응용 프로그램의 시작부터 : 이렇게하면 애플리케이션이 유니 코드 경로와 호환되어야 할 때 미래에 많은 문제를 피할 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top