COM package ASP code

zhaozj2021-02-16  77

ActiveX is a widely used code package proposed by Microsoft to improve the reusability of program code, speeding up the development speed of program projects, generally referred to as "components". In the integrated development environment of VB6, we can see several ActiveX projects:

1, ActiveX EXE

This is the ActiveX / COM server component running outside the process, which means that the process of their runs is different from the client code of the initialization component. Although you can access ActiveX EXE with ASP, it is not recommended to change the IIS library, which allows all executable files to be started by script code running on the server.

2, ActiveX OCXS

These special components are included in the GUI environment to display the additional support required for the host application display and the operation component. You can also put the OCX component on the web page. However, OCX is the application interface, which cannot be created using ASP.

3, ActiveX Document DLL and ActiveX Document EXE

The Active documentation can display the VB form in the OLE file box application, such as IE or Office Binder. But they cannot be applied in ASP.

4, ActiveX DLLS

These ActiveX / COM components and clients operated in the same process. And the ActiveX DLL we have to discuss is the entire component. General Microsoft's additional components and other components provided by other third-party manufacturers are this type of ActiveX DLL, but it is not all written by 肰 b, which can also be developed using VC / Java and so on.

Explore what is ActiveX DLL, we begin to formally write our own ActiveX DLL to implement the same features in the ASP, well known, ASP has built-in Response, Request, Server, Session, Application five objects, in fact, these five built-in objects It is the five ActiveX DLL components initialized in IIS console. Since IIS can initialize these five components for ASP, we can of course directly quote these components directly in our ActiveX DLL to implement our programming, that is, The functionality of accessing the ASP built-in object can be implemented by reference to these components in the VB application.

As long as you have a web server above PWS4 or IIS4, you have a name called "Microsoft Active Server Pages Object", we can reference this object library in the VB's ActiveX DLL application, by reference to this object library, We have gained an object (class): ScriptingContext, this object is also the core object of our entire article. The relationship within the object library is as follows:

Object library class member

Asptypelibrary ScriptingContext Application

REQUEST

Response

Session

Server

Through the above relationship map, we can easily understand the class scriptingcontent. Let's take a concrete example:

1. Create a new ActiveX DLL project using VB6

2. Reference "Microsoft Active Server Pages Object" object library.

3. Create two component events: onstartpage and oneundpage

4. Create a reference to class ScriptingContent in event onstartpage.

5, instantiate the class ScriptingContent.

Test.cls (class implementation)

'Statement of the object

DIM RP As Response

DIM RQ As Request

DIM AP as Application

DIM SR AS Server

DIM SN AS Session

'When the component is created, this event will trigger the event public sub-onstartpage (MySC as scriptingcontent)

'Instantiation of objects

Set rp = mysc.response

Set rq = mysc.request

SET SR = mysc.server

Set ap = mysc.Application

SET SN = mysc.session

rp.write "
ActiveX DLL components have been created!

End Sub

'Trigger this event when the component is destroyed

Public Sub OneendPage ()

Rp.write "
ActiveX DLL components have been destroyed!
"

'Destroying object

Set rp = Nothing

SET RQ = Nothing

SET SR = Nothing

SET AP = Nothing

SET SN = Nothing

End Sub

'Define our own component method

Public Sub HelloWorld ()

Rp.write "

Hello, World! "

End Sub

This way, we create an ActiveX DLL that can access the ASP built-in object. We named this component project to first, compiling this item in VB to become a DLL file first.dll, and we register this DLL file in the system. Next, we need a simple ASP program that almost no code to call this component:

Test.asp

Test ActiveX DLL </ Title></p> <p></ hEAD></p> <p><body></p> <p><%</p> <p>DIM Testme</p> <p>'Creating the components we have just compiled, once you create this component, you will be in the Ye Side Output "ActiveX DLL components have been</p> <p>'created! "</p> <p>Set testme = server.createObject ("first.test")</p> <p>'Method of calling components</p> <p>Testme.helloworld</p> <p>'Logout assembly, while logging out, it will automatically display "ActiveX DLL component has been destroyed!"</p> <p>Set testme = Nothing</p> <p>%></p> <p></ body></p> <p></ html></p> <p>Through a simple example above, we can see the same functionality using the ActiveX DLL, and the same features that are brought by the code confidentiality and program run are more efficient. ActiveX DLL and Pure ASP have their own advantages and disadvantages, as long as we use both technologies, such as properly encapsulating business logic in ActiveX DLL, or using DLL package technology in a confidential place, you must write efficient Fast web application.</p> <p>(The above program is passed in VB6 Enterprise Edition, Windows2000 Server Chinese version test passed)</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-16768.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="16768" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.055</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'ZFYKBhfSe2CaYg19g8LCdJATAFGXNdHYaxTqfjucsUAore0Gxkw5fu027DwqwW19TcE_2BdKP5kepW7ks0'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>