Cara Deklarasi dan Penggunaannya dapat dilihat di Website :
http://pinvoke.net
Website ini menyediakan cara deklarasi dan penggunaan hampir semua fungsi Windows API pada VB.NET dan C#.NET. Misalnya fungsi yang sering dipakai penulis yaitu fungsi untuk memanggil suat file sesuai dengan program default untuk menjalankannya, misal doc ya akan berjalan di Mocrosoft Word, seakan-akan file tersebut diklik dua kali.
Fungsi ShellExecute milik Shell32.dll Windows, ketika dipanggil membutuhkan deklarasi :
Deklarasi Untuk C# :
public enum ShowCommands : int
{
SW_HIDE = 0,
SW_SHOWNORMAL = 1,
SW_NORMAL = 1,
SW_SHOWMINIMIZED = 2,
SW_SHOWMAXIMIZED = 3,
SW_MAXIMIZE = 3,
SW_SHOWNOACTIVATE = 4,
SW_SHOW = 5,
SW_MINIMIZE = 6,
SW_SHOWMINNOACTIVE = 7,
SW_SHOWNA = 8,
SW_RESTORE = 9,
SW_SHOWDEFAULT = 10,
SW_FORCEMINIMIZE = 11,
SW_MAX = 11
}
{
SW_HIDE = 0,
SW_SHOWNORMAL = 1,
SW_NORMAL = 1,
SW_SHOWMINIMIZED = 2,
SW_SHOWMAXIMIZED = 3,
SW_MAXIMIZE = 3,
SW_SHOWNOACTIVATE = 4,
SW_SHOW = 5,
SW_MINIMIZE = 6,
SW_SHOWMINNOACTIVE = 7,
SW_SHOWNA = 8,
SW_RESTORE = 9,
SW_SHOWDEFAULT = 10,
SW_FORCEMINIMIZE = 11,
SW_MAX = 11
}
Deklarasi Untuk VB.NET
[DllImport("shell32.dll")]
static extern IntPtr ShellExecute(
IntPtr hwnd,
string lpOperation,
string lpFile,
string lpParameters,
string lpDirectory,
ShowCommands nShowCmd);
ByVal hWnd As IntPtr, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Integer) As IntPtr
Penggunaan untuk C# :
// Untuk mengirim email
ShellExecute( IntPtr.Zero, "open", "mailto:nuramijaya@blogspot.com", "", "", ShowCommands.SW_SHOWNOACTIVATE ); // Untuk membuka URL
ShellExecute( IntPtr.Zero, "open", "http://cariprogram.blogspot.com", "", "", ShowCommands.SW_SHOWNOACTIVATE ); // Untuk mengedit file
ShellExecute( IntPtr.Zero, "edit", @"c:\halaman.html", "", "", ShowCommands.SW_SHOWNOACTIVATE );
ShellExecute( IntPtr.Zero, "open", "mailto:nuramijaya@blogspot.com", "", "", ShowCommands.SW_SHOWNOACTIVATE ); // Untuk membuka URL
ShellExecute( IntPtr.Zero, "open", "http://cariprogram.blogspot.com", "", "", ShowCommands.SW_SHOWNOACTIVATE ); // Untuk mengedit file
ShellExecute( IntPtr.Zero, "edit", @"c:\halaman.html", "", "", ShowCommands.SW_SHOWNOACTIVATE );
// Untuk membuka file
ShellExecute( IntPtr.Zero, "open", @"c:\dokumen.docx", "", "", 0);
ShellExecute( IntPtr.Zero, "open", @"c:\dokumen.docx", "", "", 0);
Penggunaan untuk VB.NET :
' Untuk mengirim email
ShellExecuteA(Me.Handle, "open", "mailto:nuramijaya@blogspot.com", "", "", 4)
' Untuk membuka URL
ShellExecuteA(Me.Handle, "open", "http://cariprogram.blogspot.com", "", "", 4)
' Untuk mengedit file
ShellExecuteA(Me.Handle, "edit", "c:\halaman.html", "", "", 4)
ShellExecuteA(Me.Handle, "open", "mailto:nuramijaya@blogspot.com", "", "", 4)
' Untuk membuka URL
ShellExecuteA(Me.Handle, "open", "http://cariprogram.blogspot.com", "", "", 4)
' Untuk mengedit file
ShellExecuteA(Me.Handle, "edit", "c:\halaman.html", "", "", 4)
' Untuk membuka file
ShellExecuteA(Me.Handle, "open", "c:\dokumen.docx", "", "", 4)
ShellExecuteA(Me.Handle, "open", "c:\dokumen.docx", "", "", 4)