Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - Useful programming resources | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 6941/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 09-09-05 06:25 AM Link | Quote
I thought it might be a good idea to make a thread for useful programming-related notes and code that can be used in various applications. So I did.

The most useful website you will ever find for programming in Windows is the official Windows developer documentation - MSDN (the Microsoft Developers Network). It's free and contains information on every API function, control, constant and structure. The page linked here contains information about each type of control; I've bookmarked it here since it's quite useful. To look up API functions, constants or structures, just type their name (case insensitive) in the search box; the info will usually be the second or third result on the page and looks something like Beep(DWORD,DWORD) function [Base]. (Don't bother typing in things that aren't a name; it won't get you anywhere. )
Here's another useful MSDN link - API functions in alphabetical order.

For Visual Basic programmers, AllAPI lists VB6 implementations of nearly every API function. Make sure you have a good ad-blocker, though. Popup and flash blocking is recommended.

If you develop for the Gameboy or GBA, be it programming them or emulating them, you'll find these specifications very useful:
Gameboy
GBA
For DS developers, DSLinux and the DS Tech Wiki can offer some useful information.

If you use PHP, you only need to know one website: PHP.net.

C programmers should find some good use for this function I made:
/*
Prints debug output if enabled
Inputs:
-Level = Minimum debug level.
-Everything else = what to print
(works same as printf());
*/
void DebugOut(int Level, char* fmt, ...)
{
if((FileDebugLevel == DO_NONE) && (ConsoleDebugLevel == DO_NONE) && (MessageDebugLevel == DO_NONE)) return;
int e;
if(Level <= DO_ERR_THRESHOLD) e = GetLastError();
if(Level <= DO_ERR_THRESHOLD) GetErrorMessage(e,TempStr[7]);
if((FileDebugLevel > 0) && (!debugfile))
debugfile = fopen("debug.log","wt"); //Overwrite existing file in text mode
va_list list;
va_start(list, fmt);
if(ConsoleDebugLevel >= Level)
{
vprintf(fmt, list);
if(Level <= DO_ERR_THRESHOLD) printf("Error %d: %s",e,TempStr[7]);
}
if(FileDebugLevel >= Level)
{
vfprintf(debugfile, fmt, list);
if(Level <= DO_ERR_THRESHOLD) fprintf(debugfile,"Error %d: %s",e,TempStr[7]);
fflush(debugfile); //Force write immediately (in case of crash)
}
if(MessageDebugLevel >= Level)
{
char msg[1024];
vsprintf(msg, fmt, list);
MessageBox(NULL,msg,"Debug Message",MB_ICONINFORMATION);
}
va_end(list);
}


You'll need the following declarations:
//Debug output levels
#define DO_NONE 0 //No debug output
#define DO_CRITICAL 1 //Critical errors (system crash imminent!)
#define DO_MAJOR 2 //Major errors (uhoh)
#define DO_MINOR 3 //Minor errors (that doesn't seem right...)
#define DO_STATUS 4 //Status messages (loading...)
#define DO_ALL 5 //All messages
#define DO_ERR_THRESHOLD DO_MAJOR //Print error message from GetLastError() for levels this and below

#define GetErrorMessage(code, buf) FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,code,0,buf,sizeof(buf),NULL)

int ConsoleDebugLevel = 1000; //Console debug output level
int FileDebugLevel = 1000; //debug.log output level
int MessageDebugLevel = DO_MAJOR; //Message box output level
FILE* debugfile = 0; //debug.log


Set the ConsoleDebugLevel, FileDebugLevel and MessageDebugLevel to whatever output level you want. Any messages with that level or lower will be printed. ConsoleDebugLevel prints the message to the console (stdout). FileDebugLevel writes it into debug.log; this file is automatically created the first time a message is printed to it (overwriting any existing file) and flushed after each write to ensure that the text will be there if the program crashes. MessageDebugLevel displays the message in a popup message box (only recommended for critical errors; you don't want to get caught in a message box loop). Any message with a level equal to or less than DO_ERR_THRESHOLD will be followed by a message containing the error code and corresponding error message from GetLastError(). (This doesn't apply to message boxes, I should fix that sometime. )

The function works just like printf(), but you specify the output level before it, like so:
DebugOut(DO_CRITICAL,"Out of memory!");
DebugOut(DO_MINOR,"Warning: file pointer is past EOF\n");
DebugOut(DO_ALL,"Window handle #%d = 0x%08X\n",WindowID,hWnd);


Note that you need to add the '\n' to the end to create a line break. This is so you can print that a certain part of a small task has completed, and have the entire task's status on one line (like "Reading header... reading objects... reading sprites... done.") or whatever else you could do with printf(). Here's a trick I like to use:
DebugOut(DO_STATUS,"Doing something... ");
DebugOut(DO_ALL,"\n");
//Do stuff
DebugOut(DO_ALL,"Finished part 1\n");
//Do more stuff
DebugOut(DO_ALL,"Finished part 2\n");
//Do some more
DebugOut(DO_ALL,"Finished part 3\n");
DebugOut(DO_STATUS,"Done.\n");

This way, with DO_STATUS you'll just see "Doing something... Done.", while with DO_ALL you'll see more detailed information.

Also note that you need to manually close debugfile when the program ends, and don't use DebugOut() after that anymore or it'll open it again (unless your messages are a higher level than FileDebugLevel).

So feel free to post your own links and useful code snippets.
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - Useful programming resources | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.012 seconds.