Advertisement

glGetString(GL_VENDOR)..

Started by September 21, 2002 03:26 AM
-1 comments, last by soreno 22 years, 5 months ago
i have a problem creating a dll that should return GL_VENDOR and GL_RENDERER as a const char. I suspect that I do not release ressources correctly but I'm unable to spot the error - could you help ? mainTest
  
#include <windows.h>
#include <stdio.h>

void getInfo();
typedef const char* (* InfoFunc)();

int main(int argc, char **argv)
{
   getInfo();
   getInfo();  

   return 0;
}

void getInfo()
{
   HINSTANCE dll;
   InfoFunc infoFunc;
   
   dll=LoadLibrary("Info.dll");
   if(dll != NULL)
   {
	  printf("*success* LoadLibrary\n");
	  infoFunc = (InfoFunc)GetProcAddress(dll, "getInfo");
	  if(infoFunc != NULL)
	  {
		 printf("*success* GetProcAddress\n");
		 printf("\tOUTPUT:\n%s", infoFunc());
		 if(FreeLibrary(dll))
		 {
			printf("*success* FreeLibrary\n");
		 }
		 else
		 {
			printf("*error* FreeLibrary\n");
		 }
	  }
	  else
	  {
		 printf("*error* GetProcAddress\n");
	  }
   }
   else
   {
	  printf("*error* LoadLibrary\n");
   }
}
  
dllInfo
  
#include <windows.h>
#include <GL/GL.h>
#include <string.h>
#include <stdio.h>

extern "C" const char* getInfo();

int WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
  return false;
}
 
__declspec ( dllexport) const char* getInfo()
{
   GLuint PixelFormat;
   HWND hWnd = NULL;
   HDC hDC = NULL;
   HGLRC hRC = NULL;
   char info[1024] = "";

   if(hDC=GetDC(hWnd)){
	  static PIXELFORMATDESCRIPTOR pfd= { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0};
	  if(PixelFormat=ChoosePixelFormat(hDC, &pfd)){
		 if(SetPixelFormat(hDC, PixelFormat, &pfd)){
			if(hRC=wglCreateContext(hDC)){
			   if(wglMakeCurrent(hDC, hRC)){
				  strcpy(info, "\n\tVENDOR[");
				  strcat(info, (char *)glGetString(GL_VENDOR));
				  strcat(info, "]\n\tRENDERER[");
				  strcat(info, (char *)glGetString(GL_RENDERER));
				  strcat(info, "]\n");
				  if(hRC){
					 if(wglMakeCurrent(NULL, NULL)){
						if(wglDeleteContext(hRC)){
						   hRC=NULL;
						   if(hDC && !ReleaseDC(hWnd, hDC)){
							  printf("*error* ReleaseDC\n");
							  hDC=NULL;
						   }
						} else { printf("*error* wglDeleteContext\n");}
					 } else { printf("*error* wglMakeCurrent(NULL, NULL)\n");}
				  } else { printf("*error* hRC\n");}
			   } else { printf("*error* wglMakeCurrent\n");}
			} else { printf("*error* wglCreateContext\n");}
		 } else { printf("*error* SetPixelFormat\n");}
	  } else { printf("*error* ChoosePixelFormat\n");}
   } else { printf("*error* GetDC\n");}

   return info;
}
  
output is: *success* LoadLibrary *success* GetProcAddress OUTPUT: VENDOR[NVIDIA Corporation] RENDERER[GeForce2 MX/PCI/3DNOW!] *success* FreeLibrary *success* LoadLibrary *success* GetProcAddress *error* SetPixelFormat OUTPUT: *success* FreeLibrary mvh Søren Olesen [edited by - soreno on September 21, 2002 4:28:25 AM]

This topic is closed to new replies.

Advertisement