| 订阅 | 在线投稿
分享
 
 
 

将ASP写成DLL

来源:互联网  宽屏版  评论
2004-08-21 13:14:12

本文为【将ASP写成DLL】的汉字拼音对照版显示拼音

CSDN - wendangzhongxin - ASP

biaoti

liyongVisual BasicbaASPbianxiechengDLL abigfrogshoucang

guanjianzi

ASP zujian DLL VB

zhepianwenzhangzhuyaoshiweixiangjiangzijideASPshuipingtigaoderenxiede!baASPdaimabianchengzujian,kaifazhebujinshijiakuaileASPdesudu,erqieyenengbaohuzijidedaima.zhepianwenzhangxiechulai,yeshiweilegeixiangkaifazujianwangyoushangyitangrumenke! xiamian,womenhuilaibianxieyigefeichangjiandandezujian,chongdianshizhidaozenyangkaifaDLLzujian,erbushiqifuduodedaima!zhexiedouyaokaonimenzijiyihoudenulile.

fuwuqiduanzujian

shouxian,fuwuqiduandezujianyaoyoubieyukehuduandezujian.kehuduandezujianshitongguowangluochuanshu,yikaoHTMLlaiqizuoyong.erqiezhinengzaiIEshangyouyong.danshifuwuqiduandezujianshiyunxingzaifuwuqiduan,tazaifuwuqishangzhixinggezhongcaozuo.yinci,suoyoudeliulanqidounengxiangyong,tayikaodeshifuwuqierbushiliulanqi.

dangIISbeiqingqiuzhixingyigeASPchengxu,tashouxianhuizaiASPwenjianzhongzhaodao% %>biaoqianzhijiandedaima,bingqiezhixingta(yekeyishiscript runat=server>/script>zhijiandedaima).ruguozhegeASPchengxuzaixianqianbeitiaoyongguo,nametajiuhuiyongneicunzhongdebianyiguodechengxulaixiangyonghufanhuiHTMLdaima,ruguomeiyou,nametajiuchongxinbianyi.zheliASPjiubiCGIduoyidiansuduyoushi,yinweiCGIshimeiyigeqingqiudou使shiyongyige线xiancheng.zheyangjiudadaxiaohaolefuwuqideziyuan.

xiangbuxiangnixiedechengxuzijijiunengzaiIISyunxing!?!xianzainijiuxingle!使shiyongVB5(dangranxianzaishiVB6le),nijiunengjianliDynamic Linked Libraries (DLLwenjian),tanengzaiIISshangzhijieyunxing(ruguoyouaspwenjianlaiqingqiudehua).

xitongheruanjiandeyaoqiu

nixuyaoyige32weidecaozuoxitonglaiyunxingASP.dangranniyedeanzhuangIIShuoPWS.womenxiamiandechengxushizaiwindows95+PWS+VB5dehuanjingxiakaifade.

womenkaishiba

qidongnideVB,xuanzeActiveXtubiao.zhegetubiaokeyizaixinjiangongchengzhaodao!VBhuitigongyigemorendegongchengming(project1)heleiming(class1).womenhuijiangzhelianggemingzidougaidiao.zaigaimingzhiqian,qingshouxianquerenwomenyongyouMicrosoft Active Server Pages Object Library,tazaiwomendechengxufeichangyouyong.congcaidanzhongxuanze"gongcheng",ranhouzaiqizhongxuanze"yinyong",jiuhuichuxian"yinyong"chuangkoucongzhongxuanzeMicrosoft Active Server Pages Object Library.

geigongchengheleimingming

xianzaiwomenlaigenjuzijideaihaolaiweiproject1heclass1laimingmingba!geitamenmingmingyeshihenchongyaode,womenyihouhuiyongzhegegongchengmingheleiminglaichuangjianzhegezujiandeshili!houmianxiangxijieshao.

ruhegaiming,wojiubuxiangduoshuole!womendegongchengminggaiweiExmaple,leimingweiHelloword

zenyang使shiyonggongchenghelei

xianzaiwomenyoulewomenzijidegongcheng(Example1)heleiming(HelloWorld).yihouwomenjiuhuizaiASPdaimazhong使shiyongtamendemingzilaiyinyongzhegezujian.zaiASPzhongwomenjiuzheyangyinyong,ruxia:

Set ObjReference = Server.CreateObject("ProjectName.ClassName")

duiyuwomengongchengdeyinyongjiushi:Set ObjReference = Server.CreateObject("Example1.HelloWorld")

