⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpleisapi.cpp

📁 C++Builder网络应用例程. C++Builder网络应用例程.
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#include <vcl\isapi.hpp>
#include "Unit1.h"
#pragma hdrstop
//---------------------------------------------------------------------------
//   Important note about DLL memory management:
//
//   If your DLL exports any functions that pass String objects (or structs/
//   classes containing nested Strings) as parameter or function results,
//   you will need to add the library BCBMM.LIB to both the DLL project and any
//   EXE projects that use the DLL.  This will change the DLL and its calling
//   EXE's to use the BCBMM.DLL as their memory manager.  In these cases,
//   the file BCBMM.DLL should be deployed along with your DLL.
//
//   To avoid using BCBMM.DLL, pass string information using "char *" or
//   ShortString parameters.
//---------------------------------------------------------------------------
USERES("simpleisapi.res");
USEUNIT("Unit1.cpp");
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
        return 1;
}
//---------------------------------------------------------------------------
extern "C" __declspec(dllexport) BOOL __stdcall GetExtensionVersion( THSE_VERSION_INFO  *pVer )
{

    pVer->dwExtensionVersion = MAKELONG( HSE_VERSION_MINOR,
                                         HSE_VERSION_MAJOR );

    lstrcpyn( pVer->lpszExtensionDesc,
              "This is a sample Web Server Application",
               HSE_MAX_EXT_DLL_NAME_LEN );

    return TRUE;
}
//---------------------------------------------------------------------------
void WriteClientData(TEXTENSION_CONTROL_BLOCK *lpEcb, char *WriteBuffer)
{
  int Count;

  Count = strlen(WriteBuffer);
  lpEcb->WriteClient(lpEcb->ConnID, (void *)WriteBuffer, Count, 0);
}
//---------------------------------------------------------------------------
extern "C" __declspec(dllexport) DWORD __stdcall HttpExtensionProc( TEXTENSION_CONTROL_BLOCK  *lpEcb )
{
  char *Buffer, InBuffer[255], OutBuffer[1024], *WorkString, *FoundAmpersand;
  int BufferSize;

  lpEcb->ServerSupportFunction(lpEcb->ConnID, HSE_REQ_SEND_RESPONSE_HEADER, NULL, 0, 0);
  WriteClientData(lpEcb, "Content-type: text/plain\n\n");

  if (strcmp(lpEcb->lpszMethod, "GET") == 0)
  {
    Buffer = new char [strlen(lpEcb->lpszQueryString + 1)];
    strcpy(Buffer, lpEcb->lpszQueryString);
  }
  else if (strcmp(lpEcb->lpszMethod, "POST") == 0)
  {
    if (lpEcb->cbAvailable > 0)
    {
      Buffer = new char [lpEcb->cbAvailable + 1];
      memcpy((void *)Buffer, (void *)lpEcb->lpbData, lpEcb->cbAvailable);
      Buffer[lpEcb->cbAvailable] = '\0';
    }
    else
    {
      WriteClientData(lpEcb, "Content length not specified\n");
      return HSE_STATUS_SUCCESS;
    }
  }
  else
  {
    WriteClientData(lpEcb, "Unrecognized Method\n");
    return HSE_STATUS_SUCCESS;
  }

  WriteClientData(lpEcb, "***Some HTTP Headers***\n");

  BufferSize = 255;
  if (lpEcb->GetServerVariable(lpEcb->ConnID, "HTTP_USER_AGENT",
                               InBuffer, BufferSize))
    wsprintf(OutBuffer, "HTTP_USER_AGENT = %s\n", InBuffer);
  else
    strcpy(OutBuffer, "HTTP_USER_AGENT = Unknown\n");

  WriteClientData(lpEcb, OutBuffer);

  if (lpEcb->GetServerVariable(lpEcb->ConnID, "HTTP_HOST",
                               InBuffer, BufferSize))
    wsprintf(OutBuffer, "HTTP_HOST = %s\n", InBuffer);
  else
    strcpy(OutBuffer, "HTTP_HOST = Unknown\n");

  WriteClientData(lpEcb, OutBuffer);

  WriteClientData(lpEcb, "\n***Information from form ***\n");

  wsprintf(OutBuffer, "Method: %s\n", lpEcb->lpszMethod);
  WriteClientData(lpEcb, OutBuffer);

  Buffer = url2str(Buffer);
  WorkString = Buffer;
  FoundAmpersand = strchr(WorkString, '&');
  while (FoundAmpersand)
  {
    FoundAmpersand[0] = '\0';
    wsprintf(OutBuffer, "%s\n", WorkString);
    WriteClientData(lpEcb, OutBuffer);
    WorkString += (FoundAmpersand - WorkString + 1);
    FoundAmpersand = strchr(WorkString, '&');
  }

  if (strlen(WorkString))
  {
    wsprintf(OutBuffer, "%s\n", WorkString);
    WriteClientData(lpEcb, OutBuffer);
  }

  delete [] Buffer;

  return HSE_STATUS_SUCCESS;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -