Program starting with windows error

Started by
2 comments, last by NoLoGiC 19 years, 12 months ago
Hey everyone! I have a program which starts with windows, and upon startup is supposed to read a config file and take action depending on what is in there. The crazy thing that is happening is upon windows startup, my program runs, but the input from the file it receives seems to be garbage. When I run the program manually, it reads the config file without problem. Windows''s registry key points to the same executable, and my error checking would let me know if the file weren''t accessable. Anyone run into any similar problems? Thanks for reading this, NoLoGiC
Advertisement
I encountered something similar a while back on a project, it would compile and run fine in debug mode (vb interpreter) but would crash in release mode. It turned out to be a leak from going past the end of a lump of allocated memory.

Not sure if that''s any help, but....

Jay
Maybe it has something to do with your working directory; when you run the program from within your IDE, it doesn''t set it appropriately, and is loading the wrong file.
Posting this in case it benefits anyone else running into similar problems:

My windows program would edit the registry and add itself to the list of items to run at startup (its an organizer, nothing malicious )

When the program was run manually, it would find its config in the same path as the executable and life was good. Knowing it ran this way, I used dataFile = fopen("configFileName", "r") to access it.

However, when windows ran it at startup, it wouldn''t read the config file. It turns out that the working path in this case wasn''t the same as the executable, but Drive:\Documents and Settings\user .

To remedy the problem, I use GetModuleFileName to get the path and filename of the executable, PathRemoveFileSpec to remove the executable filename, and strcat to add my config filename to it.

While there is probably an easier way, it works beautifully now!

Hope this helps anyone who runs into a similar problem,
NoLoGiC

This topic is closed to new replies.

Advertisement