Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
Tutorial RSS
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Charts
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Controls - A sample of invoking Win32 API in ASP.NET 2.0 (C#)
A sample of invoking Win32 API in ASP.NET 2.0 (C#)


ASP.NET Controls Tutorial

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 used over 10 web hosting companies before we found Server Intellect. Their dedicated servers and add-ons were setup swiftly, in less than 24 hours. We were able to confirm our order over the phone. They respond to our inquiries within an hour. Server Intellect's customer support and assistance are the best we've ever experienced.

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 />
&nbsp;
<asp:Label ID="lblTime" runat="server" Width="136px"></asp:Label></div>
</form>
</body>
</html>

Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.

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.

[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!

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!



 
  Developer Resources







Server Intellect Rocks