datei erneut öffnen->FEHLER
-
wenn ich ne datei öffne und dann erneut öffne, dann krieg ich nen fehler!
hier ein auszug ausm code:
char *LoadFileToObj(char* file, HWND toshow) { HANDLE hf; hf = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL); unsigned long nRead = GetFileSize(hf,NULL); char *lpbuffer = new char[nRead]; unsigned long nBytesRead; lpbuffer[nRead]=0; ReadFile(hf,lpbuffer,nRead,&nBytesRead, NULL); SetWindowText(toshow, file); return lpbuffer; } void SaveToFile(char *pFilename, char *pBuffer, int nSize) { HANDLE hf; hf = CreateFile(pFilename, GENERIC_WRITE, FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES) NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL); unsigned long nBytesRead; WriteFile(hf , pBuffer, nSize, &nBytesRead, NULL); } inline int GetEditTextLength(HWND hWnd) { return SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0)+1; } void OpenOrSaveDlg(bool mode, HWND hFileWindow, HWND hContentWindow, HWND hwnd) { if(mode == TRUE) { OPENFILENAME ofn; // common dialog box structure char szFile[260]; // buffer for file name< // Los Gehts (MSDN krams) //Memory leeren: ZeroMemory(&ofn, sizeof(ofn)); //Grösse, Owner, File... ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFile = szFile; // // Set lpstrFile[0] to '\0' so that GetOpenFileName does not // use the contents of szFile to initialize itself. // //Anm,: ??? ofn.lpstrFile[0] = '\0'; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0"; ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir = NULL; ofn.Flags = OFN_OVERWRITEPROMPT; if (GetSaveFileName(&ofn)==TRUE) { char *lpBuffer = new char[GetEditTextLength(hContentWindow)]; GetWindowText(hContentWindow, lpBuffer, GetEditTextLength(hContentWindow)); SaveToFile(ofn.lpstrFile, lpBuffer, GetEditTextLength(hContentWindow)); } } if(mode == FALSE) { OPENFILENAME ofn2; char szFile[260]; ZeroMemory(&ofn2, sizeof(ofn2)); ofn2.lStructSize = sizeof(ofn2); ofn2.hwndOwner = hwnd; ofn2.lpstrFile = szFile; ofn2.lpstrFile[0] = '\0'; ofn2.nMaxFile = sizeof(szFile); ofn2.lpstrFilter = "All\0*.*\0Text\0*.TXT\0"; ofn2.nFilterIndex = 1; ofn2.lpstrFileTitle = NULL; ofn2.nMaxFileTitle = 0; ofn2.lpstrInitialDir = NULL; ofn2.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if (GetOpenFileName(&ofn2)==TRUE) { SetWindowText(hContentWindow, LoadFileToObj(ofn2.lpstrFile, hFileWindow)); } } }
-
Ist irgendwie logisch, Du öffnest Sie, schließt sie aber nie...
Man lese die MSDN bezüglich CreateFile etwas genauer...
-
ach da muss man auch wieder schliessen
ja ok ich werds lesen!