PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

File: Save As with Commdlg.h?

Sorry for asking so many questions.

What am I doing wrong here?

This snippet is in my WndProc function.

The code compiles, but nothing gets saved.

I was looking for a WinCE-specific example, but haven't found anything.

I'm guessing it's another unicode vs. ASCII issue?

Thanks.

Code:

FILE* textfile=NULL;
LRESULT lResult = TRUE;
TCHAR szFile[MAX_PATH] = TEXT("\0");
OPENFILENAME ofn;
memset(&(ofn), 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
ofn.nMaxFile = MAX_PATH;

case ID_FILE_SAVEAS:

ofn.lpstrFilter = TEXT("Text(*.txt)\0*.txt\0");
ofn.lpstrTitle = TEXT("Save File As");
ofn.Flags = OFN_HIDEREADONLY;
ofn.lpstrDefExt = TEXT("txt");

if (GetSaveFileName(&ofn))
{

ShowInfo(hwnd,ofn.lpstrFile);

textfile=fopen((LPSTR)ofn.lpstrFile,"w");

if(!textfile) return -1;

fprintf(textfile, "TEST!\n");

}
break;
WingedOne · 03 Jun 2004, 12:09 UTC — I got it solved.
Nevermind.

I figured it out.

I changed line 23 to read:

textfile=_tfopen(ofn.lpstrFile,_T("w"));

and now it works fine. :D

Nothing to see here. Move along. Move along.
When you had to cast the filename to (LPSTR) that should have been an indicator that your string types didn't match. You can use fopen but you will have to convert UNICODE to ANSI first.

Also don't forget to close your file.

Dan East