xianzaiwomenjiunengyongObjReferencelaitiaoyongwomenzaizujianzhongsuochuangjiandehanshu,zichengxu.xiamianwomenhuilaixieyigeSayHellodezichengxu,womenzhixingtadedaimaruxia:

%

Set ObjReference = Server.CreateObject("Example1.HelloWorld")

ObjReference.SayHello

%>

weilezaiHellowordleizhong使shiyongASPdefangfa,nibixuzaicileizhongxieyigeOnStartPagezihanshu.ruxia:

Public Sub OnStartPage(PassedScriptingContext As ScriptingContext)

Set MyScriptingContext = PassedScriptingContext

End Sub

xianzai,wulunshenmeshihouyonghu访fangwenyigedaiyoubenzujiandeASPwenjian,IISjiuhuibaScriptingContextchuansonggeiwomendeduixiangqingwomen使shiyong.zhegeScriptingContextbaokuolequanbudeASPfangfaheshuxing.shixianshang,zhe使shidewomenyounengli访fangwensuoyouASPdeduixiang.kanxiamiandedaima:

Public Sub OnStartPage(PassedScriptingContext As ScriptingContext)

Set MyScriptingContext = PassedScriptingContext

Set MyApplication = MyScriptingContext.Application

Set MyRequest = MyScriptingContext.Request

Set MyResponse = MyScriptingContext.Response

Set MyServer = MyScriptingContext.Server

Set MySession = MyScriptingContext.Session

End Sub

yihouwomenjiunengyongzaiVBzhongyongMyApplicationlaidaitiASPzhongdeApplication,tonglikeyidaitiRequest,Server.....,buguowomenlaishiyaozaiOnStartPagezhiqianlaishenmingzhexiebianliang:

Private MyScriptingContext As ScriptingContext

Private MyApplication As Application

Private MyRequest As Request

Private MyResponse As Response

Private MyServer As Server

Private MySession As Session

使shiyongASPdeduixiangwomendebianliangxianzaijiunengxiangbiaozhundeASPduixianglai使shiyongle!biru,womenjingchangzaiASPzhongyongRequest.form()laishoujitijiaobiaodandeshuju.xianzaiwomenzaiwomendeVBzhongshixianzhegegongneng,daimaruxia:

yongASPzhongshixian:

%

MyTempVariable = Request.Form("userName")

Response.Write ("you entered "& MyTempVariable & "as your user name")

%>

zaiVBzhongshixian:

MyTempVariable = MyRequest.Form("userName")

MyResponse.Write ("you entered "& MyTempVariable & "as your user name")

tongguo使shiyongMyResponselaidaitiResponse,womennenggou使shiyongsuoyouResponsedefangfa,dangran,MyResponsezhegemingzikeyisui便bianlaiqu,nishenzhikeyijiuquResponse.lingyijianwomendezhuyideshi,womendezaiwomendejianlideleizhong,xieshangOnEndPagezihanshu,zhegeOnStartPageshixiangfande!OnStartPageshichuangjianduixiang,OnEndPageshixiaohuiduixiang.

Public Sub OnEndPage()

Set MyScriptingContext = Nothing

Set MyApplication = Nothing

Set MyRequest = Nothing

Set MyResponse = Nothing

Set MyServer = Nothing

Set MySession = Nothing

End Sub

SayHellofangfawomenlaijianliyigezihanshu,yongyuxianshi"Holle World".zhegeSayHellofangfazhishiHelloWorldzhegeleizhongyigezihanshu,womenyihouhuizaiASPzhongyongyixiadexianshizhegefangfa

%

Set ObjReference = Server.CreateObject("Example1.HelloWorld")

ObjReference.SayHello

%>

SayHellodechengxu,henjiandande!

Public Sub SayHello()

MyResponse.Write ("Hello World")

End Sub

xianzaiyigexiaoxingdezujianbianxiewancheng,shengxiadegongzuojiushibianyizhegezujian,zai"gongcheng"caidanzhongbaocunta,qushenmemingzidoukeyi,womenyongExmaple1.vbpba!ranhoujiuyongzaicaidanzhongxuanze"make exmaple1.dll",jiangqibianyichengDLLwenjian.yigezujianjiuzhenzhengwanchengle!

zhuyi,bianyilecizujiannamenijiudexianbanidePWSguandiao,ranhouzaibianyicizujian.fouzeVBjiuhuigaosunixiezujianzai使shiyongzhong.

zaiASPzhong使shiyongwomendezijidezujian.

