亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? icsdll1.cpp

?? . Info directory .delphiinternet Delphi sample applications (all Delphi versions) .cppinternet C++
?? CPP
字號:
/*---------------------------------------------------------------------------

Author:       Fran鏾is PIETTE
Creation:     April 08, 2000
Description:  This is a demo showing how to use a TWSocket component in a DLL.
              This demo must be used with ICS TcpSrv demo program as a server.
              The DLL is a client which connect to the server and send "time"
              command, then wait for the reply and return it in the buffer
              passed to the DLL.
              There is only one function exported from the DLL: IcsDllDemo.
              It takes four arguments: a pointer to the hostname to connect to,
              a pointer to the port, a pointer to a buffer and a pointer for
              buffer size. On entry buffer size must be initialised with the
              size of the actual buffer. On exit, it is filled with the
              actual reply size. The function's return value is the error code
              such as 10061 when the server is not running.
Version:      1.00
EMail:        http://www.overbyte.be       francois.piette@overbyte.be
              http://www.rtfm.be/fpiette   francois.piette@rtfm.be
              francois.piette@pophost.eunet.be
Support:      Use the mailing list twsocket@elists.org
              Follow "support" link at http://www.overbyte.be for subscription.
Legal issues: Copyright (C) 2000-2002 by Fran鏾is PIETTE
              Rue de Grady 24, 4053 Embourg, Belgium. Fax: +32-4-365.74.56
              <francois.piette@overbyte.be> <francois.piette@pophost.eunet.be>

              This software is provided 'as-is', without any express or
              implied warranty.  In no event will the author be held liable
              for any  damages arising from the use of this software.

              Permission is granted to anyone to use this software for any
              purpose, including commercial applications, and to alter it
              and redistribute it freely, subject to the following
              restrictions:

              1. The origin of this software must not be misrepresented,
                 you must not claim that you wrote the original software.
                 If you use this software in a product, an acknowledgment
                 in the product documentation would be appreciated but is
                 not required.

              2. Altered source versions must be plainly marked as such, and
                 must not be misrepresented as being the original software.

              3. This notice may not be removed or altered from any source
                 distribution.

              4. You must register this software by sending a picture postcard
                 to the author. Use a nice stamp and mention your name, street
                 address, EMail address and any comment you like to say.

History:


---------------------------------------------------------------------------*/
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#pragma argsused
#include "WSocket.hpp"
//---------------------------------------------------------------------------
extern "C" __declspec(dllexport) int __stdcall IcsDllDemo(char *HostName,
                                                          char *Port,
                                                          char *Buffer,
                                                          int  *BufSize);
