以下函数为dll导出函数,在delphi中定时调用,第一次成功连接,第二次
socket->create()出现异常,错误号1410,郁闷3天了,这到底是什么原因?
extern "C" int   _cdecl ExecuteSyn()
{
CString str;
DWORD n = 0; if (!AfxSocketInit())
{
return FALSE;
} CSocket *pSocket = NULL;
pSocket = new CSocket; TRY{
if(pSocket->Create()){
::AfxMessageBox("successful");
}else{
n = ::GetLastError();
str.Format("%d", n);
::AfxMessageBox(str);
}
}
CATCH (CException, e){
n = ::GetLastError();
str.Format("%d", n);
::AfxMessageBox(str);
// ::AfxMessageBox("异常");
}
END_CATCH if(pSocket->Connect("10.188.182.219", 21)){
::AfxMessageBox("good");
}
else
::AfxMessageBox("bad");

str.Format("%d", (int)pSocket);
::AfxMessageBox(str);
if(pSocket){
delete pSocket;
pSocket = NULL;
::AfxMessageBox("release");
}
return 1;
}

解决方案 »

  1.   

    void GetError()
    {
    LPTSTR lpMsgBuf;
    FormatMessage( 
    FORMAT_MESSAGE_ALLOCATE_BUFFER | 
    FORMAT_MESSAGE_FROM_SYSTEM | 
    FORMAT_MESSAGE_IGNORE_INSERTS,
    NULL,
    GetLastError(),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    (LPTSTR) &lpMsgBuf,
    0,
    NULL 
    );
    MessageBox(NULL,lpMsgBuf,"ERROR",MB_OK);
    LocalFree( lpMsgBuf );
    }
      

  2.   

    if(pSocket){
    //先close掉
    delete pSocket;
    pSocket = NULL;
    ::AfxMessageBox("release");
    }
      

  3.   

    应该是你第二次Create的时候没有Close第一次的,不明白你为什么要定时创建
      

  4.   

    薄荷老大,laiyiling老大,你们来我就比较有信心了!!!
    其实这个贴我发3次了,dll里,网络编程里都有
    http://community.csdn.net/Expert/TopicView.asp?id=3153214这是一个被delphi写的交换系统程序定时调用vcdll里的主程序,更详细的情况请参看
    上面这个贴,希望得到你们的帮助!小弟谢谢了!
      

  5.   

    DLL在被load是在CSocket里注册了一个类,在free得时候没有注销那个类,导致第二次load时候注册失败!
    参看
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/WindowClasses/WindowClassReference/WindowClassFunctions/RegisterClass.asp