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
");
infoFunc = (InfoFunc)GetProcAddress(dll, “getInfo”);
if(infoFunc != NULL)
{
printf(“success GetProcAddress
“);
printf(” OUTPUT:
%s”, infoFunc());
if(FreeLibrary(dll))
{
printf("success FreeLibrary
");
}
else
{
printf("error FreeLibrary
");
}
}
else
{
printf("error GetProcAddress
");
}
}
else
{
printf("error LoadLibrary
");
}
}
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, "
VENDOR[");
strcat(info, (char *)glGetString(GL_VENDOR));
strcat(info, “]
RENDERER[”);
strcat(info, (char *)glGetString(GL_RENDERER));
strcat(info, "]
");
if(hRC){
if(wglMakeCurrent(NULL, NULL)){
if(wglDeleteContext(hRC)){
hRC=NULL;
if(hDC && !ReleaseDC(hWnd, hDC)){
printf("error ReleaseDC
");
hDC=NULL;
}
} else { printf("error wglDeleteContext
");}
} else { printf("error wglMakeCurrent(NULL, NULL)
");}
} else { printf("error hRC
");}
} else { printf("error wglMakeCurrent
");}
} else { printf("error wglCreateContext
");}
} else { printf("error SetPixelFormat
");}
} else { printf("error ChoosePixelFormat
");}
} else { printf("error GetDC
");}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