Call DLL in the ASP file

zhaozj2021-02-16  187

Dynamic Library (DLL) is an important way to speed up the execution speed of the application key part, but some people may not know that it is to speed up the server's execution of the server by calling the DLL in the ASP file. I will simply This section describes how to call the DLL in the ASP file. First, you must have a DLL file. This example creates an ActiveX DLL file via VB5.0, which simulates a throwing process. In the VB5.0 environment, create a new project and double-click the ActiveX DLL icon in the New Project window, VB will automatically add a class module to the project and set the project type to ActiveX DLL. Change the name property of the class module to CLSDICE in the attribute window. From the engineering menu, select the project properties to change the project name to MyDLL. From the File menu, select Save CLSDICE and save the class module as MyDICE.CLS. Add the following code:

Option expedition

Private max, Point as integer

Public property get result () AS Integer

Result = POINT

End Property

Public property get maxpoint () AS integer

MaxPoint = max

End Property

Public property let maxpoint (Num as integer)

MAX = NUM

End Property

Public Sub Throw ()

Randomize

Point = int (rND * max) 1

End Sub

Private sub coplass_initialize ()

MAX = 6

End Sub

This class module defines two attributes of the Clsdice object and a method that simulates the process of throwing. The maxpoint attribute represents the number of colors, adding the Property Let statement will enable the customer to modify the number of colors; the Result property indicates the number of points that last throws the color of the colors; the THROW method represents the action of the roll; the private sub class_initialize statement The size of the son is the default setting to 6 sides.

From the File menu, select Generate MyDLL.dll and save it to the appropriate place. At this point, we created a DLL file.

The second step is to reference the class clsdice in the ASP file.

All code for ASP (Active Server Page Active Server Pages) is running on the server, and customers can only view the results that are backup in HTML. It uses "<%" and "%>" tag to identify script code, do not return to the client, outside the code, using the HTML tag to identify content. The CREATEOBJECT function created a CREATEOBJECT function in the code of Dice.asp, which is from the ActiveX.dll-MyDll.dll file created above, and the following example uses the VBScript scripting language.

'Load the type library specified in the Metadata tag. Path is the path stored by mydll.dll on the machine

Using DLL </ Title> </ head> in ASP file</p> <p><body></p> <p><%</p> <p>On Error ResMe Next 'Can continue to execute when an unexpected error occurs?</p> <p>If Request.form ("T1") = "" "" ") = 6</p> <p>Else</p> <p>Session ("Point") = Request.form ("T1")</p> <p>END IF</p> <p>'Use session ("Point") to store the number of colors</p> <p>Set dice1 = server.createObject ("Mydll.Clsdice")</p> <p>'Create a DICE1 object using the SET statement, where mydll is the project name when you create a DLL file above (Note: Not the name of the file), the name of CLSDice is a class module. To this we can use the MaxPoint, Result, and the Throw property (Method) to operate the DICE1 object.</p> <p>If Request.servervariables ("Request_Method") = "post" then</p> <p>Dice1.maxpoint = session ("Point") 'Sets the number of faces</p> <p>Dice1.Throw 'throwing</p> <p>%></p> <p><form method = "post" action = "DICE.ASP"></p> <p><p> When the number of colors is <input type = "text" name = "t1" size = "5" value = <% = session ("point")% >> </ p></p> <p><p> <input type = "submit" value = "throw" Name = "b1"> </ p></p> <p></ form></p> <p><p> The result is: <% = DICE1.RESULT%> point </ p> 'Return Results</p> <p><%</p> <p>Else</p> <p>Dice1.maxpoint = session ("Point")</p> <p>%></p> <p><form method = "post" action = "DICE.ASP"></p> <p><p> When the number of colors is <input type = "text" name = "t1" size = "5" value = <% = session ("point")% >> </ p></p> <p><p> <input type = "submit" value = "throw" Name = "b1"> </ p></p> <p></ form></p> <p><%</p> <p>END IF</p> <p>%></p> <p></ body></p> <p>The above code is compiled in Windows NT4.0 SP3 IIS4.0 IE5.0 VB5.0, but there are still many shortcomings, but my original intention is to introduce you how to call DLL in the ASP, so I didn't improve it.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-8324.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="8324" 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.043</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 = 'LG2k4YEJBGCjP6efDLnmst6x4yy0TtmfDoRqmlNnqM7DAgFxucdQCU5m1lghTpLGAHwEb_2By74Z6SlM9I'; 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>