so i have this dll with a DBTProc, whenever a window gets created i want to write something in a log file. Now everytime I run it it adds three times the
text in this log file, but then it does nothing anymore. I do hear a beep everytime a window get created so it doesn't actually open my file to write in, any ideas about what's wrong?

code:
LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam)
{
if (code < 0)
{
return CallNextHookEx(CBThook, code, wParam, lParam);
}

hWndnew = (HWND)wParam;
if (code == HCBT_CREATEWND)
{
CREATESTRUCTA* cswnd = (CREATESTRUCTA*) lParam;
cswnd-> y = 0;
cswnd-> x = 0;
cswnd -> cx = 500;
cswnd -> cy = 400;
lParam = (LPARAM) cswnd;
FILE * logfile;

if((logfile=fopen("logfile.LOG","a")) != NULL)
{
fprintf(logfile, "hoi\n");
fclose(logfile);
}
else{
Beep(2000, 20);
}
}