using System;
using System.Runtime.InteropServices;
namespace FastCSharp
{
class Class1
{
[STAThread]
unsafe static void Main(string[] args)
{
// comInvoke();
// helloWorld();
// StructInvoke();
// classInvode();
// PointerInvoke();
unsafeMethod();
}
// 調用一個com組件
// tlbimp工具
public static void comInvoke()
{
//string fileName = "c:\\Windows\\clock.avi";
string fileName = @"C:\Documents and Settings\Administrator\桌面\WebApplication1\心中心密咒\dgmz.wma";
QuartzTypeLib.FilgraphManager graphManager = new QuartzTypeLib.FilgraphManagerClass();
QuartzTypeLib.IMediaControl mc = (QuartzTypeLib.IMediaControl)graphManager;
mc.RenderFile(fileName);
mc.Run();
Console.WriteLine("Hello World");
Console.ReadLine();
}
public static void helloWorld()
{
Win32Invoke.MessageBox(0,"Hello World","Platform Invoke Sample",0);
}
// 傳遞結構變量
public static void StructInvoke()
{
Point p = new Point();
p.x = 1;
p.y = 1;
Rect r = new Rect();
r.left = 0;
r.bottom = 2;
r.right = 2;
r.top = 0;
bool b = Win32Invoke.PtInRect(ref r,p);
System.Console.WriteLine("Point[1,1] is int Rect[0,0,2,2] ?" +b );
}
// 傳遞一個對象
public static void classInvode()
{
MySystemTime t = new MySystemTime();
Win32Invoke.GetSystemTime(t);
Console.WriteLine("System time is "
+ t.wYear + "/"
+ t.wMonth + "/"
+ t.wDay + " "
+ t.wHour + ":"
+ t.wMinute + ":"
+ t.wSecond
);
}
// 傳送一個C#函數指針給Dll函數
public static void PointerInvoke()
{
CallBack myCallBack = new CallBack(Class1.Report);
Win32Invoke.EnumWindows(myCallBack,0);
}
public static bool Report(int hwnd, int lParam)
{
Console.WriteLine("Window handle is" + hwnd);
return true;
}