Looking for some help, problems with C++ Dlls (Using Visual Studio C++ 6.0)

Discussion in 'C++' started by Dave, Jan 24, 2007.

  1. Dave

    Dave Guest

    Hi everyone. Okay, I'm trying to dynamically link some dlls and I'm
    having some problems. I originally had a project that seems to work,
    but for the life of me I can't repeat the results.

    I used app wizard to create a simple Win32 Dynamic Linked library. the
    code is as follows:


    #include "stdafx.h"
    #include "stdio.h"

    int i = 0;

    BOOL APIENTRY DllMain( HANDLE hModule,
    DWORD ul_reason_for_call,
    LPVOID lpReserved
    )
    {
    return TRUE;
    }

    void _stdcall InitDll(){
    i = 1;
    }



    I build that and get 'TestDll.dll'

    The program I use to open this dll looks like this:


    #include "stdafx.h"
    #include <windows.h>


    typedef void(__stdcall *InitDllOperation)();


    int main(int argc, char* argv[])
    {

    InitDllOperation initDll;

    HINSTANCE dllLib = LoadLibrary("TestDll.dll");

    if( dllLib == NULL )
    {
    printf( "Unable to load library\n");
    return 1;
    }
    else
    {
    printf( "loaded library successfully\n");
    }

    initDll =
    (InitDllOperation)GetProcAddress((HINSTANCE)dllLib,"InitDll");

    if( initDll == NULL )
    {
    printf( "initDll failed to load\n");
    return 1;
    }
    else
    {
    printf( "init Success\n");
    }

    return 0;
    }


    Every time the library loads successfully, but the 'initDll' object is
    ALWAYS Null. The return from GetProcAddress seems to always come up
    null. Any suggestions?

    Thanks
     
    Dave, Jan 24, 2007
    #1
    1. Advertising

  2. Re: Looking for some help, problems with C++ Dlls (Using Visual StudioC++ 6.0)

    * Dave:
    > Hi everyone. Okay, I'm trying to dynamically link some dlls and I'm


    Well, that belongs in a Windows programming newsgroup, sorry.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Jan 24, 2007
    #2
    1. Advertising

  3. On Jan 23, 10:37 pm, "Dave" <> wrote:
    > Hi everyone. Okay, I'm trying to dynamically link some dlls and I'm
    > having some problems. I originally had a project that seems to work,
    > but for the life of me I can't repeat the results.
    >


    [ snip ]

    >
    > }Every time the library loads successfully, but the 'initDll' object is
    > ALWAYS Null. The return from GetProcAddress seems to always come up
    > null. Any suggestions?


    Hello Dave,

    Your question is off topic here, but you can check two things:

    1. Exporting functions from DLLs requires using __declspec(export)
    2. Name mangling needs to be disabled on exported functions. Mangled
    names may not be what you expect, so GetProcAddress may not find the
    function you want.

    Search for some sample code on Google. There are plenty of good
    examples available.

    But again, this question is off topic here. :)

    Regards,
    Markus.


    >
    > Thanks
     
    Markus Svilans, Jan 24, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wh
    Replies:
    2
    Views:
    531
    Cowboy \(Gregory A. Beamer\)
    Jan 16, 2004
  2. Thirumalai
    Replies:
    0
    Views:
    674
    Thirumalai
    May 22, 2006
  3. rockdale
    Replies:
    1
    Views:
    621
    Juan T. Llibre
    Aug 23, 2006
  4. xman
    Replies:
    0
    Views:
    513
  5. xman
    Replies:
    1
    Views:
    611
    Victor Bazarov
    Aug 17, 2005
Loading...

Share This Page