国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

C#中與未操控語句交互運作

2024-07-21 02:18:27
字體:
來源:轉載
供稿:網(wǎng)友


收集最實用的網(wǎng)頁特效代碼!

using system;
using system.runtime.interopservices;

namespace fastcsharp
{
class class1
{


[stathread]
unsafe static void main(string[] args)
{
// cominvoke();
// helloworld();
// structinvoke();
// classinvode();
// pointerinvoke();
unsafemethod();
}

// 調(diào)用一個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#函數(shù)指針給dll函數(shù)
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;
}
// 指針函數(shù)
unsafe static void squareparam(int *p)
{
//unsafe mthod:takes pointer to int
*p *= *p;
}
// unsafe method : user address-of operator (&)
unsafe public static void unsafemethod()
{
int i = 5;
squareparam(&i);
console.writeline("5 * 5 == " + i );
p pt = new p();
pt.x = 5;
pt.y = 6;
//fixed 關鍵字是告訴c#資源回收器接下來不要對某過變量的地址進行運算,不要對此變量的地址有任何改動
//pin pt in place
fixed(int* pointer =&pt.x)
{

squareparam(pointer);
}
//pt now nupinned
console.writeline("pt.x == {0} pt.y == {1}",pt.x,pt.y);
}
}
public class win32invoke
{
[dllimport("user32.dll",charset = charset.auto)]
public static extern int messagebox(int hwnd,string text,string caption,uint type);
[dllimport("user32.dll")]
public static extern bool ptinrect(ref rect r, point p);
[dllimport("kernel32.dll")]
public static extern void getsystemtime(mysystemtime st);
[dllimport("user32.dll")]
public static extern int enumwindows(callback x, int y);
}

public struct point
{
public int x;
public int y;
}
public class p
{
public int x;
public int y;
}
[structlayout(layoutkind.explicit)]
public struct rect
{
[fieldoffset(0)] public int left;
[fieldoffset(4)] public int top;
[fieldoffset(8)] public int right;
[fieldoffset(12)] public int bottom;
}
[structlayout(layoutkind.sequential)]
public class mysystemtime
{
public ushort wyear;
public ushort wmonth;
public ushort wdayofweek;
public ushort wday;
public ushort whour;
public ushort wminute;
public ushort wsecond;
public ushort wmilliseconds;
}
// delegate
public delegate bool callback(int hwnd, int lparam);



}




發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 乡宁县| 姚安县| 明星| 蒲城县| 平阴县| 海安县| 石楼县| 新闻| 清镇市| 东港市| 明溪县| 和平县| 宁城县| 乐陵市| 泾川县| 孟州市| 虎林市| 耒阳市| 舞阳县| 三亚市| 游戏| 寿阳县| 信丰县| 定兴县| 博乐市| 海晏县| 望都县| 太和县| 嘉义市| 稷山县| 云梦县| 肃南| 麦盖提县| 龙井市| 恩施市| 合山市| 通山县| 沙洋县| 林芝县| 南宁市| 和顺县|