dangnigengzhenglezaibianyizhongdecuowu,chenggongdibianyileexample1zhegegongcheng,xianzainijiudenachunizuixihuandeHTMLbianjiqilaixiexiaxiamiandeyuju,baocunweiASPwenjian.

HTML>HEAD>TITLE>Example 1/TITLE>/HEAD>

BODY>

%

Set ObjReference = Server.CreateObject("Example1.HelloWorld")

ObjReference.SayHello

%>

/BODY>/HTML>

yunxinghoujikekandaojieguo:

Hello World

zhucezujian

ruguonixianghenidepengyou,linjufenxiangnidezujian,namenijiudezainidexitongshangzhucenidezujian.womenyiban使shiyongRegsvr32.exelaizhucezujian.zhucehounidezujianhuichuxianzaiWin95/Win98dewindows/systemmuluzhong.xiamianshiyigezhucedelizi:

Regsvr32.exe C:/wwwroot/Example1/Example1.dll

zainidexitongzhong,VBhuizidonggeinizhuce,suoyinihenshaoyongdaoRegsvr32.exe

womenzhelizhishixieleyigefeichangxiaodezujian,nimenkeyixiehaozijidegengdadezujian,erqiehuankeyiyongVBzhongdehenduokongjian.

rangwomenyongzujianlaikuozhanwomendechengxudegongnengba!yexiwangduoduodekandaowomenzhongguorendezujian.

原文
 
