Fog Creek Software
g
Discussion Board




win32 c++ question (out of desperation)

I know this generally isn't the place to post programming questions but I will anyway - or please point me to the best place.

I'm on a placement year for my degree and even though I don't know c++ my boss decided it would be fine for me to "learn on the job" and write an app for windows ce 3 / pocket pc devices...

Anyhow, my problem is I want to open a text file... I've got me open file dialog and passing the filename to a function correctly. However any attempt to use _wfopen successfully leaves me stuck.

So from file open dialog > successful _wfopen usage anyone?

James 'Smiler' Farrer
Thursday, January 15, 2004

Are you sure Ce supports the _wfopen call? I don't think it does.

Mr Jack
Thursday, January 15, 2004

http://msdn.microsoft.com/library/en-us/wcecrt/htm/_wcecrt_fopen_wfopen.asp

MSDN would suggest it does.

James 'Smiler' Farrer
Thursday, January 15, 2004

I might add I'm not opposed to using something else, as long as I can parse csv / tsv easily.

James 'Smiler' Farrer
Thursday, January 15, 2004

My guess would be (and this is a complete guess becuase I do not know you or your experience) is that you are doing something incorrect with the UNICODE.  When I moved from Win32 to do a few small CE projects, I about tore my hair out getting all of the UNICODE stuff right.

Post a code snippet

Matt Watson
Thursday, January 15, 2004

are you passing in the full path, or just the filename?
what sort of permissions are you trying to open it with, and what permissions are set on the file?


Thursday, January 15, 2004

I didn't realize CE supported Unicode. You learn something new every day. Out of curiousity, have you tried fopen?

Troy King
Thursday, January 15, 2004

Passing full name eg the param is "\My Documents\folder\thisfile.txt"

Then the code to try and open it...

FILE *fptr
TCHAR filename[128];
lstrcpy(filename, (LPTSTR)lParam)

fptr = _wfopen(filename,"r");

James 'Smiler' Farrer
Thursday, January 15, 2004

And yes I do have all the ; placed before someone points that out :)

James 'Smiler' Farrer
Thursday, January 15, 2004

So what happens? "Leaves me stuck" isn't very helpful.

BTW, shouldn't your "r" be _T("r")?


Thursday, January 15, 2004

OK changed it to use _T as well..

Well an...

if (fptr == NULL) {
  MessageBox(hWnd, TEXT("doh"), TEXT("error"), MB_OK);
}

is not executed...

Then...

fclose(fptr);
numclosed = _fcloseall();

In debug mode, numclosed has the value for 0...

so the check for null fails and it appears that it doesn't close the file?

Hmm.

James 'Smiler' Farrer
Thursday, January 15, 2004

How could _fcloseall close the file when you just called fclose with the file ptr the line before? All the zero is telling you is that there were no other files open, surely?


Thursday, January 15, 2004

Ah, I misread the documentation of what _fcloseall() does. Sorry.

Ok. Yup it now does return 1 for numclosed so I can assume it does open it. Now more fscanf appears to do nothing.

Oh well, onwards and onwards. Cheers for the help guys.

James 'Smiler' Farrer
Thursday, January 15, 2004

Check into "GetLastError()"


Thursday, January 15, 2004

*  Recent Topics

*  Fog Creek Home