Date: Sun, 23 Nov 1997 18:28:36 -0800 (PST) Message-Id: <199711240228.SAA02753@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: eggbrains AT aol DOT com (Egg brains), djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: computer freezes when i try to get a mouse event using 0x33 ax=0c Precedence: bulk At 12:05 11/22/1997 GMT, Egg brains wrote: >okay, a few days ago i posted a message here. i got all the answers i needed >(thanks) and no errors were genertated while it was compiling (so far so good) >then when i ran it and clicked my left mouse button (the event I am trying to >trap)... it generated and annoying win95 error and quit. i tried running it in >dos and it froze all thogether. > >i think this is because i am setting a bad vector so that the mouse calls a bad >reference on the event.... am i right? and does anyone know why this is >occuring? Close. See two comments below. > > >---- CODE SNIPPET ---- > >#include >#include >#include >static __dpmi_regs callback_regs; >static _go32_dpmi_seginfo callback_info; > >void happySub(__dpmi_regs *) >{ > cout << "abc!!!"; You CANNOT call libc/libstdc++ functions that might call DOS from a hardware interrupt handler, because DOS is not reentrant. If the user clicked the mouse while a DOS function was executing, the effects could be disastrous. Use something that doesn't call DOS, perhaps `cprintf'. > return; >} > >long initMouse(unsigned mask, void (*func)(__dpmi_regs *)) >{ > __dpmi_regs r; > > callback_info.pm_offset = (long)func; > if >(_go32_dpmi_allocate_real_mode_callback_retf(&callback_info,&callback_regs)) > return -1; /* failure */ > > r.x.ax = 0xC; > r.x.cx = mask; You need to tell the mouse driver the address of your handler. It doesn't know it by magic. :) Add these lines: r.x.es = callback_info.rm_segment; r.x.dx = callback_info.rm_offset; > __dpmi_int (0x33, &r); > > return (r.x.flags & 1) ? -1 : 0; >} > >void main() >{ > char *dummy; > cout << "mouse demo"; > initMouse(0x01, happySub); > > for(long i; i>0; i++){ > cout << i << endl; > } > > cin >> dummy; >} >----END CODE SNIPPET---- Hope this helps. Nate Eldredge eldredge AT ap DOT net