   KillGLWindow Failing
  Hi, I was wondering what could cause the below, specifically, the unregister function to fail.   GLvoid KillGLWindow(GLvoid){if (hRC){if (!wglMakeCurrent(NULL,NULL)){MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);}if (!wglDeleteContext(hRC)){MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);}hRC=NULL;}if (hDC && !ReleaseDC(hwnd,hDC)){MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);hDC=NULL;}if (hwnd  && !DestroyWindow(hwnd)){MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);hwnd=NULL;}if (!UnregisterClass("OpenGL",hInstance)){MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);hInstance=NULL;}}I am implementing it like this:case WM_DESTROY:{PostQuitMessage(0);    KillGLWindow(); }break;  Everytime I run the program and exit it, it returns with the messagebox "Could Not Unregister Class".  I''ve tried moving code around and commenting out the PostQuitMessage but it does not seem to work and plus it is giving me a very big memory leak.Thanks. 
  This is probably not the solution but...I used to get errors like that when I did not have a corresponding glEnd for all my glBegins.  But when It happened to me, it could not unregiseter the DC and RC along with your problem. ;  Thanks for the reply, but it seems that all begin/end functions are accounted for.  I tried localizing the problem step by step and it seems there is something definatly wrong with my program.I got this far: BOOL CreateGLWindow(char* title, int width, int height, int bits){GLuintPixelFormat;WNDCLASSwc;DWORDdwExStyle;DWORDdwStyle;RECTWindowRect;WindowRect.left=(long)0;WindowRect.right=(long)width;WindowRect.top=(long)0;WindowRect.bottom=(long)height;hInstance= GetModuleHandle(NULL);wc.style= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;wc.lpfnWndProc= (WNDPROC) WndProc;wc.cbClsExtra= 0;wc.cbWndExtra= 0;wc.hInstance= hInstance;wc.hIcon= LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));wc.hCursor= (HCURSOR)LoadImage(hInstance,MAKEINTRESOURCE(IDC_POINTER), IMAGE_CURSOR,0,0,LR_DEFAULTSIZE);wc.hbrBackground= NULL;wc.lpszMenuName= MAKEINTRESOURCE(IDR_MYMENU);wc.lpszClassName= "OpenGL";if (!RegisterClass(&wc)){MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);return FALSE;}if (!UnregisterClass("OpenGL",hInstance)){MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);hInstance=NULL;}...Notice that I have placed the UnregisterClass command right after the class is registered to see if there is something wrong.  Once I execute the program, it throws the "Could Not Unregister Class." dialogbox at me.  How could it just register the class and not register it a millisecond later?  There are no functions inbetween that could mess with the atom, and the handle to the Instance is perfectly good (not NULL).  I just don''t know what to do right now, the program is about 6.32k lines long and I guess the only thing is to scrap it or else try and do something else but I''m all out of ideas.In case you''re wondering, here is the WinMain function up till I called the creation of the opengl window: int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){MSGmsg;BOOLdone=FALSE;    char double_buff[100]={0};    GetModuleFileName(hInstance,path_name,1000);//Assign the location of the "Klash of Magic.ini" file    char *place=strstr(path_name,"Klash of Magic.exe");    strcpy(place,"Klash of Magic.ini");    strcpy(ini_path,path_name);//Assign the location of the "spells.dat" file    strcpy(place,"Data\\Spells.dat");    strcpy(spells_path,path_name);//Assign the location of the "units.dat" file    strcpy(place,"Data\\Units.dat");    strcpy(units_path,path_name);//Assign the location of the "objects.dat" file    strcpy(place,"Data\\Objects.dat");    strcpy(objects_path,path_name);//Begin Accessing and checking of external data files    option_SHOW_SPLASH=GetPrivateProfileInt("Game","SHOW_SPLASH",1,ini_path);    if(option_SHOW_SPLASH)    {    splash = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_SPLASH),  hwnd,(DLGPROC)Splash_Dialog);    }    char path_storage[4][1000];    strcpy(path_storage[0],ini_path);    strcpy(path_storage[1],spells_path);    strcpy(path_storage[2],units_path);    strcpy(path_storage[3],objects_path);    for(loop=0; loop < 4; loop++)    {   strcpy(path_name,path_storage[loop]);   GetPrivateProfileString("system","version_com","N/A",double_buff,1000,path_name);   if(!strcmp(double_buff,"N/A"))   { char error_elucidate[1500]; LoadString(hInstance,ID_STRING_DATA_LOADFIND,error_elucidate,1500); strcat(error_elucidate,path_storage[loop]); MessageBox(hwnd,error_elucidate, "File Error",MB_OK | MB_ICONEXCLAMATION); return FALSE;   }   if(atof(double_buff) != version)   { char error_elucidate[1500]; LoadString(hInstance,ID_STRING_DATA_ASK,error_elucidate,1500); strcat(error_elucidate,path_storage[loop]); if(MessageBox(hwnd,error_elucidate,"Version Difference Warning!", MB_YESNO | MB_ICONEXCLAMATION | MB_DEFBUTTON2 | MB_APPLMODAL) == IDNO) {    return FALSE; }   }    }if (!CreateGLWindow("Klash of Magic",640,480,16)){return 0;}Also, I''ve already tried commenting out the file checking and creation of the splashscreen, but it is still the same result. ;  Try passing the ATOM returned by RegisterClass() to UnregisterClass() in the first paramter (instead of the class name). Also try using GetLastError() to get some help on what''s wrong.   "In the middle of difficulty lies opportunity"  - Albert Einstein ;  Thanks for the suggestion, the ATOM passing failed the same way as passing the class name but I did find something out.if (!RegisterClass(&wc)){MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);return FALSE;}char storage[100]={0};if(!GetClassName(hwnd,storage,100)){ MessageBox(hwnd,"GetClassName FAILED!","#@!$",MB_OK);}MessageBox(hwnd,storage,"TEST",MB_OK);  I implemented these new lines of code in and the GetClassName function failed.  The array that ws suppose to contain the name of the class had nothing in there so I am guessing there must be something else wrong.  But what?  I tried transcripting code from NeHe''s tutorials into my game, but the errors are nevertheless the same.  There must be something else that is affecting the program, but nothing should affect it this early.  Especially after the registering of a classname and the termination of it right afterward.  I tried rebuilding my project and such but I still get the same answer.  Oh yea, the error returned was that the first argument was invalid. ;  The name of the class have to be different from other classes already registered,and maybe u have the classname in CreateGLWindow() different of KillGLWindow() i think...sorry about my english   _,,,^Ó..ò^,,,_ ;  Thanks for the suggestion.  I''ve doubled-checked and the names do indeed match along with their cases and I have also cheanged the class name to something else but the same error is thrown at me.  I guess my last resort is to create a skeletal window opengl program and slowly transcript and test each portion of my code along with the skeletal one until an answer can be found.  I guess this is one of those things that seperate the determined from the ill-prepared. Naturally if I find the problem I''ll post the malicious part that was responsible for it in the first place on the forum. 