Please Help With C DLL

M

Matthew Hanna

I am writing a short OpenGL application in Visual Basic. I need an
extension that I can't get from the VB side. I create a dll named
glFogCoordf_Vb.dll to do the work for me. The dll fails to see the OpenGL
commands. I am at a loss as to how this can be fixed. Any ideas on how to
fix the problem? The dll is being created in MS Visual C/C++ 6.0 using the
Win32 Dynamic-Link Library Wizard. My code is as follows...

-- glFogCoordf_vb.def --
LIBRARY glFogCoordf_vb

DESCRIPTION 'Volume Fog OpenGL Extension'

EXPORTS
glFogCoordfEXT

-- glFogCoordf_vb.h --
#ifdef GLFOGCOORDF_VB_EXPORTS
#define GLFOGCOORDF_VB_API __declspec(dllexport)
#else
#define GLFOGCOORDF_VB_API __declspec(dllimport)
#endif

GLFOGCOORDF_VB_API void APIENTRY glFogCoordfEXT(const float fCoord);

-- glFogCoordf_vb.cpp --
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows
headers

#include <windows.h>
#include <olectl.h>
#include <gl\gl.h>
#include "glFogCoordf_vb.h"

#pragma comment( lib, "opengl32.lib" )

typedef void (APIENTRY * PFNGLFOGCOORDFEXTPROC) (GLfloat coord); // Declare
Function Prototype
PFNGLFOGCOORDFEXTPROC glFogCoordfEXT_func = NULL; // Our glFogCoordfEXT
Function

int Extension_Init()
{
char Extension_Name[] = "EXT_fog_coord";

MessageBox(NULL, "Checkpoint 1", "Message", MB_OK);

// Allocate Memory For Our Extension String
char* glextstring=(char *)malloc(strlen((char
*)glGetString(GL_EXTENSIONS))+1);

MessageBox(NULL, "Checkpoint 2", "Message", MB_OK);
strcpy (glextstring,(char *)glGetString(GL_EXTENSIONS)); // Grab The
Extension List, Store In glextstring

MessageBox(NULL, glextstring, "Extensions", MB_OK);
if (!strstr(glextstring,Extension_Name)) // Check To See If The
Extension Is Supported
return FALSE; // If Not, Return FALSE

free(glextstring); // Free Allocated Memory

// Setup And Enable glFogCoordEXT
glFogCoordfEXT_func = (PFNGLFOGCOORDFEXTPROC)
wglGetProcAddress("glFogCoordfEXT");

return TRUE;
}


BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
/* if (!Extension_Init()) {
return FALSE;
}
*/
case DLL_PROCESS_DETACH:
glFogCoordfEXT_func = NULL;
break;
}
return TRUE;
}

GLFOGCOORDF_VB_API void APIENTRY glFogCoordfEXT(const float fCoord)
{
if (glFogCoordfEXT_func == NULL) {
Extension_Init();
}

if (glFogCoordfEXT_func != NULL) {
glFogCoordfEXT_func((GLfloat)fCoord);
}
}



I get past Checkpoint 1 but the dll bombs on glGetString which I assume
means that the function isn't there. I have tried stepping through the code
during debug and it goes straight to strlen and complains about an invalid
memory address. This code was taken from a C application I wrote and it
works fine there. The OpenGL in the VB application works fine as well; as
long as I don't let it execute the call to the dll. Any help would be
greatly appreciated.

Thanks!
Matthew Hanna
 
T

Thomas Matthews

Matthew said:
I am writing a short OpenGL application in Visual Basic. I need an
extension that I can't get from the VB side. I create a dll named
glFogCoordf_Vb.dll to do the work for me. The dll fails to see the OpenGL
commands. I am at a loss as to how this can be fixed. Any ideas on how to
fix the problem? The dll is being created in MS Visual C/C++ 6.0 using the
Win32 Dynamic-Link Library Wizard. My code is as follows... [snip]

Thanks!
Matthew Hanna

You need help from the experts in a Microsoft newsgroup.
This newsgroup, only discusses the _standard_
C++ language which has no facilities for DLLs or OpenGL.

See the FAQ and welcome.txt links below.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top