CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2005
    Posts
    25

    Thumbs up How to link the DLL to ur activex control using LoadLibrary() API call?

    hai,

    I want to develop activex control. I need to link the DLL to the control using LoadLibrary() API call. Usually LoadLibrary.cpp and LoadLibrary.h these two files are added to the wizard from that we need to call the API LoadLibrary. Its not working now.

    Can you explain how to use the LoadLibrary(), getProcAddress() API call in the wizard? What ever modifications i have to do in DLL side?

    Thanks in advance,

    R.Jaiganesh

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: How to link the DLL to ur activex control using LoadLibrary() API call?

    I don't understand what you are saying. If you want to use API ::LoadLibrary() and ::GetProcAddress() take a look in MSDN. It's not big deal. You have to do something like this.

    Code:
    // function prototype from DLL
    typedef int (__cdecl myFunc*)(void);
    
    // load the library
    HMODULE hdll = ::LoadLibrary("mylib.dll");
    if(hdll != NULL)
    {
       // get a pointer to the desired function
       myFunc pointerToMyFunc = (myFunc)::GetProcAddress(hdll, "MyFuncName");
      
       if(pointerToMyFunc != NULL)
       {
          // call the function
          int result = (*pointerToMyFunc)();
       }
    
       // free the loaded library
       ::FreeLibrary(hdll);
    }
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: How to link the DLL to ur activex control using LoadLibrary() API call?


    Look up Run-Time Dynamic Linking - its the kind that interests you.

  4. #4
    Join Date
    Mar 2005
    Posts
    25

    Re: How to link the DLL to ur activex control using LoadLibrary() API call?

    hai,

    How to find out the LoadLibrary ( ) API call is getting executed successfully or Not? how to print the return value of this call? . where to put the DLL ?.I try this LoadLibrary ( ) .It returns MZ string after that it fails in GetProcAddress . can u give sample for this LoadLibrary() and GetProcAddress( )?

    Thanks in Advance.
    Regards

    R.Jaiganesh.

  5. #5
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: How to link the DLL to ur activex control using LoadLibrary() API call?

    Quote Originally Posted by jaiganeshbe
    How to find out the LoadLibrary ( ) API call is getting executed successfully or Not?
    See cilu's post.
    Quote Originally Posted by jaiganeshbe
    how to print the return value of this call? . where to put the DLL ?.
    Put the DLL in the application directory, and supply relative path.
    Quote Originally Posted by jaiganeshbe
    can u give sample for this LoadLibrary() and GetProcAddress( )?
    Did you read my previous post? It says "Using DLLs with Sample".
    Last edited by Siddhartha; October 25th, 2005 at 03:49 AM.

  6. #6
    Join Date
    Mar 2005
    Posts
    25

    Re: How to link the DLL to ur activex control using LoadLibrary() API call?

    I cant get address of the function inside the DLL.what ever link specified in that they saying different procedure to build the dll.In my case I already have the DLL.whether I have to change the calling convention of the DLL function or not?

  7. #7
    Join Date
    Oct 2005
    Posts
    2

    Resolved Re: How to link the DLL to ur activex control using LoadLibrary() API call?

    //DLL is having the following API
    //DLL name is MyFirstAPIDll.dll
    #define MY_API __declspec(dllexport)
    MY_API HRESULT MyFirstAPI(char *pApiName)
    {
    AfxMessageBox("MyFirstAPI");
    return S_FALSE;
    }

    //Now load the This particular dll in the client side applications as follows
    UINT uReturnVal;
    typedef HRESULT (*typeMyFirstAPI) (char *pApiName);
    HINSTANCE hDLL; // Handle to DLL
    MySetVarName lpfnDllFunc1; // Function pointer
    hDLL = LoadLibrary("MyFirstAPIDll.dll");
    if (hDLL != NULL)
    {
    lpfnDllFunc1 =(typeMyFirstAPI)::GetProcAddress(hDLL,"MyFirstAPI");
    if (!lpfnDllFunc1)
    {
    // handle the error
    FreeLibrary(hDLL);
    return ;
    }
    else
    {
    // call the function
    char *pVarname =NULL;
    uReturnVal = lpfnDllFunc1(pVarname );
    }
    }

  8. #8
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: How to link the DLL to ur activex control using LoadLibrary() API call?

    How to find out the LoadLibrary ( ) API call is getting executed successfully or Not? how to print the return value of this call? . where to put the DLL ?.I try this LoadLibrary ( ) .It returns MZ string after that it fails in GetProcAddress . can u give sample for this LoadLibrary() and GetProcAddress( )?
    Do you have MSDN? Then read the documentation of these functions.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How to link the DLL to ur activex control using LoadLibrary() API call?

    Quote Originally Posted by jaiganeshbe
    I cant get address of the function inside the DLL.
    I think this is the point. First you have to find out the reason of GetProcAddress failure. Did you try to make those dll linking in some test project? just for make yourself sure you understand the things alright?

    what ever link specified in that they saying different procedure to build the dll.
    Would you say the same but different way? I didn't get your thought.

    In my case I already have the DLL.whether I have to change the calling convention of the DLL function or not?
    Cool. Never could understand people who make program design by dice throwing. Why do you have to change calling convention? Calling convention of exported function matters for function call but not for its address discovering. To get it you just have to know real export name of the function. And if you don't, then reach for depends.exe and take a look at your dll exports.

    Man, I'm really upset. I really cannot understand how anybody can program ActiveX been absolutely faint with dll basics.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured