I have a DLL that is written in C. I am trying to use it from VB. I can use most commands, but the most important one is giving me trouble. The problem is in my declaration I am sure. It is causing a GPF... which does not occur in its Visual C++ counterpart calling program. Can anyone help me figure out what is wrong with my VB declare from this????

Here is my VB Declaration:

Private Declare Function mnCheckDevices Lib "mnw.dll" (ByRef mn_DevFlg() As Long, ByRef mn_Port As Long, ByRef mn_DevCnt As Long, ByRef mn_ErrMsg() As Byte, ByRef mn_BuffSize As Long) As Long

Here is the C procedure:

//Inputs:
//dev_flag => pointer to array for active devices
// port => pointer to selected com port
//dev_cnt => pointer to variable for number of devices found
//error_mess => string that holds return error message
//buff_size => pointer to variable for buffer size
//Outputs:
//None
/////////////////////////////////////////////////////////////////////////////
extern "C"
int __declspec(dllexport) WINAPI mnCheckDevices(int *dev_flg, int *port, int *dev_cnt, char *error_mess, int *buff_size)
{
static long start, end;
static int port_num;
static int i, rec_addr[2];
static int errflag[MAX_BOARDS];
static int ret_code;
static int baud_rate;
static bool BaudRatesTried[5];
static char address;

DeviceDialog = new TDeviceDialog(NULL);
DeviceDialog->Show();
DeviceDialog->Update();

port_num = *port;

for (i = 0; i <= MAX_BOARDS; i++)
errflag[i] = dev_flg[i] = 0;

for (i = 0; i < 5; i++)
BaudRatesTried[i] = false;

baud_rate = BaudRates[0];
BaudRatesTried[0] = true;

CloseComm(&port_num); // close comm port
InitComm(&port_num, &baud_rate, buff_size); //reinitialize comm port

while (1)
{
// detect number of devices present on line and their addresses
address = 0x00;
ret_code = XmitPacket("*", &address, &port_num);
if (ret_code < 0)
return ret_code;

ret_code = DeviceDialog->GetActiveDevices(&port_num, rec_addr, error_mess,
dev_flg, dev_cnt);
if (ret_code == 0)
{
chk_devices = true;
break;
}
else if (ret_code < 0)
{
Application->MessageBox("CheckDevices failed.\n\rCommunication error.", NULL, MB_OK);
break;
}
// Select a different baud rate
// BaudRatesTried[port_num-5] = true;
for (i = 0; i < 5; i++)
{
if (!BaudRatesTried[i])
{
baud_rate = BaudRates[i];
BaudRatesTried[i] = true;
break;
}
}
if (i == 5)
{
// DeviceDialog->CloseDialog();
DeviceDialog->Close();
Application->MessageBox("CheckDevices failed. No active devices found.",
NULL, MB_OK);
return -1;
// baud_rate = -1;
// break;
}
else
{
CloseComm(&port_num); // close comm port
InitComm(&port_num, &baud_rate, buff_size); // reinitialize comm port
}
}

if (baud_rate > 0)
{
start = GetTime();
do
{
end = GetTime();
if (end - start < 0)
end = end + 8640000;
} while (end - start < 50); // delay 0.50 seconds
// DeviceDialog->CloseDialog();
DeviceDialog->Close();
}
return baud_rate;
} // mnCheckDevices() ends