calling a win32 dll from ATL Component

Posted on 2006-04-24
Last Modified: 2013-11-25
  i had the requirement that i need to call a exported funtions from win32/MFC dlls from ATL Component. how to do this can any one please suggest.
Question by:vgiridhar
    LVL 48

    Accepted Solution

    Non-MFC Dll can be called from ATL component by the same way like from any project. All .lib file to the priject, include h-file and call functions and classes.
    MFC extension Dll can be called only from project with MFC support.
    Regulary MFC Dll can be called from any project, even if it doesn't has MFC support. Regulary MFC Dll exposes standard interface - exported classes or functions, and can be used as any other Dll.
    LVL 2

    Expert Comment

    There are two ways..

    1. is as AlexcFM said above.
    2.using LoadLibrary and GetProcAddress API's

    I hope this will help you.

    LVL 3

    Assisted Solution

    the code that help you

    typedef DWORD ( *hh1)(LPSTR strPass1, LPSTR strPass2);
    hh1 function_from_dll;

    CString strRet;
    CString strPass1;
    CString strPass2

         HINSTANCE hLib;
         hLib = LoadLibrary(("Example.dll"));
              function_from_dll= (hh1)GetProcAddress(hLib, ("getURL"));
              strRet= function_from_dll(strPass1,strPass2);

    LVL 11

    Assisted Solution

    To assist what AlexFM's point 1.

    To include the .lib file into the project you could add this line of code into one of your .h/.cpp file:
    #pragma comment(lib, "your_dll's_lib.lib")


    You could add it through IDE like MSVC++, which will have some UI's dialog boxes to add this in to the project. (I think it is in Project Settings)

    I hope that now you are allready and equipped with all the possible ways of calling the .dlls from other application.

    Best Regards,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now