views:

17

answers:

2

I'm attempting to run the following piece of code from an Out-of-Process COM Server in its main thread, however no file is ever created.

I wondered if anyone can tell me why this is?

FILE *f = fopen("Log.txt", "w");
fputs("Tony", f);
fputs("\n", f);
fclose(f);
A: 

I think the most likely cause is that fopen is failing with an access denied error. Have you tried stepping through the code? The best way to diagnose this is to attach a debugger and examine the value of errno.

Peter Ruderman
How could I debug it if it is out of proc? Is there an easy way??
Tony
@Tony -- use "Debug -> Attach to process". Select your server process as a target.
atzz
+2  A: 

Short from a permission problem, the odds are pretty good that the file actually got created but that you just can't find it back. You are not giving a full path name for the file (like "c:\\blah\\log.txt") which means that it will be created in the current working directory of the COM client app. Which is guaranteed to be not the same directory where your COM server is located.

You'll need to specify the full path. In Windows, that should be a directory that you have guaranteed write access to. Use SHGetFolderPath() to get the path to the appdata folder. Or set aside a fixed directory name for logging (not recommended).

Hans Passant