
Navigator : Home > Tutorials > Controls Tutorials > ...
A sample of invoking Win32 API in ASP.NET 2.0 (C#)
This tutorial show you a simple example to explain how to invoke Win32 API in ASP.NET 2.0 and C#.
To invoke Win32 API using ASP.NET 2.0 and C# 2.0 is actually very simple.
First, you will need to import the namespaces
using System.Net; using System.Text.RegularExpressions; using System.Text; using System.Runtime.InteropServices; |
We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.
Then, add two controls to web page, a Button and a Label control
<%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>A sample of invoking Win32 API in ASP.NET 2.0 VB</title> </head> <body> <form id="form1" runat="server">
<div> <strong>Test Your Click Interval</strong><br /> <br /> <asp:Button ID="btnSubmit" runat="server" Text="Click Me!" /> <br /> <br /> <asp:Label ID="lblTime" runat="server" Width="136px"></asp:Label></div> </form> </body> </html> |
Add a function for displaying the time interval between mouse clicks of the button
Declare an API function to import Windows Dll at first. Add the other code to count the interval between mouse clicks.
If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.
[DllImport("kernel32.dll")] static extern bool QueryPerformanceCounter(out long lpPerformanceCounter); [DllImport("kernel32.dll")] static extern bool QueryPerformanceFrequency(out long lpFrequency);
protected void Page_Load(object sender, EventArgs e) {
long CurrentTime; if (!Page.IsPostBack) {
lblTime.Text = ""; CurrentTime = 0; Session["LastTime"] = new long(); Session["Frequency"] = new long(); long temp; if (!QueryPerformanceFrequency(out temp)) {
lblTime.Text = "Error:Server doesn't support performance counter"; btnSubmit.Enabled = false; } Session["Frequency"] = temp; } else {
if (QueryPerformanceCounter(out CurrentTime) && (long)Session["LastTime"] != 0) {
lblTime.Text = lblTime.Text + ((CurrentTime - (long)Session["LastTime"]) / (long)Session["Frequency"]).ToString() + "second since last click.<br>"; } else {
lblTime.Text = lblTime.Text + "Please click again.<br>"; } Session["LastTime"] = CurrentTime; } } |
Looking for the VB.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!