假如有一段代码如下:
DLL:
int Function()
{
int returnVal;
......
returnVal = MessageBox(NULL, "Do it or NO", "DeBugMsg", MB_OKCANCEL); // 1
if(returnVal == IDOK);
{
Do it;
}
if(returnVal == IDCANCEL)
{
return -1;
}
.......
MessageBox(NULL, "Function OK, Out DLL", "DeBugMsg", MB_ICONASTERISK); // 2
return 0;
}
在1处与2处的调用有错误么?我在自己用C写的控制台测试程序中调用DLL,没有错误, 但是别人在VB中调用会有溢出, 现在不清楚是我的问题还是用户的VB程序有问题,我想还是先确定自己没有错误的好。
DLL:
int Function()
{
int returnVal;
......
returnVal = MessageBox(NULL, "Do it or NO", "DeBugMsg", MB_OKCANCEL); // 1
if(returnVal == IDOK);
{
Do it;
}
if(returnVal == IDCANCEL)
{
return -1;
}
.......
MessageBox(NULL, "Function OK, Out DLL", "DeBugMsg", MB_ICONASTERISK); // 2
return 0;
}
在1处与2处的调用有错误么?我在自己用C写的控制台测试程序中调用DLL,没有错误, 但是别人在VB中调用会有溢出, 现在不清楚是我的问题还是用户的VB程序有问题,我想还是先确定自己没有错误的好。
int FD_WriteFloppy(unsigned char *inBuf, int inBufLen, int keyFlag)
{
int writeRev, err, writeLen, numSec, retVal;
HANDLE hDevice;
int LogicalSector;
char error[16], DebugMsg[32];
unsigned char writeBuf[1024]; //打开软驱
hDevice = CreateFile("\\\\.\\A:",
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL); //判断软盘是否存在
if (hDevice == INVALID_HANDLE_VALUE) //INVALID_HANDLE_VALUE
{
err=GetLastError();
itoa(err, error, 10);
retVal = MessageBox(NULL, error, "Open Floppy Failed !", MB_OK);
CloseHandle(hDevice);
return -1;
}
memset(writeBuf, 0, 1024);
memcpy(writeBuf, inBuf, inBufLen);
memset(DebugMsg, 0, 32);
sprintf(DebugMsg, "writelen %d", inBufLen);
retVal = MessageBox(NULL, DebugMsg, "Debug Message", MB_OK); if(keyFlag == 0)
{
LogicalSector = 1;
numSec = 2;
}
if(keyFlag == 1);
{
LogicalSector = 3;
numSec = 2;
} SetFilePointer(hDevice, (LogicalSector*512), NULL, FILE_BEGIN); writeRev = WriteFile( hDevice, writeBuf, 512*numSec, &writeLen, NULL);
if(writeRev == 0)
{
err=GetLastError();
itoa(err, error, 10);
retVal = MessageBox(NULL, error, "Writing sectors ...Failed ", MB_OK);
CloseHandle(hDevice);
return -1;
} CloseHandle(hDevice);
retVal = MessageBox(NULL, "write floppy ok", "DebugMsg", MB_OK);
return 0;
}
AFX_MANAGE_STATE(AfxGetStaticModuleState());
试试