first DLL program

This is a discussion on first DLL program within the Windows Programming forums, part of the Platform Specific Boards category; I created my first program using a DLL. I used a sample out of the Visual C++ 6 bible. That ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    first DLL program

    I created my first program using a DLL. I used a sample out of the Visual C++ 6 bible. That one worked fine. Their sample "DisplayAppName()" has no parameters. Then when I tried to build a function with parameters for "Multiply(int x, int y)" I could not figure out the syntax. I tried everything I could think of to include declaring my own function pointer so as to have a pointer of the correct type. I know it is not in the linking process because one works. I believe it is the syntax but cannot figure it out. Any help or hint is greatly appreciated.

    IDE: Visual C++ 6.0
    Using DLL wizard...


    //*****************************************
    //in the DLL .h file
    void DisplayAppName();
    int Multiply(int x, int y);


    //*****************************************
    //in the DLL cpp file
    void DisplayAppName()
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState() );
    CString str = AfxGetAppName();
    AfxMessageBox( str );
    }

    int Multiply(int x, int y)
    {
    return x * y;
    }


    //****************************************
    //In the client program (driver program)
    void CDllTestDlg::OnButton1()
    {
    FARPROC pfn;

    char buffer[255];
    CString s;

    GetCurrentDirectory(255, buffer);
    s = buffer;
    s.TrimRight("\\");

    s += ("\\DllProj.dll");

    HMODULE hm = LoadLibrary( s );

    if( hm != NULL )
    {
    CString s1;

    //this works fine
    pfn = GetProcAddress(hm, "DisplayAppName");

    if( pfn != NULL )
    pfn();
    else
    {
    s1.Format("Error %d", GetLastError());
    MessageBox( s1 );
    }

    //** this does not work
    //**i also tried "Multiply(int x, int y)
    //** i also tried declaring my own pointer to function
    //int (*multi)(int x, int y);
    //multi = GetProcAdress(hm, "Multiply");
    pfn = GetProcAddress(hm, "Multiply");
    if( pfn != NULL )
    {
    s1.Format("2 * 2 = %d", pfn());
    MessageBox( s1 );
    }

    }

    }
    zMan

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    function with parameters in dll..

    ....oops I goofed sorry.. Here it is again
    Code:
    //***************************************** 
    //in the DLL .h file 
    void DisplayAppName(); 
    int Multiply(int x, int y); 
    
    
    //***************************************** 
    //in the DLL cpp file 
    void DisplayAppName() 
    { 
        AFX_MANAGE_STATE(AfxGetStaticModuleState() ); 
        CString str = AfxGetAppName(); 
        AfxMessageBox( str ); 
    } 
    
    int Multiply(int x, int y) 
    { 
       return x * y; 
    } 
    
    
    //**************************************** 
    //In the client program (driver program) 
    void CDllTestDlg::OnButton1() 
    { 
       FARPROC pfn; 
    
       char buffer[255]; 
       CString s; 
    
       GetCurrentDirectory(255, buffer); 
       s = buffer; 
       s.TrimRight("\\"); 
    
       s += ("\\DllProj.dll"); 
    
       HMODULE hm = LoadLibrary( s ); 
    
       if( hm != NULL ) 
       { 
          CString s1; 
    
          //this works fine 
          pfn = GetProcAddress(hm, "DisplayAppName"); 
    
          if( pfn != NULL ) 
             pfn(); 
          else 
         { 
             s1.Format("Error %d", GetLastError()); 
             MessageBox( s1 ); 
         } 
    
         //** this does not work 
         //**i also tried "Multiply(int x, int y) 
         //** i also tried declaring my own pointer to function 
         //int (*multi)(int x, int y); 
         //multi = GetProcAdress(hm, "Multiply");  
         pfn = GetProcAddress(hm, "Multiply"); 
         if( pfn != NULL ) 
         { 
                s1.Format("2 * 2 = %d", pfn()); 
                MessageBox( s1 ); 
         } 
    
      } 
    
    }
    zMan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Replies: 8
    Last Post: 12-01-2008, 10:09 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21