[comp.windows.ms] Getting simple debug output

wytten@cs.umn.edu (Dale Wyttenbach) (08/04/90)

I'm a experienced X11 programmer trying to write my first MSW
program, and having a difficult time getting simple debug
output from my program.  (I'm trying to avoid learning yet
another debugger)

Right now I'm just opening a file called debug.txt and writing
stuff into that, but I'd like to have a quickie function that
pops up a dialog box with a message, sort of like this:

sprintf(buf,"a= %d, b=%d",a,b);
debugwin(buf);

I would like to do this with a dialog box, but I don't know if you can
pass the buf in since dialog boxes are defined in the .rc file.
(Remember I'm brand new at this) Does anyone have something like this
they would share?  Any better ideas?  "debug" doesn't appear in the
index of any of the manuals we got with the SDK.

Thanks,

Dale Wyttenbach
wytten@cs.umn.edu

mojo@netcom.UUCP (Morris Jones) (08/04/90)

There is a debug facility provided which (I'm told) is part of the WDEB386
debugger, but I've found that it works whether the debugger is loaded or
not.

	OutputDebugString(LPSTR msg);

writes "msg" to COM1:.  I keep a serial terminal on COM1 for use with
WDEB386, so it's a very convenient API.  I've never seen the documentation
for this function either, only read about it on the MSWIN forum on
CompuServe.  But I've been using it successfully.

Mojo

-- 
mojo@netcom.UUCP          Site Coordinating Instructor, San Jose South
Morris "Mojo" Jones       Skilled Motorcycling And Rider Training (S.M.A.R.T.)
Campbell, CA              800-675-5559 ... 800-CC-RIDER

bcw@rti.rti.org (Bruce Wright) (08/05/90)

In article <1990Aug3.184951.5599@cs.umn.edu>, wytten@cs.umn.edu (Dale Wyttenbach) writes:
> I'm a experienced X11 programmer trying to write my first MSW
> program, and having a difficult time getting simple debug
> output from my program.  (I'm trying to avoid learning yet
> another debugger)
> 
> Right now I'm just opening a file called debug.txt and writing
> stuff into that, but I'd like to have a quickie function that
> pops up a dialog box with a message, sort of like this:
> 
> sprintf(buf,"a= %d, b=%d",a,b);
> debugwin(buf);
> 
> I would like to do this with a dialog box, but I don't know if you can
> pass the buf in since dialog boxes are defined in the .rc file.

The simplest way to get an error message into a dialog box is with
the MessageBox function - this puts up a small dialog box and a
message without requiring that you define the dialog box in the .rc
file.  Typical syntax is:

	MessageBox (hWnd, szBuffer, szAppName,
			MB_OK | MB_ICONEXCLAMATION);

(for example).  Note that you can get more pushbuttons by using 
somewhat different flags:  for example, MB_OKCANCEL has both an
OK and a Cancel pushbutton, and the function returns which button
was pushed.

One simple but useful function in many cases is one to check the 
range of a value and pop up a message box if it's out of range:

BOOL CheckRange (hWnd, iValue, iLow, iHigh, szMessage)
	HWND	hWnd;
	short	iValue, iLow, iHigh;
	char	*szMessage;
	{
	char	szBuffer [80];

	if ((iValue < iLow) || (iValue > iHigh))
		{
		wsprintf (szBuffer, szMessage, iValue);
		MessageBox (hWnd, szBuffer, szAppName,
				MB_OK | MB_ICONEXCLAMATION);
		return TRUE;
		}
	return FALSE;
	}

(This will only work on Windows 3.0 because wsprintf doesn't exist
in Windows 2.0, but you should be able to substitute sprintf - it
just takes more space.  szAppName is just a string with the name of 
the application and is put in the message box caption).

The main problem with this technique is that if you need a lot of
information (like writing out a lot of values in the message box or
you want to see previous error messages as well), it gets sort of 
cumbersome.

						Bruce C. Wright

goodearl@world.std.com (Robert D Goodearl) (08/06/90)

In article <11364@netcom.UUCP> mojo@netcom.UUCP (Morris Jones) writes:
>There is a debug facility provided which (I'm told) is part of the WDEB386
>debugger, but I've found that it works whether the debugger is loaded or
>not.
>
>	OutputDebugString(LPSTR msg);
>
>writes "msg" to COM1:.

The documentation states that OutputDebugString() will send its output to the
debugger (CodeView or WDEB386) if present, or to the aux port.

Bob Goodearl -- goodearl@world.std.com

bob@antares.UUCP (Bob Paauwe) (08/07/90)

In article <1990Aug3.184951.5599@cs.umn.edu>, wytten@cs.umn.edu (Dale Wyttenbach) writes:
> Right now I'm just opening a file called debug.txt and writing
> stuff into that, but I'd like to have a quickie function that
> pops up a dialog box with a message, sort of like this:
> 
> sprintf(buf,"a= %d, b=%d",a,b);
> debugwin(buf);
> 
> Thanks,
> 
> Dale Wyttenbach
> wytten@cs.umn.edu

Look at the MessageBox function.  I think it will do exactly what 
you want.  My old SDK documentation says this:

  "This function creates and displays a window that contains an
  application supplied message and caption, plus any combination
  of the predefined icons and push buttons described in the 
  following list."

You can use this to display a window with a one line message and
and OK button.

Basicly replace your 'debugwin(buf);' with -
  MessageBox ( hWndParent, (LPSTR)buf, (LPSTR)"DEBUG", MB_OK );

-- 
Bob Paauwe                 ________________________    Any resemblence to a
bpaauwe@antares.intel.com              |      REAL opinion is unintentional.
/-----------------___________________/---\___________________-----------------\
!ames!pacbell!sactoh0!mcdre3!bpaauwe \___/      I'd rather be Gliding!!!!!

brianf@umd5.umd.edu (Brian Farmer) (08/08/90)

In article <1990Aug3.184951.5599@cs.umn.edu> wytten@cs.umn.edu (Dale Wyttenbach) writes:
>stuff into that, but I'd like to have a quickie function that
>pops up a dialog box with a message, sort of like this:
>
>sprintf(buf,"a= %d, b=%d",a,b);
>debugwin(buf);
>
>I would like to do this with a dialog box, but I don't know if you can
>pass the buf in since dialog boxes are defined in the .rc file.
>(Remember I'm brand new at this) Does anyone have something like this
>they would share?  Any better ideas?  "debug" doesn't appear in the
>index of any of the manuals we got with the SDK.
>


The May or June of 88 Microsoft Systems Journal has a very good Debug output
function.  Its basicly a printf type function but with a mask parameter so
you could only display certain Debugs or all if you wanted, 30 different masks
are available.  They appear in in small dialog box which can remember the last
200 or so.  Until Win3 and a Codeview which works on my 80, I swore (and
cursed) by this helpful utility.
    The one problem with this box is you must be able to start your
program in order you use it, you have to be able to get to your windows 
system menu.  Early output I have to do thru a MessageBox.  Since source could 
was included all limitations could changed.


Brian Farmer
brianf@umd5.umd.edu

bdlepla@caen.engin.umich.edu (Bryan Dennis Lepla) (09/04/90)

In article <1990Aug3.184951.5599@cs.umn.edu>, wytten@cs.umn.edu (Dale Wyttenbach) writes:
> I'm a experienced X11 programmer trying to write my first MSW
> program, and having a difficult time getting simple debug
> output from my program.  (I'm trying to avoid learning yet
> another debugger)
> 
> Right now I'm just opening a file called debug.txt and writing
> stuff into that, but I'd like to have a quickie function that
> pops up a dialog box with a message, sort of like this:
> 
> sprintf(buf,"a= %d, b=%d",a,b);
> debugwin(buf);
> 
> I would like to do this with a dialog box, but I don't know if you can
> pass the buf in since dialog boxes are defined in the .rc file.
> (Remember I'm brand new at this) Does anyone have something like this
> they would share?  Any better ideas?  "debug" doesn't appear in the
> index of any of the manuals we got with the SDK.
> 
> Thanks,
> 
> Dale Wyttenbach
> wytten@cs.umn.edu

Dale, you're on the right track.  Use MessageBox instead.

MessageBox(hWnd, buf, "Caption",MB_OK);

where hWnd is the handle to the window that creates this message box.
It will create a box with your message and will wait until you hit return.

I got this straight out of Petzold's book _Programming Windows_.  I highly 
recommend it.  (Or wait a couple months for his 3.0 update.)