<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      C++Builder使用ADSI創建web網站

      [摘要]以下是我學習MSDN中的文章?偨Y出適合在C++Builder下創建WebServer的例子:其中使用ADSI的一些接口,注意要將Activeds.Lib添加入工程,還要包含以下幾個頭文件。比較簡單...
      以下是我學習MSDN中的文章?偨Y出適合在C++Builder下創建WebServer的例子:
      其中使用ADSI的一些接口,注意要將Activeds.Lib添加入工程,
      還要包含以下幾個頭文件。
      比較簡單,希望能拋磚引玉。

      file://---------------------------------------------------------------------------

      #include <vcl.h>
      #pragma hdrstop

      #include "Unit1.h"

      file://---------------------------------------------------------------------------
      #pragma package(smart_init)
      #pragma resource "*.dfm"
      #include "iads.h"
      #include "adssts.h"
      #include "Adshlp.h"


      TForm1 *Form1;

      __fastcall TForm1::TForm1(TComponent* Owner)
              : TForm(Owner)
      {
      }



      file://幾個參數:ip:ip地址字符串,domain:域名(www.youname.com),DiskPath:虛擬目錄路徑(C:\wwwroot)
      BOOL CreateWebServer(String ip,String domain,String DiskPath)
      {
      IADsContainer *pCont=NULL;
      IADs* pAds=NULL;
      IADs* pVrAds=NULL;
      IADsServiceOperations *pSrvOp;
      IDispatch *pDisp = NULL;
      IDispatch *pVrDisp = NULL;
      AnsiString WNumer=IntToStr(random(1000)); //取一個隨機數建立站點
      String newBindings=ip+":80:"+domain;

      /* 獲得WebServer */
      if(ADsGetObject(L"IIS://localhost/w3svc",IID_IADsContainer,(void**)&pCont)==S_OK)
      {   //創建站點
        if(pCont->Create(L"IIsWebServer",(wchar_t*)WideString(WNumer),&pDisp)==S_OK)
          {
             pDisp->QueryInterface(IID_IADs, (void**)&pAds);
             pDisp->QueryInterface(IID_IADsServiceOperations, (void**)&pSrvOp);
             pAds->Put(L"ServerSize",Variant(int(1)));
             pAds->Put(L"ServerComment",Variant(String("xiwei")));//服務器注釋,沒太多用處,xiwei我的名字
             pAds->Put(L"ServerBindings",Variant(String(newBindings)));
             pAds->SetInfo();

          file://創建主目錄
          
         pCont->GetObject(L"IIsWebServer",(wchar_t*)WideString(WNumer),&pDisp);//得到剛才創建地網站
         if(pDisp->QueryInterface(IID_IADsContainer,(void**)&pCont)==S_OK)
         {
           if(pCont->Create(L"IIsWebVirtualDir",L"Root",&pVrDisp)==S_OK)
             {
               pVrDisp->QueryInterface(IID_IADs, (void**)&pVrAds);
               pVrAds->Put(L"AccessRead",Variant(BOOL("True")));
               pVrAds->Put(L"AccessWrite",Variant(BOOL("True")));
               pVrAds->Put(L"AccessScript",Variant(BOOL("True")));
               pVrAds->Put(L"EnableDirBrowsing",Variant(BOOL("True")));
               pVrAds->Put(L"Path",Variant(String(DiskPath)));
               pVrAds->Put(L"AppRoot",Variant(String(DiskPath)));
               pVrAds->SetInfo();
               pVrAds->Release();
               pAds->Release();
               pCont->Release();
             }
           file://啟動新建的WebServer
          pSrvOp->Start();
          pSrvOp->Release();
          }
         }
      }

      }
      void __fastcall TForm1::Button2Click(TObject *Sender)
      {
      CreateWebServer(Edit1->Text,"www.cccaaa.com",Edit2->Text);
      }
      file://---------------------------------------------------------------------------

      以上內容缺少錯誤處理,諸如ip地址已被占用等,我認為技術這東西用不著保守,沒等生利息呢,已經貶值了。
      哈哈,希望各位給以指正!我的Email:proton@yeah.net


      日韩精品一区二区三区高清