locked
Passing Callbacks to a DLL that was created with C++6.0 RRS feed

  • Question

  • //----------------------------------------------------------------------------------------------------------------

    PROBLEM:

    I am using Microsoft Visual C++ 2005 express edition to consume functions from a DLL that was written using Visual C++ 6.0. I do not have the DLL source code for debugging purposes.

     

    The DLL interfaces with an auxillary hardware device. When the hardware receives incoming data, the DLL triggers a user defined callback routine. I am only speculating, but I think the DLL creates a thread that runs in the background.

     

    I am creating a forms application and I cannot get the callback routine to work using VC++ 2005 Express.  If I take essentially the same code and build my project using VC++ 6.0, the callbacks work just fine. So I have a high degree of confidence that the hardware is working properly and that the DLL works.

     

    How do I get the callback to work in VC++ 2005 Express?

     

    //----------------------------------------------------------------------------------------------------------------

     

    /************************************************************************************

    The DLL  uses the following structures and provides the following function:

    *************************************************************************************

    typedef struct

         {

         unsigned char bActive;

         void (CALLBACK *pfMailBoxReleased)(void *);

         unsigned char bData[MAILBOX_BUFFER_SIZE];

         void *vpData;

    } MailBoxType;

     

     

    typedef struct {

         unsigned char bProtocol;

         void (CALLBACK *pfApplicationRoutine)(MailBoxType *);          // This function works in 6.0 but not 2005!

          void *vpData;

    } LoadMailBoxType;

     

    short LoadMailBox (short dpaHandle, LoadMailBoxType *pLoadMailBoxData);

    short InitDPA(short *dpaHandle,short dpaNumber);

     

    /************************************************************************************

    My application does the following:

    *************************************************************************************

    void ProcessTxData (MailBoxType *Handle)

    {

    //Just output a simple message indicating that the callback executed

    ofstream outFile;

    outFile.open("Tx.txt");

    outFile<< "Callback Routine \n";

    outFile.close();

    }

     

    unsigned char dataIn[2048];

     

     

    [DllImport("dpam32.dll")]

    extern "C" short InitDPA(short *dpaHandle,short dpaNumber);

     

    [DllImport("dpam32.dll")]

    extern "C" short LoadMailBox (short dpaHandle,LoadMailBoxType *pLoadMailBoxData);

     

    [STAThreadAttribute]

    int main(array<System:Tongue Tiedtring ^> ^args)

    {

    short result             = eNoError;

    short dpaInitStatus  = eNoError;

    short dpaHandle      = 0;

     

    //Init the hardware

    dpaInitStatus = InitDPA(&dpaHandle, 601);           //601 is a number that correspond to specific hardware

     

    //Rx Mailbox

    RxMailBox.bProtocol = 3;

    RxMailBox.pfApplicationRoutine = ProcessRxData;    //this is the routine that is not executing

    RxMailBox.vpData = dataIn;

     

    result = LoadMailBox(dpaHandle, &RxMailBox);     //After this line executes, my routine should be called but it is not.

     

     

    //BELOW IS MICROSOFT CODE. IT WAS GENERATED AUTOMATICALLY

     

    // Enabling Windows XP visual effects before any controls are created

    Application::EnableVisualStyles();

    Application:Tongue TiedetCompatibleTextRenderingDefault(false);

    // Create the main window and run it

    Application::Run(gcnew Form1());

    return 0;

    }

     

     

     

     

    Wednesday, February 13, 2008 11:07 PM

Answers

All replies