Creating File Help

Started by
7 comments, last by MattOranges 12 years, 4 months ago
Ok, so god help whoever attempts to look at this code.

The problem concerns two function in this code,
[font="monospace"]

BOOL CALLBACK AddOrder(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam), on line 351,and

[/font][font="monospace"]

BOOLCALLBACK AddQuery(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam), on line 876

[/font]
[font="monospace"]


[/font]
[font="monospace"]

They both work properly on their own, but if I run AddOrder, do not close the application, and run AddQuery, the logfile is never made. The logfile is supposed to be made on lines 979, 985, 1046, 1052, 1101, and 1107, depending on what the user is doing/what they have input. None of these calls will work after AddOrder has been run, but will work as many times as required if AddOrder has never been called.

[/font]
[font="monospace"]


[/font]
[font="monospace"]

Code is here:

[/font]http://codepad.org/SBhzt9oT
[font="monospace"]


[/font]
[font="monospace"]

I posted the whole project because as I said, I dont know where this problem could be. If its not simple, I sure am not expecting anyone to comb through this whole bananarama.

[/font]
[font="monospace"]


[/font]
[font="monospace"]

I cant find any link between the two functions and am baffled. I hope its something simple that Im just not seeing.

[/font]
[font="monospace"]


[/font]
[font="monospace"]

Thanks in advance for any help, godspeed.

[/font]
Advertisement
Its hard to tell but you might have an extra } at 1194, it appears to be from the previous commented out while loop.

edit: actually it looks like its for the previous previous while loop sorry about that!
darn, had my hopes all up! Sorry for a bad commenting, you can tell this isnt quite finished -.-

darn, had my hopes all up! Sorry for a bad commenting, you can tell this isnt quite finished -.-


Hrmm, I have having trouble locating anything that sticks out but im no expert.
But looking in your AddQuery Function
static int textactive = 0; //1 = barcode, 2 = customer, 3 = ordernumber

When you go into your code you set the number based on the LOWORD(wParam)

but if your wParam is not IDC_QBARCODE, IDC_QCUSTOMER, or IDC_QORDERNUMBER
Your textactive would still be set to zero and when you get to your IDOK, if this was still 0 nothing would be written to a log file.

I would try stepping through that section and see whats going on.



[quote name='MattOranges' timestamp='1323451331' post='4892248']
darn, had my hopes all up! Sorry for a bad commenting, you can tell this isnt quite finished -.-


Hrmm, I have having trouble locating anything that sticks out but im no expert.
But looking in your AddQuery Function
static int textactive = 0; //1 = barcode, 2 = customer, 3 = ordernumber

When you go into your code you set the number based on the LOWORD(wParam)

but if your wParam is not IDC_QBARCODE, IDC_QCUSTOMER, or IDC_QORDERNUMBER
Your textactive would still be set to zero and when you get to your IDOK, if this was still 0 nothing would be written to a log file.

I would try stepping through that section and see whats going on.



[/quote]

I can tell you, having stepped through the program repeatedly, it does get to where it calls fopen. It passes it a valid file name as well. To the best of my knowledge,
[font="monospace"] myfile=fopen(filename,[/font]

"w"

[font="monospace"]);[/font]

[font="Arial"]is being properly called, and not creating a file. I should have said that more explicitly in the first post, my bad again. You are right about needing a check to make sure I have some value for textactive when OK is pressed.[/font]

Also you should check if myfile is NULL after the fopen, as to WHY it doesn't open thats something strange.

I was thinking maybe you didn't fclose or something like that but I didn't find that in the code.
http://pubs.opengroup.org/onlinepubs/7908799/xsh/fopen.html

And check errno for one of those error codes.
- myfile 0x5040e4f8 {_ptr=0x00000000 <Bad Ptr> _cnt=0 _base=0x00000000 <Bad Ptr> ...} _iobuf *
- _ptr 0x00000000 <Bad Ptr> char *
CXX0030: Error: expression cannot be evaluated
_cnt 0 int
- _base 0x00000000 <Bad Ptr> char *
CXX0030: Error: expression cannot be evaluated
_flag 2 int
_file 3 int
_charbuf 0 int
_bufsiz 0 int
- _tmpfname 0x00000000 <Bad Ptr> char *
CXX0030: Error: expression cannot be evaluated

Is what the watch tells me about myfile immediately after fopen is called when it WORKS.


- myfile 0x5040e4f8 {_ptr=0x00000000 <Bad Ptr> _cnt=0 _base=0x00000000 <Bad Ptr> ...} _iobuf *
- _ptr 0x00000000 <Bad Ptr> char *
-51 'Í' char
_cnt 0 int
- _base 0x00000000 <Bad Ptr> char *
66 'B' char
_flag 2 int
_file 3 int
_charbuf 0 int
_bufsiz 4096 int
- _tmpfname 0x00000000 <Bad Ptr> char *
CXX0030: Error: expression cannot be evaluated

Is what it looks like immediately after fopen is called and it doesn't work.

Will edit this with more info shortly (looking up errno)

EDIT:
so i included errno.h and added
char * errorMessage = strerror( errno );
after a fopen call, and unless there is more to it than that, errorMessage is showing "NoError"

EDIT:
so i included errno.h and added
char * errorMessage = strerror( errno );
after a fopen call, and unless there is more to it than that, errorMessage is showing "NoError"


I have no idea, I am sorry :/
Oi, thanks for trying anyway, I know that a lot of code to even consider looking at.

This topic is closed to new replies.

Advertisement