Announcement

Collapse
No announcement yet.

Call a regular mfc dll with PBDLL exe

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Call a regular mfc dll with PBDLL exe

    Hi there,

    does anyone know how to call a "regular MFC DLL" from pbdll.
    Try the MS dlltrace sample without success.

    Build my own CPP DLL :
    Code:
    //**************HWMain.h file*****************
    
    //HWMain.h Non-MFC DLL header file
    
    //sure it will be included only once
    #ifndef _ATM_HWMAIN_H_
    #define _ATM_HWMAIN_H_
    #pragma once
    
    //to speedup & reduce size
    #define VC_EXTRALEAN
    
    //Header body
    
    //export macros
    #define DLL_EXPORT __declspec(dllexport) 
    //import macro
    #define DLL_IMPORT __declspec(dllimport)
    
    #include <windows.h>
    
    //to export for C++ & C
    #ifdef __cplusplus 
     extern "C" 
     {  
    #endif
    
    //exported variable
    DLL_EXPORT int exp_iVar=99;
    
    //exported function
    DLL_EXPORT int ExportedFunc(int bParam);
    
    //exported class, with all definitions
    class DLL_EXPORT CHookWorks
    {
    public:
     //blah blah method
     int HookWorksFunc(void);
    
     //blah blah variable
     int m_iHookWorks;
    
     //con and decon
     CHookWorks();
     ~CHookWorks();
    };
    
    #ifdef __cplusplus 
       } 
    #endif
    
    
    #endif 
    //EOF Header body
    
    //*******************HMain.cpp file********************
    #include "HMain.h"
    
    //Regular DLL Entry Point, do not have any importancy 
    //to me here
    BOOL WINAPI DllMain(HINSTANCE hinstDLL, // DLL module handle
                        DWORD fdwReason, // for calling function
                        LPVOID lpvReserved   // reserved
                        )
    
    {				   
     switch(fdwReason)
     { 
      case DLL_PROCESS_ATTACH:
       
      break;
    
      case DLL_THREAD_ATTACH:
       
      break;
    
      case DLL_THREAD_DETACH:
      
      break;
    
      case DLL_PROCESS_DETACH: 
      
      break;
    
      default:
       break;
     }
    
     return TRUE;
    }
    
    //class export, with all definitions
    //member method
    int CHookWorks::HookWorksFunc()
    {
     m_iHookWorks=10;
     return 2;
    }
    
    //constructor
    CHookWorks::CHookWorks()
    {
     m_iHookWorks=1;
    }
    
    //destructor
    CHookWorks::~CHookWorks()
    {
    }
    
    //exported function declaration
    DLL_EXPORT int ExportedFunc(int bParam)
    {
     return bParam;
    }
    
    //*******************HWMain.cpp file********************
    from pbdll i try this :
    Code:
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' sample app shows use of mfc dlls
    '
    
    #DIM ALL
    #COMPILE EXE
    #REGISTER NONE
    #INCLUDE "win32api.inc"
    
    DECLARE FUNCTION ExportedFunc  LIB "hMain.dll" ALIAS "ExportedFunc"( BYVAL iVal AS INTEGER ) AS INTEGER
    DECLARE FUNCTION newHookWorks  LIB "hMain.dll" ALIAS "[email protected]@[email protected]" (hMFC AS DWORD) AS DWORD
    '' class CHookWorks & CHookWorks: [img]http://www.powerbasic.com/support/forums/redface.gif[/img]perator=(class CHookWorks const &)
    DECLARE FUNCTION initHookWorks LIB "hMain.dll" ALIAS "[email protected]@[email protected]@@Z" (lpClass AS DWORD) AS DWORD
    '' int CHookWorks::HookWorksFunc(void)
    DECLARE FUNCTION HookWorksFunc LIB "hMain.dll" ALIAS "[email protected]@@QAEHXZ" () AS INTEGER
    DECLARE FUNCTION killHookWorks LIB "hMain.dll" ALIAS "[email protected]@[email protected]" (lpClass AS DWORD) AS DWORD
    
    
    FUNCTION PBMAIN()
        LOCAL hMFC42DLL        AS DWORD
        LOCAL lpHookWorksClass AS DWORD
        LOCAL hMemHookWorks    AS DWORD
        LOCAL lpBuild          AS DWORD
        LOCAL iRet             AS INTEGER
    
        hMFC42DLL = GetModuleHandle("MFC42.dll")
        IF ISFALSE hMFC42DLL THEN hMFC42DLL = LoadLibrary("MFC42.dll")
    
        lpHookWorksClass = newHookWorks( hMFC42DLL )
        MSGBOX HEX$( lpHookWorksClass ),,"newHookWorks"
    
        hMemHookWorks = GlobalLock ( lpHookWorksClass )
        lpBuild       = initHookWorks( hMemHookWorks )
        MSGBOX HEX$( lpBuild ),,"initHookWorks"
    
        iRet = 4
    '    iRet = HookWorksFunc(  )    ''' causes a mem error
    
        GlobalUnLock  hMemHookWorks
        killHookWorks lpHookWorksClass
    
        MSGBOX FORMAT$( ExportedFunc(7) ) ,,"hMain.dll - ExportedFunc"
        MSGBOX "done"
    END FUNCTION
    MSDEV Debugger says : symbol this not defined when i try to access
    the HookWorksFunc in the HookWorks class.


    ------------------
Working...
X