Archive for the ‘.NET’ Category
-
Hello, Windows Forms(MSIL) World!
Posted on 6月 6th, 2012 by cx20
Windows Forms(MSIL)
Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
以下は MSIL における Windows フォーム の例となっている。ソースコード
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.1 // Copyright (c) Microsoft Corporation. All rights reserved. // Metadata version: v4.0.30319 .assembly extern System.Windows.Forms { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .zV.4.. .ver 4:0:0:0 } .assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .zV.4.. .ver 4:0:0:0 } .assembly extern System.Drawing { .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....: .ver 4:0:0:0 } .assembly Hello { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. .hash algorithm 0x00008004 .ver 0:0:0:0 } .module Hello.exe // MVID: {FF5266CD-116D-4A87-B4A5-1B94604BA0FE} .imagebase 0x00400000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0002 // WINDOWS_GUI .corflags 0x00000001 // ILONLY // Image base: 0x001E0000 // =============== CLASS MEMBERS DECLARATION =================== .class private auto ansi beforefieldinit HelloForm extends [System.Windows.Forms]System.Windows.Forms.Form { .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { // コード サイズ 94 (0x5e) .maxstack 4 .locals init (class [System.Windows.Forms]System.Windows.Forms.Label V_0) IL_0000: ldarg.0 IL_0001: call instance void [System.Windows.Forms]System.Windows.Forms.Form::.ctor() IL_0006: nop IL_0007: nop IL_0008: ldarg.0 IL_0009: ldc.i4 0x280 IL_000e: ldc.i4 0x1e0 IL_0013: newobj instance void [System.Drawing]System.Drawing.Size::.ctor(int32, int32) IL_0018: call instance void [System.Windows.Forms]System.Windows.Forms.Form::set_Size(valuetype [System.Drawing]System.Drawing.Size) IL_001d: nop IL_001e: ldarg.0 IL_001f: ldstr "Hello, World!" IL_0024: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Text(string) IL_0029: nop IL_002a: newobj instance void [System.Windows.Forms]System.Windows.Forms.Label::.ctor() IL_002f: stloc.0 IL_0030: ldloc.0 IL_0031: ldc.i4 0x140 IL_0036: ldc.i4.s 20 IL_0038: newobj instance void [System.Drawing]System.Drawing.Size::.ctor(int32, int32) IL_003d: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Size(valuetype [System.Drawing]System.Drawing.Size) IL_0042: nop IL_0043: ldloc.0 IL_0044: ldstr "Hello, Windows Forms(MSIL) World!" IL_0049: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Text(string) IL_004e: nop IL_004f: ldarg.0 IL_0050: call instance class [System.Windows.Forms]System.Windows.Forms.Control/ControlCollection [System.Windows.Forms]System.Windows.Forms.Control::get_Controls() IL_0055: ldloc.0 IL_0056: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control/ControlCollection::Add(class [System.Windows.Forms]System.Windows.Forms.Control) IL_005b: nop IL_005c: nop IL_005d: ret } // end of method HelloForm::.ctor .method private hidebysig static void Main() cil managed { .entrypoint .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 ) // コード サイズ 15 (0xf) .maxstack 1 .locals init (class HelloForm V_0) IL_0000: nop IL_0001: newobj instance void HelloForm::.ctor() IL_0006: stloc.0 IL_0007: ldloc.0 IL_0008: call void [System.Windows.Forms]System.Windows.Forms.Application::Run(class [System.Windows.Forms]System.Windows.Forms.Form) IL_000d: nop IL_000e: ret } // end of method HelloForm::Main } // end of class HelloForm // ============================================================= // *********** 逆アセンブルが完了しました *********************** // 警告: Win32 リソース ファイル hello.res を作成しました。
上記コードは、以下の C# の実行ファイルを ildasm.exe で逆アセンブルしたものである。
ソースコード
using System; using System.Drawing; using System.Windows.Forms; class HelloForm : Form { public HelloForm() { this.Size = new Size( 640, 480 ); this.Text = "Hello, World!"; Label label1 = new Label(); label1.Size = new Size( 320, 20 ); label1.Text = "Hello, Windows Forms(MSIL) World!"; this.Controls.Add( label1 ); } [STAThread] static void Main() { HelloForm form = new HelloForm(); Application.Run(form); } }
コンパイル方法
C:¥> ilasm Hello.il
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Windows Forms(MSIL) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, Windows Forms(C++/CLI) World!
Posted on 6月 5th, 2012 by cx20
Windows Forms(C++/CLI)
Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
以下は C++/CLI における Windows フォーム の例となっている。ソースコード
#using <System.dll> #using <System.Drawing.dll> #using <System.Windows.Forms.dll> using namespace System; using namespace System::Drawing; using namespace System::Windows::Forms; public ref class HelloForm : public Form { public: HelloForm() { this->Size = System::Drawing::Size( 640, 480 ); this->Text = "Hello, World!"; Label^ label1 = gcnew Label(); label1->Text = "Hello, Windows Forms(C++/CLI) World!"; label1->Size = System::Drawing::Size( 320, 20 ); this->Controls->Add( label1 ); } }; int main( array<System::String^>^ args ) { HelloForm^ form = gcnew HelloForm(); Application::Run(form); return 0; }
コンパイル方法
C:¥> cl Hello.cpp /clr /link /SUBSYSTEM:WINDOWS /ENTRY:main
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Windows Forms(C++/CLI) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, Windows Forms(JScript.NET) World!
Posted on 6月 4th, 2012 by cx20
Windows Forms(JScript.NET)
Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
以下は JScript.NET における Windows フォーム の例となっている。ソースコード
import System; import System.Drawing; import System.Windows.Forms; import Accessibility; main(); class HelloForm extends Form { function HelloForm() { this.Size = new System.Drawing.Size( 640, 480 ); this.Text = "Hello, World!"; var label1 = new Label; label1.Size = new System.Drawing.Size( 320, 20 ); label1.Text = "Hello, Windows Forms(JScript.NET) World!"; this.Controls.Add( label1 ); } } function main() { var form = new HelloForm; Application.Run(form); }
コンパイル方法
C:¥> jsc /target:winexe Hello.js
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Windows Forms(JScript.NET) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, Windows Forms(F#) World!
Posted on 6月 3rd, 2012 by cx20
Windows Forms(F#)
Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
以下は F# における Windows フォーム の例となっている。ソースコード
open System open System.Drawing open System.Windows.Forms type HelloForm() as this = inherit Form() do this.Size <- new Size( 640, 480 ) this.Text <- "Hello, World!" let label1 = new Label() label1.Size <- new Size( 320, 20 ) label1.Text <- "Hello, Windows Forms(F#) World!" do this.Controls.Add(label1) let form = new HelloForm() do Application.Run(form)
コンパイル方法
C:¥> fsc --target:winexe Hello.fs
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Windows Forms(F#) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, Windows Forms(VB.NET) World!
Posted on 6月 2nd, 2012 by cx20
Windows Forms(VB.NET)
Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
以下は VB.NET における Windows フォーム の例となっている。ソースコード
Imports System Imports System.Drawing Imports System.Windows.Forms Class HelloForm Inherits Form Public Sub New() Me.Size = New Size( 640, 480 ) Me.Text = "Hello, World!" Dim label1 As New Label label1.Size = New Size( 320, 20 ) label1.Text = "Hello, Windows Forms(VB.NET) World!" Me.Controls.Add( label1 ) End Sub <STAThread> _ Shared Sub Main() Dim form As New HelloForm() Application.Run(form) End Sub End Class
コンパイル方法
C:¥> vbc /target:winexe Hello.vb
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Windows Forms(VB.NET) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, Windows Forms(C#) World!
Posted on 6月 1st, 2012 by cx20
Windows Forms(C#)
Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
以下は C# における Windows フォーム の例となっている。ソースコード
using System; using System.Drawing; using System.Windows.Forms; class HelloForm : Form { public HelloForm() { this.Size = new Size( 640, 480 ); this.Text = "Hello, World!"; Label label1 = new Label(); label1.Size = new Size( 320, 20 ); label1.Text = "Hello, Windows Forms(C#) World!"; this.Controls.Add( label1 ); } [STAThread] static void Main() { HelloForm form = new HelloForm(); Application.Run(form); } }
コンパイル方法
C:¥> csc /target:winexe Hello.cs
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Windows Forms(C#) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, COM(MSIL) World!
Posted on 5月 22nd, 2012 by cx20
MSIL
COM(Component Object Model)はマイクロソフトの提唱するプログラム部品の仕様である。
COM を用いて開発された部品であれば言語を問わず利用することができる。
以下は MSIL による COM クライアントの例となっている。ソースコード
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.1 // Copyright (c) Microsoft Corporation. All rights reserved. // Metadata version: v2.0.50727 .assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .zV.4.. .ver 2:0:0:0 } .assembly extern Shell32 { .ver 1:0:0:0 } .assembly Hello { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. .hash algorithm 0x00008004 .ver 0:0:0:0 } .module Hello.exe // MVID: {558CDDD7-4AF4-48D6-A830-0DA2C5C15D19} .imagebase 0x00400000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY // Image base: 0x01D10000 // =============== CLASS MEMBERS DECLARATION =================== .class private auto ansi beforefieldinit Hello extends [mscorlib]System.Object { .method private hidebysig static void Main(string[] args) cil managed { .entrypoint // コード サイズ 56 (0x38) .maxstack 5 .locals init (class [Shell32]Shell32.Shell V_0, class [Shell32]Shell32.Folder V_1, object V_2, bool V_3) IL_0000: nop IL_0001: newobj instance void [Shell32]Shell32.ShellClass::.ctor() IL_0006: stloc.0 IL_0007: ldc.i4.s 36 IL_0009: conv.i8 IL_000a: box [mscorlib]System.Int64 IL_000f: stloc.2 IL_0010: ldloc.0 IL_0011: ldc.i4.0 IL_0012: ldstr "Hello, COM(MSIL) World!" IL_0017: ldc.i4.0 IL_0018: ldloc.2 IL_0019: callvirt instance class [Shell32]Shell32.Folder [Shell32]Shell32.IShellDispatch5::BrowseForFolder(int32, string, int32, object) IL_001e: stloc.1 IL_001f: ldloc.1 IL_0020: ldnull IL_0021: ceq IL_0023: stloc.3 IL_0024: ldloc.3 IL_0025: brtrue.s IL_0030 IL_0027: nop IL_0028: ldloc.1 IL_0029: call int32 [mscorlib]System.Runtime.InteropServices.Marshal::ReleaseComObject(object) IL_002e: pop IL_002f: nop IL_0030: ldloc.0 IL_0031: call int32 [mscorlib]System.Runtime.InteropServices.Marshal::ReleaseComObject(object) IL_0036: pop IL_0037: ret } // end of method Hello::Main .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { // コード サイズ 7 (0x7) .maxstack 8 IL_0000: ldarg.0 IL_0001: call instance void [mscorlib]System.Object::.ctor() IL_0006: ret } // end of method Hello::.ctor } // end of class Hello // ============================================================= // *********** 逆アセンブルが完了しました *********************** // 警告: Win32 リソース ファイル Hello.res を作成しました。
上記コードは、以下の C# の実行ファイルを ildadm.exe で逆アセンブルしたものである。
ソースコード
using System; using System.Runtime.InteropServices; using Shell32; class Hello { static void Main(string[] args) { Shell shell = new Shell(); Folder folder; object vRootFolder = (long)ShellSpecialFolderConstants.ssfWINDOWS; folder = shell.BrowseForFolder(0, "Hello, COM(MSIL) World!", 0, vRootFolder); if (folder != null) { Marshal.ReleaseComObject(folder); } Marshal.ReleaseComObject(shell); } }
コンパイル&実行方法(.NET Framework)
C:¥> ilasm Hello.il C:¥> Hello
実行結果
+----------------------------------------+ |Browse For Folder [X]| +----------------------------------------+ | Hello, COM(MSIL) Wolrd! | | | | +------------------------------------+ | | |[Windows] | | | | +[addins] | | | | +[AppCompat] | | | | +[AppPatch] | | | | +[assembly] | | | | : | | | | : | | | | : | | | +------------------------------------+ | | [Make New Folder] [ OK ] [Cancel] | +----------------------------------------+
-
Hello, COM(C++/CLI) World!
Posted on 5月 21st, 2012 by cx20
COM(C++/CLI)
COM(Component Object Model)はマイクロソフトの提唱するプログラム部品の仕様である。
COM を用いて開発された部品であれば言語を問わず利用することができる。
以下は C++/CLI による COM クライアントの例となっている。ソースコード
using namespace System; using namespace System::Runtime::InteropServices; using namespace Shell32; int main(array<System::String ^> ^args) { Shell^ shell = gcnew Shell; Folder^ folder; Object^ vRootFolder = (long)ShellSpecialFolderConstants::ssfWINDOWS; folder = shell->BrowseForFolder(0, "Hello, COM(C++/CLI) World!", 0, vRootFolder); if (folder != nullptr) { Marshal::ReleaseComObject(folder); } Marshal::ReleaseComObject(shell); return 0; }
コンパイル方法
C:¥> SET PATH=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin;%PATH% C:¥> tlbimp %SystemRoot%\system32\shell32.dll /out:Shell32.dll C:¥> cl /FU Shell32.dll Hello.cs /clr
実行結果
+----------------------------------------+ |Browse For Folder [X]| +----------------------------------------+ | Hello, COM(C#) Wolrd! | | | | +------------------------------------+ | | |[Windows] | | | | +[addins] | | | | +[AppCompat] | | | | +[AppPatch] | | | | +[assembly] | | | | : | | | | : | | | | : | | | +------------------------------------+ | | [Make New Folder] [ OK ] [Cancel] | +----------------------------------------+
-
Hello, COM(JScript.NET) World!
Posted on 5月 20th, 2012 by cx20
COM(JScript.NET)
COM(Component Object Model)はマイクロソフトの提唱するプログラム部品の仕様である。
COM を用いて開発された部品であれば言語を問わず利用することができる。
以下は JScript.NET による COM クライアントの例となっている。ソースコード
import System; import System.Runtime.InteropServices; var ssfWINDOWS = 36 main(); function main() { var shell = new ActiveXObject("Shell.Application"); var folder = shell.BrowseForFolder( 0, "Hello, COM(JScript.NET) World!", 0, ssfWINDOWS ); if ( folder != null ) { Marshal.ReleaseComObject( folder ); } Marshal.ReleaseComObject( shell ); }
コンパイル方法
C:¥> jsc hello.js
実行結果
+----------------------------------------+ |Browse For Folder [X]| +----------------------------------------+ | Hello, COM(JScript.NET) Wolrd! | | | | +------------------------------------+ | | |[Windows] | | | | +[addins] | | | | +[AppCompat] | | | | +[AppPatch] | | | | +[assembly] | | | | : | | | | : | | | | : | | | +------------------------------------+ | | [Make New Folder] [ OK ] [Cancel] | +----------------------------------------+
-
Hello, COM(F#) World!
Posted on 5月 19th, 2012 by cx20
COM(F#)
COM(Component Object Model)はマイクロソフトの提唱するプログラム部品の仕様である。
COM を用いて開発された部品であれば言語を問わず利用することができる。
以下は F# による COM クライアント(事前バインディングならびに実行時バインディング)の例となっている。ソースコード(事前バインディング)
open System open System.Runtime.InteropServices open Shell32 let shell = new Shell32.ShellClass() let vRootFolder = Shell32.ShellSpecialFolderConstants.ssfWINDOWS let folder = shell.BrowseForFolder( 0, "Hello, COM(F#) World!", 0, vRootFolder ) if folder <> null then Marshal.ReleaseComObject( folder ) |> ignore Marshal.ReleaseComObject( shell ) |> ignore
コンパイル方法(事前バインディング)
C:¥> SET PATH=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin;%PATH% C:¥> tlbimp %SystemRoot%\system32\shell32.dll /out:Shell32.dll C:¥> fsc -r:Shell32.dll Hello.fs
ソースコード(実行時バインディング)
open System open System.Reflection open System.Runtime.InteropServices let objType = Type.GetTypeFromProgID("Shell.Application") let shell = Activator.CreateInstance(objType) let param = [| (0 :> Object); ("Hello, COM(F#) World!" :> Object); (0 :> Object); (36 :> Object) |] let folder = shell.GetType().InvokeMember("BrowseForFolder", BindingFlags.InvokeMethod, null, shell, param ) if folder <> null then Marshal.ReleaseComObject( folder ) |> ignore Marshal.ReleaseComObject( shell ) |> ignore
コンパイル方法(実行時バインディング)
C:¥> fsc Hello.fs
実行結果
+----------------------------------------+ |Browse For Folder [X]| +----------------------------------------+ | Hello, COM(F#) Wolrd! | | | | +------------------------------------+ | | |[Windows] | | | | +[addins] | | | | +[AppCompat] | | | | +[AppPatch] | | | | +[assembly] | | | | : | | | | : | | | | : | | | +------------------------------------+ | | [Make New Folder] [ OK ] [Cancel] | +----------------------------------------+