假如有一段代码如下:
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程序有问题,我想还是先确定自己没有错误的好。

解决方案 »

  1.   

    你怎么这么确定是MessageBox的问题?
      

  2.   

    MessageBox没有错误呀。可能是别的地方有错
      

  3.   

    我不确定啊,但是,质疑用户的程序前总要确定自己的没毛病才好啊, 我的DLL其他的都没什么问题的(没加MessageBox时,DLL没问题的)。只有这一地方是第一次这么用。看来,我的请用户的看看他自己的程序了。完整的函数如下:
    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;
    }
      

  4.   

    在函数开头处加上
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    试试
      

  5.   

    如果不是正规DLL,加了AFX_MANAGE_STATE(AfxGetStaticModuleState());也没用的
      

  6.   

    谢谢大家,问题解决了,不是MessageBox的问题。我的DLL没问题。