Problems: C++ program, Delphi 2.0 DLL, and a callback

Howdy.  I've written a DLL in Delphi 2.0 and I am testing it with both a C++
console app and a C GUI app written in BC++ 5.0.  Everything works great
except for the callback function in my DLL.

The DLL communicates with the serial port.  I'm using the callback function to
send data received on the serial port as it comes in.

Whenever my DLL makes a call to the C++ program, and exception error occours.
The C++ callback code executes, but the C++ program fails to terminate
properly. I suspect that my DLL calling the C++ callback code is screwing up
the program counter so that once the callback finishes executing, it doesn't
know where to go back to.

This problem occours in both the win32 console and GUI app I've written for
testing purposes.  This problem occours even if the callback function
contains no code.  HOWEVER, everything works fine if I use a Delphi driver
program to test my DLL and callbacks.

Anyone have any ideas?

Here's some rough code (I don't have my program with me, so I'm doing this
from memory to create an example.)

// Delphi:
TCallback = procedure(szText: pchar); stdcall;

// C++

void (*func)(int);
extern "C" void _stdcall DLL_SendCallbackAddr(void (*func)(char*));
extern "C" int _stdcall DLL_SendToCOMPort(char *);
void _stdcall CPP_Callback(char *);

char databuffer[80];

    DLL_SendToCOMPort("atdt 357-5343\r\n");

    /* code here to prevent program from exiting without user input */


// In my test programs, this function usualy gets called twice.  Once for the
// ATDT command sent to the modem, and again when it gets a busy signal
// The code in the below function executes fine, but an exception occours
// each time CPP_Callback returns.

void CPP_Callback(char * szData)
    strcpy(databuffer, szData);


-----------== Posted via Deja News, The Discussion Network ==----------       Search, Read, Discuss, or Start Your Own