[url=http://www.csdn.net/]CSDN[/url] - [url=http://www.csdn.net/develop/]文档中心[/url] - ASP 标题 利用Visual Basic把ASP编写成DLL abigfrog(收藏) 关键字 ASP 组件 DLL VB   这篇文章主要是为想将自己的ASP水平提高的人写的!把ASP代码变成组件,开发者不仅是加快了ASP的速度,而且也能保护自己的代码.这篇文章写出来,也是为了给想开发组件网友上一堂入门课! 下面,我们会来编写一个非常简单的组件,重点是知道怎样开发DLL组件,而不是其复杂的代码!这些都要靠你们自己以后的努力了.   服务器端组件   首先,服务器端的组件要有别于客户端的组件.客户端的组件是通过网络传输,依靠HTML来起作用.而且只能在IE上有用.但是服务器端的组件是运行在服务器端,它在服务器上执行各种操作.因此,所有的浏览器都能享用,它依靠的是服务器而不是浏览器.   当IIS被请求执行一个ASP程序,它首先会在ASP文件中找到〈% %>标签之间的代码,并且执行它(也可以是〈script runat=server>〈/script>之间的代码).如果这个ASP程序在先前被调用过,那么它就会用内存中的编译过的程序来向用户返回HTML代码,如果没有,那么它就重新编译.这里ASP就比CGI多一点速度优势,因为CGI是每一个请求都使用一个线程.这样就大大消耗了服务器的资源.   想不想你写的程序自己就能在IIS运行!?!现在你就行了!使用VB5(当然现在是VB6了),你就能建立Dynamic Linked Libraries (DLL文件),它能在IIS上直接运行(如果有asp文件来请求的话).   系统和软件的要求   你需要一个32位的操作系统来运行ASP.当然你也得安装IIS或PWS.我们下面的程序是在windows95+PWS+VB5的环境下开发的.   我们开始吧   启动你的VB,选择ActiveX图标.这个图标可以在新建工程找到!VB会提供一个默认的工程名(project1)和类名(class1).我们会将这两个名字都改掉.在改名之前,请首先确认我们拥有Microsoft Active Server Pages Object Library,它在我们的程序非常有用.从菜单中选择"工程",然后在其中选择"引用",就会出现"引用"窗口从中选择Microsoft Active Server Pages Object Library.   给工程和类命名   现在我们来根据自己的爱好来为project1和class1来命名吧!给它们命名也是很重要的,我们以后会用这个工程名和类名来创建这个组件的实例!后面详细介绍.   如何改名,我就不想多说了!我们的工程名改为Exmaple,类名为Helloword   怎样使用工程和类   现在我们有了我们自己的工程(Example1)和类名(HelloWorld).以后我们就会在ASP代码中使用它们的名字来引用这个组件.在ASP中我们就这样引用,如下:   Set ObjReference = Server.CreateObject("ProjectName.ClassName")   对于我们工程的引用就是:Set ObjReference = Server.CreateObject("Example1.HelloWorld")   现在我们就能用ObjReference来调用我们在组件中所创建的函数,子程序.下面我们会来写一个SayHello的子程序,我们执行它的代码如下: 〈% Set ObjReference = Server.CreateObject("Example1.HelloWorld") ObjReference.SayHello %>   为了在Helloword类中使用ASP的方法,你必须在此类中写一个OnStartPage子函数.如下: Public Sub OnStartPage(PassedScriptingContext As ScriptingContext) Set MyScriptingContext = PassedScriptingContext End Sub      现在,无论什么时候用户访问一个带有本组件的ASP文件,IIS就会把ScriptingContext传送给我们的对象请我们使用.这个ScriptingContext包括了全部的ASP方法和属性.实现上,这使得我们有能力访问所有ASP的对象.看下面的代码: Public Sub OnStartPage(PassedScriptingContext As ScriptingContext) Set MyScriptingContext = PassedScriptingContext Set MyApplication = MyScriptingContext.Application Set MyRequest = MyScriptingContext.Request Set MyResponse = MyScriptingContext.Response Set MyServer = MyScriptingContext.Server Set MySession = MyScriptingContext.Session End Sub   以后我们就能用在VB中用MyApplication来代替ASP中的Application,同理可以代替Request,Server.....,不过我们来是要在OnStartPage之前来申明这些变量: Private MyScriptingContext As ScriptingContext Private MyApplication As Application Private MyRequest As Request Private MyResponse As Response Private MyServer As Server Private MySession As Session      使用ASP的对象我们的变量现在就能像标准的ASP对象来使用了!比如,我们经常在ASP中用Request.form()来收集提交表单的数据.现在我们在我们的VB中实现这个功能,代码如下:   用ASP中实现: 〈% MyTempVariable = Request.Form("userName") Response.Write ("you entered "& MyTempVariable & "as your user name") %>   在VB中实现: MyTempVariable = MyRequest.Form("userName") MyResponse.Write ("you entered "& MyTempVariable & "as your user name")   通过使用MyResponse来代替Response,我们能够使用所有Response的方法,当然,MyResponse这个名字可以随便来取,你甚至可以就取Response.另一件我们得注意的是,我们得在我们的建立的类中,写上OnEndPage子函数,这个OnStartPage是相反的!OnStartPage是创建对象,OnEndPage是消毁对象.    Public Sub OnEndPage() Set MyScriptingContext = Nothing Set MyApplication = Nothing Set MyRequest = Nothing Set MyResponse = Nothing Set MyServer = Nothing Set MySession = Nothing End Sub      SayHello方法我们来建立一个子函数,用于显示"Holle World".这个SayHello方法只是HelloWorld这个类中一个子函数,我们以后会在ASP中用以下的显示这个方法 〈% Set ObjReference = Server.CreateObject("Example1.HelloWorld") ObjReference.SayHello %>   SayHello的程序,很简单的! Public Sub SayHello() MyResponse.Write ("Hello World") End Sub      现在一个小型的组件编写完成,剩下的工作就是编译这个组件,在"工程"菜单中保存它,取什么名字都可以,我们用Exmaple1.vbp吧!然后就用在菜单中选择"make exmaple1.dll",将其编译成DLL文件.一个组件就真正完成了!   注意,编译了此组件那么你就得先把你的PWS关掉,然后再编译此组件.否则VB就会告诉你些组件在使用中.   在ASP中使用我们的自己的组件.   当你更正了在编译中的错误,成功地编译了example1这个工程,现在你就得拿出你最喜欢的HTML编辑器来写下下面的语句,保存为ASP文件.   〈HTML>〈HEAD>〈TITLE>Example 1〈/TITLE>〈/HEAD>   〈BODY> 〈% Set ObjReference = Server.CreateObject("Example1.HelloWorld") ObjReference.SayHello %>   〈/BODY>〈/HTML>   运行后即可看到结果:   Hello World   注册组件   如果你想和你的朋友,邻居分享你的组件,那么你就得在你的系统上注册你的组件.我们一般使用Regsvr32.exe来注册组件.注册后你的组件会出现在Win95/Win98的windows/system目录中.下面是一个注册的例子:   Regsvr32.exe C:/wwwroot/Example1/Example1.dll   在你的系统中,VB会自动给你注册,所以你很少用到Regsvr32.exe   我们这里只是写了一个非常小的组件,你们可以写好自己的更大的组件,而且还可以用VB中的很多控件.   让我们用组件来扩展我们的程序的功能吧!也希望多多的看到我们中国人的组件.
󰈣󰈤
 
 
 
>>返回首页<<
 
 热帖排行
 
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
©2005- 王朝网络 版权所有