Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Calling dll

Calling dll

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelp
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Le rner
    wrote on last edited by
    #1

    Hi all, i have made a dll i want to use that dll in my program i have called the function of that dll using this code

    typedef void (*function1_ptr) ();
    function1_ptr function1=NULL;

    int APIENTRY WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
    {

    HMODULE myDll = LoadLibrary("myfile.dll"); 
    
    if(myDll)
    {  
    	function1 = (function1\_ptr) GetProcAddress(myDll,"function1");  
    
    	if(function1)  
    		function1();
    
    	FreeLibrary(myDll);
    }
    
    return 0;
    

    }

    i have copied my dll in debug folder, but control is not going inside if statement... how should i do it.... can anybody please help me... Thanks in advance

    To accomplish great things, we must not only act, but also dream; not only plan, but also believe.

    M A E C 4 Replies Last reply
    0
    • L Le rner

      Hi all, i have made a dll i want to use that dll in my program i have called the function of that dll using this code

      typedef void (*function1_ptr) ();
      function1_ptr function1=NULL;

      int APIENTRY WinMain(HINSTANCE hInstance,
      HINSTANCE hPrevInstance,
      LPSTR lpCmdLine,
      int nCmdShow)
      {

      HMODULE myDll = LoadLibrary("myfile.dll"); 
      
      if(myDll)
      {  
      	function1 = (function1\_ptr) GetProcAddress(myDll,"function1");  
      
      	if(function1)  
      		function1();
      
      	FreeLibrary(myDll);
      }
      
      return 0;
      

      }

      i have copied my dll in debug folder, but control is not going inside if statement... how should i do it.... can anybody please help me... Thanks in advance

      To accomplish great things, we must not only act, but also dream; not only plan, but also believe.

      M Offline
      M Offline
      Madhu Nair 0
      wrote on last edited by
      #2

      Try giving full path in LoadLibrary. HMODULE myDll = LoadLibrary("myfile.dll"); to something like HMODULE myDll = LoadLibrary("C:\\Myproject\\debug\\myfile.dll");

      1 Reply Last reply
      0
      • L Le rner

        Hi all, i have made a dll i want to use that dll in my program i have called the function of that dll using this code

        typedef void (*function1_ptr) ();
        function1_ptr function1=NULL;

        int APIENTRY WinMain(HINSTANCE hInstance,
        HINSTANCE hPrevInstance,
        LPSTR lpCmdLine,
        int nCmdShow)
        {

        HMODULE myDll = LoadLibrary("myfile.dll"); 
        
        if(myDll)
        {  
        	function1 = (function1\_ptr) GetProcAddress(myDll,"function1");  
        
        	if(function1)  
        		function1();
        
        	FreeLibrary(myDll);
        }
        
        return 0;
        

        }

        i have copied my dll in debug folder, but control is not going inside if statement... how should i do it.... can anybody please help me... Thanks in advance

        To accomplish great things, we must not only act, but also dream; not only plan, but also believe.

        A Offline
        A Offline
        Abhi Lahare
        wrote on last edited by
        #3

        What the error return code you are getting from LoadLibrary function?

        1 Reply Last reply
        0
        • L Le rner

          Hi all, i have made a dll i want to use that dll in my program i have called the function of that dll using this code

          typedef void (*function1_ptr) ();
          function1_ptr function1=NULL;

          int APIENTRY WinMain(HINSTANCE hInstance,
          HINSTANCE hPrevInstance,
          LPSTR lpCmdLine,
          int nCmdShow)
          {

          HMODULE myDll = LoadLibrary("myfile.dll"); 
          
          if(myDll)
          {  
          	function1 = (function1\_ptr) GetProcAddress(myDll,"function1");  
          
          	if(function1)  
          		function1();
          
          	FreeLibrary(myDll);
          }
          
          return 0;
          

          }

          i have copied my dll in debug folder, but control is not going inside if statement... how should i do it.... can anybody please help me... Thanks in advance

          To accomplish great things, we must not only act, but also dream; not only plan, but also believe.

          E Offline
          E Offline
          EverettJF
          wrote on last edited by
          #4

          GetProcAddress(myDll,"function1"); maybe the 2nd parameter is the key. you could use "dumpbin /exports myfile.dll" to check the exported functions' name. then,give the right name string. i think your dll should include .def file

          modified on Tuesday, December 29, 2009 3:16 AM

          1 Reply Last reply
          0
          • L Le rner

            Hi all, i have made a dll i want to use that dll in my program i have called the function of that dll using this code

            typedef void (*function1_ptr) ();
            function1_ptr function1=NULL;

            int APIENTRY WinMain(HINSTANCE hInstance,
            HINSTANCE hPrevInstance,
            LPSTR lpCmdLine,
            int nCmdShow)
            {

            HMODULE myDll = LoadLibrary("myfile.dll"); 
            
            if(myDll)
            {  
            	function1 = (function1\_ptr) GetProcAddress(myDll,"function1");  
            
            	if(function1)  
            		function1();
            
            	FreeLibrary(myDll);
            }
            
            return 0;
            

            }

            i have copied my dll in debug folder, but control is not going inside if statement... how should i do it.... can anybody please help me... Thanks in advance

            To accomplish great things, we must not only act, but also dream; not only plan, but also believe.

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #5

            Le@rner wrote:

            but control is not going inside if statement...

            Which one ? The one after the call to LoadLibrary or the one after the call to GetProcAddress ? If this is the second call, make sure that you have provided a module defintion file (.def file) as explained in the documentation[^]

            Cédric Moonen Software developer
            Charting control [v2.0] OpenGL game tutorial in C++

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups