Please Help With C DLL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew Hanna

    Please Help With C DLL

    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(dlle xport)
    #else
    #define GLFOGCOORDF_VB_ API __declspec(dlli mport)
    #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.l ib" )

    typedef void (APIENTRY * PFNGLFOGCOORDFE XTPROC) (GLfloat coord); // Declare
    Function Prototype
    PFNGLFOGCOORDFE XTPROC 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=(ch ar *)malloc(strlen ((char
    *)glGetString(G L_EXTENSIONS))+ 1);

    MessageBox(NULL , "Checkpoint 2", "Message", MB_OK);
    strcpy (glextstring,(c har *)glGetString(G L_EXTENSIONS)); // Grab The
    Extension List, Store In glextstring

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

    free(glextstrin g); // Free Allocated Memory

    // Setup And Enable glFogCoordEXT
    glFogCoordfEXT_ func = (PFNGLFOGCOORDF EXTPROC)
    wglGetProcAddre ss("glFogCoordf EXT");

    return TRUE;
    }


    BOOL APIENTRY DllMain( HANDLE hModule,
    DWORD ul_reason_for_c all,
    LPVOID lpReserved
    )
    {
    switch (ul_reason_for_ call)
    {
    case DLL_PROCESS_ATT ACH:
    /* if (!Extension_Ini t()) {
    return FALSE;
    }
    */
    case DLL_PROCESS_DET ACH:
    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)f Coord);
    }
    }



    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


  • Thomas Matthews

    #2
    Re: Please Help With C DLL

    Matthew Hanna wrote:[color=blue]
    > 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...[/color]
    [snip]
    [color=blue]
    > Thanks!
    > Matthew Hanna
    >[/color]

    You need help from the experts in a Microsoft newsgroup.
    This newsgroup, news:comp.lang. c++, 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:

    C++ Faq: http://www.parashift.com/c++-faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.l earn.c-c++ faq:

    Other sites:
    http://www.josuttis.com -- C++ STL Library book

    Comment

    Working...