void StrToBuffer(char *Buffer, int *BufSize, char *Msg);
//---------------------------------------------------------------------------
// We use a workerthread to do the job.
// This will allows the DLL to be called by several processes simultaneously
class TClientThread : public TThread
{
private:
    TWSocket *FClientSocket;
    void __fastcall ClientWSocketDataAvailable(TObject *Sender, WORD Error);
    void __fastcall ClientWSocketSessionClosed(TObject *Sender, WORD Error);
    void __fastcall ClientWSocketSessionConnected(TObject *Sender, WORD Error);
protected:
    AnsiString FHostName;
    AnsiString FPort;
    int        *FErrorCode;
    BOOL       FBannerReceived;
    char       *FBuffer;
    int        *FBufSize;
    void __fastcall Execute();
public:
    __fastcall TClientThread();
    __fastcall ~TClientThread();
    __property char      *Buffer    = {read=FBuffer,    write=FBuffer};
    __property int       *BufSize   = {read=FBufSize,   write=FBufSize};
    __property int       *ErrorCode = {read=FErrorCode, write=FErrorCode};
    __property AnsiString HostName  = {read=FHostName,  write=FHostName};
    __property AnsiString Port      = {read=FPort,      write=FPort};
};
//---------------------------------------------------------------------------
// Create a new thread in the blocked state. This allow the user to register
// the client thread before it actually start working.
__fastcall TClientThread::TClientThread()
    : TThread(TRUE)
{
    FreeOnTerminate = TRUE;
}
//---------------------------------------------------------------------------
// Destroy the thread. Destroy the ClientWSocket if needed.
__fastcall TClientThread::~TClientThread()
{
    if (FClientSocket != NULL) {
         FClientSocket->~TWSocket();
         FClientSocket = NULL;
    }
}
//---------------------------------------------------------------------------
// This is the main thread routine. There is not much to do because TWSocket
// is event drive. So everythong to do is done inside an event handler,
// mostly the OnDataAvailable event handler which is triggered each time
// something is received.
void __fastcall TClientThread::Execute()
{
    try {
        // Create the client TWSocket. It is important to create it inside the
        // Execute method because it *must* be created by the thread. Otherwise
        // the messages sent by winsock would be processed in the main thread
        // context, effectively disabling multi-threading.
        FClientSocket                     = new TWSocket(NULL);
        FClientSocket->OnDataAvailable    = ClientWSocketDataAvailable;
        FClientSocket->OnSessionConnected = ClientWSocketSessionConnected;
        FClientSocket->OnSessionClosed    = ClientWSocketSessionClosed;
        FClientSocket->LineMode           = TRUE;
        FClientSocket->Addr               = FHostName;
        FClientSocket->Port               = FPort;
        FClientSocket->Proto              = "tcp";
        FClientSocket->Connect();

        // Message loop to handle TWSocket messages
        // The loop is exited when WM_QUIT message is received
        FClientSocket->MessageLoop();
    }
    catch (Exception &E)
    {
        AnsiString Buf;
        Buf = E.ClassName();
        Buf = Buf  + ": " + E.Message;
        *FErrorCode = -3;
        StrToBuffer(Buffer, BufSize, Buf.c_str());
    }

    // Returning from the Execute function effectively terminate the thread
}
//---------------------------------------------------------------------------
// This event handler is called when the client connection is established.
void __fastcall TClientThread::ClientWSocketSessionConnected(
    TObject *Sender, WORD Error)
{
    if (Error) {
        *FErrorCode = Error;
        StrToBuffer(Buffer, BufSize, "Connect failed");
        PostMessage(FClientSocket->Handle, WM_QUIT, 0, 0);
    }
}
//---------------------------------------------------------------------------
// This event handler is called when the client connection is closed.
void __fastcall TClientThread::ClientWSocketSessionClosed(
    TObject *Sender, WORD Error)
{
    PostMessage(FClientSocket->Handle, WM_QUIT, 0, 0);
}
//---------------------------------------------------------------------------
// This event handler is called when data has been received from server.
// Since this sample program use line mode, we comes here only when a
// complete line has been received.
void __fastcall TClientThread::ClientWSocketDataAvailable(
    TObject *Sender, WORD Error)
{
    AnsiString RcvBuffer;

    // Received the line
    RcvBuffer = FClientSocket->ReceiveStr();
    // Check if we already received the banner (message sent by server
    // as soon as we are connected.
    if (!FBannerReceived) {
        // We are just receiving the banner. Flag as received
        FBannerReceived = TRUE;
        // Then send the command to the server
        FClientSocket->SendStr("time\r\n");
    }
    else {
        // We already received then banner. So this must be the answer
        // to our command. Copy to the buffer, without trailling CR/LF
        // and without overflowing the given buffer
        if (RcvBuffer.Length() < *BufSize)
            *BufSize = RcvBuffer.Length() - 2;  // Remove CR/LF
        if (*BufSize > 0)
            memcpy(Buffer, RcvBuffer.data(), *BufSize);
        // Then just close the communication
        FClientSocket->CloseDelayed();
        *FErrorCode = 0;
    }
}
//---------------------------------------------------------------------------
// Copy a string to a buffer with overflow check.
void StrToBuffer(char *Buffer, int *BufSize, char *Msg)
{
    int Len;

    if ((Len = strlen(Msg)) < *BufSize)
        *BufSize = Len;
    if (*BufSize > 0)
        memcpy(Buffer, Msg, *BufSize);
}
//---------------------------------------------------------------------------
// This is the function exported from the DLL. It is intended to be called
// from the application using the DLL.
int __stdcall IcsDllDemo(
    char *HostName,
    char *Port,
    char *Buffer,
    int  *BufSize)
{
    TClientThread *WorkerThread;
    int           Result;

    try {
        Result = -1;
        // Create a new thread. It is created in sleeping state
        WorkerThread           = new TClientThread;
        // Then pass all parameters
        WorkerThread->Buffer    = Buffer;
        WorkerThread->BufSize   = BufSize;
        WorkerThread->ErrorCode = &Result;
        WorkerThread->HostName  = HostName;
        WorkerThread->Port      = Port;
        // Then let thread start his work
        WorkerThread->Resume();
        // And wait until it finishes
        WaitForSingleObject((void *)WorkerThread->Handle, INFINITE);
    }
    catch (Exception &E)
    {
        AnsiString Buf;
        Buf = E.ClassName();
        Buf = Buf + ": " + E.Message;
        Result = -2;
        StrToBuffer(Buffer, BufSize, Buf.c_str());
    }
    return(Result);
};
//---------------------------------------------------------------------------
// This function is called by Windows when the DLL is loaded/unloaded and
// each time a thread attach/detach from the DLL
BOOL WINAPI DllEntryPoint(
    HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
    switch (fwdreason) {
    case DLL_PROCESS_ATTACH:
        // Increment WSocket reference count. This will make sure winsock will
        // remains loaded. This is because there is no permanent TWSocket
        // component created.
        WSocketGCount++;
        // This will load winsock and call WSAStartup
        WSocketGetProc("");
        break;
    case DLL_PROCESS_DETACH:
        // Decrement WSocket reference count.
        WSocketGCount--;
        // If reference count goes to zero, then unload winsock.
        if (WSocketGCount <= 0) {
            WSocketUnloadWinsock();
            WSocketGCount = 0;
        }
        break;
    }
    return(1);
}
//---------------------------------------------------------------------------

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美激情在线观看视频免费| 欧美电影免费观看高清完整版| 亚洲国产精品天堂| 亚洲精品视频自拍| 国产精品传媒入口麻豆| 欧美激情一二三区| 国产精品毛片高清在线完整版| 日本一区二区三级电影在线观看 | 寂寞少妇一区二区三区| 一区二区三区在线观看国产| 一区二区三区视频在线看| 亚洲欧美日韩在线播放| 亚洲欧美激情一区二区| 一区二区三区蜜桃| 日韩精品电影在线观看| 免费不卡在线视频| 国产一区二区三区在线观看精品| 国产成人精品三级麻豆| 波多野结衣中文字幕一区二区三区 | 91麻豆精品91久久久久同性| 欧美日韩国产一级片| 日韩视频中午一区| 国产欧美日韩在线视频| 国产精品久久久久久久久晋中| 亚洲人成在线播放网站岛国 | 久久在线观看免费| 国产精品三级电影| 亚洲精品视频在线观看免费| 亚洲自拍偷拍麻豆| 奇米影视在线99精品| 国产成a人亚洲| 一本大道av一区二区在线播放 | 国产v综合v亚洲欧| 91浏览器在线视频| 日韩一级大片在线观看| 亚洲国产成人一区二区三区| 亚洲综合色噜噜狠狠| 麻豆精品一二三| 成人免费看的视频| 欧美日韩一区二区欧美激情| 国产午夜精品在线观看| 亚洲国产日韩精品| 成人视屏免费看| 欧美日韩国产色站一区二区三区| 国产婷婷色一区二区三区在线| 亚洲乱码国产乱码精品精可以看 | 日产欧产美韩系列久久99| 国产99久久久国产精品免费看 | 国产精品久久毛片| 欧美日韩亚洲综合一区| 久久久91精品国产一区二区三区| 国产激情一区二区三区四区 | 国产精品国产馆在线真实露脸| 91精品国产综合久久精品app| 精品中文av资源站在线观看| 91麻豆免费视频| 日韩午夜小视频| 一区在线观看免费| 韩国毛片一区二区三区| 欧美日韩国产综合一区二区三区| 国产精品日日摸夜夜摸av| 激情五月婷婷综合| 91精品国产综合久久久久| 亚洲精品少妇30p| 成人免费av在线| 久久嫩草精品久久久久| 另类小说一区二区三区| 欧美美女黄视频| 亚洲综合免费观看高清完整版在线 | 午夜亚洲国产au精品一区二区| 成人视屏免费看| 国产视频一区在线播放| 国内精品久久久久影院薰衣草 | 色成人在线视频| 日韩伦理av电影| 99久久精品国产网站| ●精品国产综合乱码久久久久 | 一区二区三区日韩欧美| 在线中文字幕不卡| 亚洲免费在线视频一区 二区| jlzzjlzz国产精品久久| 综合欧美一区二区三区| av电影天堂一区二区在线观看| 久久这里都是精品| 国产麻豆精品一区二区| 国产午夜精品久久久久久久 | 久久久久久久久久美女| 免费xxxx性欧美18vr| 日韩一区二区在线播放| 韩国成人福利片在线播放| 久久色.com| 国产高清无密码一区二区三区| 国产亚洲欧洲一区高清在线观看| 国产传媒一区在线| 久久久久久一级片| 国产一区二区按摩在线观看| 久久九九国产精品| 国产不卡视频在线观看| 中文字幕一区二区不卡| 欧美日韩一区二区三区在线| 国产揄拍国内精品对白| 国产精品丝袜在线| 欧美最猛性xxxxx直播| 久久综合久久99| 国产传媒久久文化传媒| 亚洲欧美激情在线| 欧美绝品在线观看成人午夜影视| 麻豆精品在线看| 亚洲天堂免费在线观看视频| 欧美日韩亚洲综合| 亚洲欧洲中文日韩久久av乱码| 国产在线视频一区二区三区| 亚洲日本一区二区| 日韩理论片一区二区| 国产日韩精品一区二区浪潮av | 国产一区二区在线影院| 免费成人在线观看| 久久99久久精品| 美女任你摸久久| 日av在线不卡| 精品一二三四区| 国产综合一区二区| 国产一区二区三区在线观看免费| 久久99最新地址| 久久99精品国产麻豆不卡| 久久se精品一区精品二区| 麻豆成人91精品二区三区| 久久99国产精品麻豆| 精品亚洲免费视频| 国产精品亚洲一区二区三区妖精 | 91精品国产综合久久福利软件 | 日韩午夜在线观看| 欧美电影免费观看高清完整版 | 亚洲午夜精品在线| 一区二区成人在线视频 | 国产午夜亚洲精品羞羞网站| 久久精品一区二区三区不卡牛牛| 久久精品在线免费观看| 国产精品视频一二| 亚洲小说欧美激情另类| 午夜久久电影网| 极品美女销魂一区二区三区| 国产乱人伦偷精品视频不卡| 不卡一二三区首页| 91国产免费看| 91精品国产综合久久精品app| 日韩视频免费观看高清完整版在线观看| 亚洲精品一区二区精华| 国产精品久久久久一区二区三区共| 亚洲男人天堂一区| 日产欧产美韩系列久久99| 国产中文字幕一区| 色8久久精品久久久久久蜜| 欧美日韩成人一区| 国产精品天天看| 午夜视黄欧洲亚洲| 国产成都精品91一区二区三| 精品视频一区二区不卡| 久久久久综合网| 一区二区三区中文字幕电影| 成人av免费观看| 欧美日韩免费观看一区三区| 国产亚洲精品aa午夜观看| 亚洲午夜免费电影| 国产成人精品影视| 欧美日韩中字一区| 国产欧美日韩三级| 午夜精品久久久久| 成人国产精品免费观看动漫| 欧美人与性动xxxx| 国产精品久久三区| 国产精品一级在线| 欧美一级久久久久久久大片| 亚洲欧美韩国综合色| 国产麻豆精品在线| 制服丝袜中文字幕亚洲| 中文字幕亚洲视频| 国产99久久久精品| 欧美mv日韩mv国产网站| 亚洲影院免费观看| 99久久婷婷国产综合精品电影| 日韩精品专区在线影院重磅| 亚洲国产另类av| 91免费国产在线观看| 国产精品麻豆99久久久久久| 国产一区999| 亚洲精品一区二区三区精华液| 视频一区二区三区中文字幕| 一本大道久久a久久综合婷婷| 欧美国产精品v| 国产一区二区久久| 日韩精品一区二区三区在线| 免费在线看一区| 欧美精品一二三| 午夜精品久久久久影视| 精品视频在线免费| 亚洲综合免费观看高清完整版在线 | 日本在线播放一区二区三区| 91免费看片在线观看| 亚洲日本成人在线观看|