May 01, 2024, 12:38:46 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


FileRequest crash

Started by SMartin, February 12, 2007, 08:46:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SMartin

I'm crashing my program when I call FileRequest and I'm not sure why.
I copied the line over into the Editor example program and it works fine there. (the only change was the 'This' pointer which I changed to 'win', matching the example in the Editor.src)

I searched the forum and grabbed as many examples of FileRequest as I could find. They all produced a crash at this particular procedure in my code.

Here is the current version of the procedure that calls the FileRequest and also a copy of the Call Stack after the crash.

MidiLog::cmdWatchChannelsLoad_Click()
{
   WatchLog = FileRequest("Open log file",This,1,"Text files|*.txt|All Files|*.*||","");
   
}

Call stack:
kernel32! RaiseException + 82
RPCRT4! RpcRaiseException + 52
RPCRT4! RpcRaiseException + 807
RPCRT4! NdrClientCall2 + 315
NETAPI32! NetShareEnum + 239
NETAPI32! NetShareEnum + 104
ntshrui! GetNetResourceFromLocalPathW + 3978
ntshrui! GetNetResourceFromLocalPathW + 3916
ntshrui! GetNetResourceFromLocalPathW + 3866
ntshrui! GetNetResourceFromLocalPathW + 4390
ntshrui! IsPathSharedW + 26
SHELL32! IsNetDrive + 1538
SHELL32! SHCloneSpecialIDList + 18615
COMDLG32! GetOpenFileNameA + 2998
COMDLG32! GetOpenFileNameA + 32651
COMDLG32! GetOpenFileNameA + 1698
COMDLG32! GetOpenFileNameA + 1370
USER32! GetDC + 109
USER32! DefDlgProcW + 1026
USER32! PrivateExtractIconExW + 254
USER32! DefDlgProcW + 34
USER32! GetDC + 109
USER32! GetDC + 335
USER32! GetParent + 364
USER32! GetWindowTextLengthW + 1351
USER32! DrawStateW + 479
USER32! DialogBoxIndirectParamAorW + 54
USER32! DialogBoxIndirectParamW + 27
COMDLG32! GetOpenFileNameA + 1216
COMDLG32! GetOpenFileNameA + 711
COMDLG32! GetOpenFileNameA + 670
COMDLG32! GetOpenFileNameA + 280
COMDLG32! GetOpenFileNameA + 28
MidiLogger! FILEREQUEST + 1130
MidiLogger! MidiLog@cmdWatchChannelsLoad_Click + 62 File: C:\Documents and Settings\Steve\My Documents\AuroraProjects\MidiLogger\MidiLogger.src, Line: 83
MidiLogger! MidiLog@OnControl + 214 File: C:\Documents and Settings\Steve\My Documents\AuroraProjects\MidiLogger\MidiLogger.src, Line: 711
MidiLogger! CWindow@OnCommand + 108
MidiLogger! CWindow@WndProc + 1064
MidiLogger! CWindow@Destroy + 1956
USER32! GetDC + 109
USER32! GetDC + 335
USER32! GetParent + 364
USER32! SendMessageW + 73
USER32! CreateMDIWindowA + 445
USER32! DeregisterShellHookWindow + 25168
USER32! GetCursorFrameInfo + 4453
USER32! SoftModalMessageBox + 3491
USER32! GetDC + 109
USER32! GetDC + 335
USER32! IsWindowUnicode + 161

Any advice?
Steve...

Ionic Wind Support Team

MidiLog is derived from what?   FileRequest is expecting a CWindow derived class pointer for the parent parameter.  The 'this' pointer is the instance of the class the method is from.

Ionic Wind Support Team

SMartin

Paul,

MidiLog is subclassed CWindow

Class MidiLog : CWindow
{
  // bunch-o-class stuff
}

Here's the sub main

Int Run=False;
MidiLog *frmMain;
   
Global Sub main
{
   frmMain=new(MidiLog,1);
   Run = frmMain->Create(0,0,WindowWidth,WindowHeight,AWS_MINIMIZEBOX|AWS_BORDER|AWS_CENTERED|AWS_SYSMENU|AWS_CAPTION|AWS_VISIBLE,0,"Midi Logger",NULL);
   If (Run==True)
   {
      Do { Wait(); } Until !frmMain->IsValid();
   }
   Else
   {
      MessageBox(Null,"Unable to create Window.","Window Creation Error");
   }
   
}

Ionic Wind Support Team

Still not enough to go on.  I don't see anything wrong so far.  Where is cmdWatchChannelsLoad_Click being called from?  A button I suppose?



Ionic Wind Support Team

SMartin

Yes.

It's called from a Select/Case in the OnControl method in the MidiLog class.

I added some code to another button (a Save As) and crashed the program from the file request there also.
I'm obviously doing something very wrong somewhere in my class implementation.

I've included a zip of the project.

Steve...

Ionic Wind Support Team

I will look further tomorrow.  Going to bed now.
Ionic Wind Support Team

Ionic Wind Support Team

Just a quick note though...  You are leaking memory in many places.  Whenever you use NEW you must use DELETE to free the object created.  For example in your OnCreate handler you have this:

   CIcon *MLIcon=New(CIcon,1);
   MLIcon->LoadFromFile(GetStartPath()+"MidiLogger.ico");
   SetIcon(MLIcon->Detach());

But no DELETE MLIcon anywhere so that will be a leak.  Better to code it like this (statically):

   CIcon MLIcon;
   MLIcon.LoadFromFile(GetStartPath()+"MidiLogger.ico");
   SetIcon(MLIcon.Detach());

Which creates it on the stack and then you don't need to worry about freeing it.  Same thing with the main midiLog class.

Paul.
Ionic Wind Support Team

sapero

Exceptions are a part of the program, and the internal api's used in FileRequest are using them to easy exit a function or change program flow.
Remember the __try and __throw? After try you can call any recursive function, where single exception can cancel all the calls, the stact would be cleaned by single command, instead return'ing n-times.
You should just ignore all unknown memory exceptions in kernel32 and this one generated by FileRequest.
While debugging you catch all exceptions - the system teels first to your debugger, then to your program, but without debugger only unhandled exceptions are 'visible'.

SMartin

Thanks for the replies,

I'll tighten up my code, and coding style, before going any further.

Steve...

SMartin

I cleaned up the memory leaks.

FileRequest is working.

I'm still working on getting into the Aurora mindset....

Thanks for the help, I'll try not to waste any more of your time.

Steve....

Ionic Wind Support Team

Not a waste of my time, that is what we are here for.  It's not like I was busy coming up with a solution to world peace or anything ;)
Ionic Wind Support Team