Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How can we make Windows API calls in .NET
How can we make Windows API calls in .NET?
✍: Guest
Windows API call are not COM based and they are invoked through Platform Invoke Services.
Declare StringConversionType (Function | Sub) MethodName Lib "DllName" ([Args])
As Type
ã StringConversionType is for what type of conversion should take place. Either we
can specify Unicode to convert all strings to Unicode values, or Auto to convert
strings according to the .NET runtime rules.
ã MethodName is the name of the API to call.
ã DllName is the name of the DLL.
ã Args are any arguments to the API call.
ã Type is the return type of the API call.
Below is a sample code for VB.NET which uses Sleep windows API for delaying.
Public Class Form1
Declare Auto Sub Sleep Lib “kernel32.dll” (ByVal dwMilliseconds
As Long)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
MessageBox.Show(“ start sleeping for 5000 Milli
seconds.....”)
Sleep(5000)
MessageBox.Show(“ end of sleeping.....”)
End Sub
End Class
Note:- Source code is provided in CD in “APICALL” folder
In VB.NET we use declare keyword but in C# it goes little bit different, we use DLLIMPORT
here.
Note :- We have interopservices in this and EXTERN keyword.
#region Using directives using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; #endregion namespace CSharpCode { partial class Form1 : Form { [DllImport(“Kernel32.dll”)] static extern int Sleep(long dwMilliseconds); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { MessageBox.Show(“Starting of 5000 ms...”); Sleep(5000); MessageBox.Show(“End of 5000 ms...”); } } }
2007-10-22, 5549👍, 0💬
Popular Posts:
1. What is normalization. 2. Difference between procedure and functions. 3. Oracle 9i Vs 10g. 4. how...
In C#, what is a weak reference? Generally, when you talk about a reference to an object in .NET (an...
How can you determine the size of an allocated portion of memory? You can't, really. free() can , bu...
What is more advisable to create a thread, by implementing a Runnable interface or by extending Thre...
What Is Posting? Posting is an event that writes Inserts, Updates and Deletes in the forms to the da...