ITPub博客

首页 > Linux操作系统 > Linux操作系统 > C++Builder使用ADSI创建web站点 (转)

C++Builder使用ADSI创建web站点 (转)

原创 Linux操作系统 作者:WebSnap 时间:2019-05-22 19:36:06 0 删除 编辑
C++Builder使用ADSI创建web站点 (转)

C++Builder使用ADSI创建站点

以下是我学习MSDN中的文章。总结出适合在C++Builder下创建WebServer的例子:
其中使用ADSI的一些接口,注意要将Activeds.Lib添加入工程,
还要包含以下几个头。
比较简单,希望能抛砖引玉。

#include
#pragma hdrstop

#include "Unit1.h"


#pragma package(smart_init)
#pragma re "*.dfm"
#include "iads.h"
#include "adssts.h"
#include "Adshlp.h"


TForm1 *Form1;

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


个参数:ip:字符串,ain:域名(),DiskPath:虚拟目录路径(C:www)
BOOL CreateWebServer(String ip,String domain,String DiskPath)
{
IADntainer *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(ADsGet(L"IIS://localhost/w3svc",IID_IADsContainer,(void**)&pCont)==S_OK)
{  /建站点
  if(pCont->Create(L"IIsWebServer",(wchar_t*)WString(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();

  建主目录
 
  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();
  }
  动新建的WebServer
  pSrvOp->Start();
  pSrvOp->Release();
  }
  }
}

}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
CreateWebServer(Edit1->Text,"",Edit2->Text);
}

以上内容缺少错误处理,诸如ip地址已被占用等,我认为技术这东西用不着保守,没等生利息呢,已经贬值了。
哈哈,希望各位给以指正!我的E:">proton@yeah.net


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10797429/viewspace-101625/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-01-04

  • 博文量
    175
  • 访问量
    141691