goo

HSP+C#

HSP+C#
関連資料
使用モジュール
HSPからC#を実行
#include "mod_CSharp.hsp"
	src = {"
		using System;
		using System.Windows.Forms;
		class Test1 {
			static void Main(string[] args){
				MessageBox.Show(\"Main()\", \"C#\");
			}
			public void Func1(){
				MessageBox.Show(¥"Hello HSP!¥", ¥"C#¥");
			}
		}
	"}

	screen 0, 300, 40 : font "メイリオ", 12
	title "mod_CSharp.hsp"
	if ( CSMakeMod(modCS) == 0 ){ dialog "err" : end }
	if ( CSCAddRef(modCS, "System.dll") == 0 ){ dialog "err2" : end }
	if ( CSCAddRef(modCS, "System.Windows.Forms.dll") == 0 ){ dialog "err3" : end }
	if ( CSCl2(modCS, src, cAsm, cErr) ){
		if ( CSCInstance(modCS, "Test1", cAsm, cObj) ){
			mes "Test1.Func1()"
			ret = CSCall(cObj, "Func1")
		}
	}
	mes "OK"
	stop
コンパイル(インスタンス作成、エラー取得、メソッド実行)
#include "user32.as"
#include "mod_CSharp.hsp"

#module mod_Main mID, mhWnd, mBmscr

#modinit int id, int x, int y, int w, int h, str titleName
	mID = id
	screen mID, ginfo_dispx, ginfo_dispy, 2, x, y, w, h
	mhWnd = hwnd
	ret = Main_AddStyle(thismod, 0x00070000)
	title titleName : objmode 2 : mref mBmscr, 67
	return 1

#modcfunc Main_SetFont str fontName, int fontSize
	font fontName, fontSize
	return 1

#modcfunc Main_Show int nShow
	ShowWindow mhWnd, nShow
	return 1

#modcfunc Main_AddStyle int nLong
	GetWindowLong mhWnd, -16
	SetWindowLong mhWnd, -16, stat | nLong
	SetWindowPos mhWnd, 0, 0, 0, 0, 0, 0x23
	return 1

#modcfunc Main_WM_SIZE label lMsg
	gsel mID : oncmd gosub lMsg, 0x0005
	return 1

#modcfunc Button_Make str btnName, label lBtn
	gsel mID : objsize 0, 0
	button gosub btnName, lBtn
	return objinfo(stat, 2)

#modcfunc MesBox_Make var bufMB, int nStyle
	gsel mID : objsize 0, 0
	mesbox bufMB, 0, 0, nStyle, 0
	return objinfo(stat, 2)

#modcfunc MesBox_Add int hMB, str sTxt
	buf = sTxt
	sendmsg hMB, 0x0e, 0, 0
	sendmsg hMB, 0xb1, stat, stat
	sendmsg hMB, 0xc2, 0, varptr(buf)
	return 1

#modcfunc ListBox_Make
	CreateWindowEx 0, "ListBox", "", 0x50300100, 0, 0, 0, 0, mhWnd, 0, hinstance, 0
	ret = stat
	sendmsg ret, 0x0030, mBmscr(38), 1
	return ret

#modcfunc ListBox_GetSel int hLB
	sendmsg hLB, 0x0188, 0, 0
	return stat

#modcfunc ListBox_SetSel int hLB, int nID
	sendmsg hLB, 0x0186, nID, nID
	return stat

#modcfunc ListBox_GetStr int hLB, int nID
	sdim buf, 260
	sendmsg hLB, 0x0189, nID, varptr(buf)
	return buf

#modcfunc ListBox_Add int hLB, int nID, str sData
	buf = sData
	sendmsg hLB, 0x0180, nID, varptr(buf)
	return stat

#modcfunc ListBox_Clear int hLB
	sendmsg hLB, 0x018B, 0, 0
	repeat stat
		sendmsg hLB, 0x0182, 0, 0
	loop
	return 1

#global

	ret = CSMakeMod(cs)
	newmod m, mod_Main, 0, -1, -1, 600, 400, "mod_CSharp.hsp"
	ret = Main_SetFont(m, "メイリオ", 11)
	ret = Main_WM_SIZE(m, *WM_SIZE)
	gosub *MAKE_CHILD
	ret = Main_Show(m, 1)
	stop

*WM_SIZE
	x = ginfo_winx / 4 : h = ginfo_winy / 2
	MoveWindow hBtnCL, 0, 0, x, 30, 1
	MoveWindow hBtnMI, 0, 30, x, 30, 1
	MoveWindow hLBCL, 0, 60, x, h - 60, 1
	MoveWindow hBtnIV, 0, h, x, 30, 1
	MoveWindow hLBMT, 0, h + 30, x, h - 30, 1
	x2 = x * 3 : h = ginfo_winy / 3 : h2 = h * 2
	MoveWindow hEditSrc, x, 0, x2, h2, 1
	x3 = x2 / 3
	MoveWindow hEditRef, x, h2, x3, h, 1
	MoveWindow hEditOut, x + x3, h2, x3 * 2, h, 1
	return

*MAKE_CHILD
	x = 1024 * 64
	sdim mbSrc, x : sdim mbRef, x : sdim mbOut, z
	ret = Main_SetFont(m, "メイリオ", 12)
	hBtnCl = Button_Make(m, "コンパイル", *BTN_CL)
	hBtnMI = Button_Make(m, "インスタンス作成", *BTN_MI)
	hBtnIV = Button_Make(m, "メソッド実行", *BTN_IV)
	ret = Main_SetFont(m, "Consolas", 14)
	hEditSrc = MesBox_Make(m, mbSrc, 5)
	objskip 3, 2
	ret = Main_SetFont(m, "メイリオ", 11)
	hEditRef = MesBox_Make(m, mbRef, 5)
	hEditOut = MesBox_Make(m, mbOut, 4)
	hLBCL = ListBox_Make(m)
	hLBMT = ListBox_Make(m)
	return

*BTN_CL
	cs = 0 : cAsm = 0 : cObj = 0 : cErr = 0
	ret = CSMakeMod(cs)
	ret = ListBox_Clear(m, hLBCL)
	ret = ListBox_Clear(m, hLBMT)
	if ( CSCClearRef(cs) ){
		notesel mbRef : sdim buf, 260
		repeat notemax
			noteget buf, cnt
			if ( buf != "" ){ ret = CSCAddRef(cs, buf) }
		loop
	}
	if ( CSCl2(cs, mbSrc, cAsm, cErr) ){
		len = CSCErrLen(cs, cErr)
		if ( len == 0 ){
			buf2 = "成功:エラー 0"
			len = CSGetClassList(cAsm, list)
			repeat len
				ret = ListBox_Add(m, hLBCL, cnt, list(cnt))
			loop
			ret = ListBox_SetSel(m, hLBCL, 0)
		}
		else {
			buf2 = strf("失敗:エラー %d\n", len)
			if ( CSCErrList(cs, cErr, list) ){
				repeat len
					buf2 += strf("%4d行 : [%s] %s\n", int(list(2, cnt)), list(3, cnt), list(4, cnt))
				loop
			}
			else {
				buf2 += "エラー取得失敗"
			}
		}
		cErr = 0
	}
	else {
		buf2 = "コンパイル失敗"
	}
	buf2 += "\n-------------------------------\n"
	ret = MesBox_Add(m, hEditOut, buf2)
	return

*BTN_MI
	sel = ListBox_GetSel(m, hLBCL)
	if ( sel == -1 ){
		dialog "クラスが選択されていません"
		return
	}
	buf = ListBox_GetStr(m, hLBCL, sel)
	if ( CSCInstance(cs, buf, cAsm, cObj) == 0 ){
		dialog "インスタンスの作成失敗 [" + buf+"] " +sel
		return
	}
	ret = ListBox_Clear(m, hLBMT)
	len = CSGetMethodList(cObj, listMethod)
	buf2 = "" : buf3 = ""
	repeat len
		buf2 = strf("%s(%s)", listMethod(0, cnt), listMethod(2, cnt))
		buf3 += strf("%s %s\n", listMethod(1, cnt), buf2)
		ret = ListBox_Add(m, hLBMT, cnt, buf2)
	loop
	ret = ListBox_SetSel(m, hLBMT, 0)
	buf3 += strf("成功:%sのインスタンス作成\nメソッド数 : %d", buf, len)
	buf3 += "\n-------------------------------\n"
	ret = MesBox_Add(m, hEditOut, buf3)
	return

*BTN_IV
	sel = ListBox_GetSel(m, hLBMT)
	if ( sel == -1 ){
		dialog "メソッドが選択されていません"
		return
	}
	if ( listMethod(2, sel) != "" ){
		dialog "引数が無いメソッドを選択してください"
		return
	}
	buf = listMethod(0, sel)
	ret = MesBox_Add(m, hEditOut, strf("%s 実行\n", buf))
	ret = CSCall(cObj, buf)
	if ( vartype(ret) == 2 ){ buf = strf("戻り値:%s", ret) }
	else {
		if ( vartype(ret) == 3 ){ buf = strf("戻り値:%f", ret) }
		else { buf = strf("戻り値:%d", ret) }
	}
	buf += "\n-------------------------------\n"
	ret = MesBox_Add(m, hEditOut, buf)
	return
EXE作成
#include "mod_CSharp.hsp"
	src = {"
		using System;
		using System.Windows.Forms;
		class Test1 {
			static void Main(string[] args){
				MessageBox.Show(\"Main()\", \"C#\");
			}
			public void Func1(){
				MessageBox.Show(\"Hello HSP!\", \"C#\");
			}
		}
	"}
	fileName = "CSTest.exe"

	screen 0, 300, 40 : font "メイリオ", 12
	title "mod_CSharp.hsp"
	if ( CSMakeMod(modCS) == 0 ){ dialog "err" : end }
	if ( CSCAddRef(modCS, "System.dll") == 0 ){ dialog "err2" : end }
	if ( CSCAddRef(modCS, "System.Windows.Forms.dll") == 0 ){ dialog "err3" : end }
	if ( CSCMakeWin(modCS, src, fileName) == 0 ){ dialog "err4" : end }
	mes strf("OK %s を作成しました", fileName)
	stop
DLL作成
#include "mod_CSharp.hsp"
	src = {"
		using System;
		using System.Windows.Forms;
		class Test1 {
			static void Main(string[] args){
				MessageBox.Show(\"Main()\", \"C#\");
			}
			public void Func1(){
				MessageBox.Show(\"Hello HSP!\", \"C#\");
			}
		}
	"}
	fileName = "CSTest.dll"

	screen 0, 300, 40 : font "メイリオ", 12
	title "mod_CSharp.hsp"
	if ( CSMakeMod(modCS) == 0 ){ dialog "err" : end }
	if ( CSCAddRef(modCS, "System.dll") == 0 ){ dialog "err2" : end }
	if ( CSCAddRef(modCS, "System.Windows.Forms.dll") == 0 ){ dialog "err3" : end }
	if ( CSCMakeDll(modCS, src, fileName) == 0 ){ dialog "err4" : end }
	mes strf("OK %s を作成しました", fileName)
	stop
DLLをロード
#include "mod_CSharp.hsp"
	moduleName = "CSTest"

	screen 0, 300, 40 : font "メイリオ", 12
	title "mod_CSharp.hsp"
	if ( CSMakeMod(modCS) == 0 ){ dialog "err" : end }
	if ( CSCLoad(modCS, moduleName, cAsm) == 0 ){ dialog "err2" : end }
	if ( CSCInstance(modCS, "Test1", cAsm, cObj) ){
		mes "Test1.Func1()"
		ret = CSCall(cObj, "Func1")
	}
	mes strf("OK %s", moduleName)
	stop
データグリッドビューの作成
#include "user32.as"
#include "mod_CSharp.hsp"
src = {"
using System;
using System.IO;
using System.Data;
using System.Xml;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.Reflection;

[StructLayout(LayoutKind.Sequential)]
struct COPYDATASTRUCT {
	public IntPtr		dwData;
	public int			cbData;
	public IntPtr       lpData;
}

[StructLayout(LayoutKind.Sequential)]
struct COL_ROW {
	public int colIndex;
	public int rowIndex;
}

class Dgv : Form {
	[DllImport(¥"user32.dll¥", CharSet = CharSet.Auto)]
	public static extern int SendMessage(IntPtr hWnd, int uMsg, IntPtr wParam, ref COPYDATASTRUCT lParam);
	public const int WM_COPYDATA = 0x004A;
	[DllImport(¥"user32.dll¥", CharSet = CharSet.Auto)]
	public static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

	IntPtr          hTarget;
	Thread			thread;
	Form			form;
	DataGridView    dgv;
	BindingSource   bSrc;
	DataTable		table;
	TextBox			textFilter;
	int             rowHeight;
	static string[]	tagNames = {
			¥"index¥", ¥"prm¥", ¥"inst¥", ¥"sample¥", ¥"href¥", ¥"dll¥", ¥"ver¥", ¥"date¥",
			¥"author¥", ¥"url¥", ¥"note¥", ¥"type¥", ¥"group¥", ¥"port¥", ¥"portinfo¥"
	};
	static string[]	colNames = {
			¥"シンボル名¥", ¥"見出し¥", ¥"パラメータリスト¥", ¥"パラメータ説明文¥",
			¥"解説文¥", ¥"サンプルスクリプト¥", ¥"関連項目¥", ¥"使用プラグイン¥",
			¥"バージョン¥", ¥"日付¥", ¥"著作者¥", ¥"関連URL¥", ¥"備考¥", ¥"タイプ¥",
			¥"グループ¥", ¥"対応環境¥", ¥"移植のヒント¥", ¥"hsファイル¥"
	};
	int[] colWidth = {
		120, 200, 200, 200, 200, 200, 100, 100, 100, 100,
		100, 100, 100, 100, 100, 100, 100, 200
	};

	public Dgv(){
		hTarget = IntPtr.Zero;
		rowHeight = 52;
		bSrc = new BindingSource();
		dgv = new DataGridView();
		dgv.ReadOnly = true;
		dgv.MultiSelect = false;
		dgv.AutoGenerateColumns = false;
		dgv.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
		dgv.AllowUserToAddRows = false;
		dgv.BackgroundColor = Color.Snow;
		dgv.RowsDefaultCellStyle.BackColor = Color.Snow;
		dgv.AlternatingRowsDefaultCellStyle.BackColor = Color.LightCyan;
		dgv.EnableHeadersVisualStyles = false;
		dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.LightBlue;
		dgv.RowHeadersDefaultCellStyle.BackColor = Color.LightBlue;
		dgv.DefaultCellStyle.Font = new Font(¥"メイリオ¥", 8);
		dgv.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
		dgv.ColumnHeadersDefaultCellStyle.Font = new Font(¥"メイリオ¥", 9, FontStyle.Bold);
		dgv.RowTemplate.Height = rowHeight;
		dgv.Dock = DockStyle.Fill;
		table = new DataTable(¥"HS¥");
		table.CaseSensitive = false;
		DataColumn col;
		int len = colNames.Length;
		for ( int i = 0; i <  len; i++ ){
			col = new DataColumn(); col.ColumnName = colNames[i]; table.Columns.Add(col);
			DataGridViewTextBoxColumn c = new DataGridViewTextBoxColumn();
			c.DataPropertyName = colNames[i]; c.Name = colNames[i]; c.HeaderText = colNames[i]; c.Width = colWidth[i];
			if ( i == 0 ) { c.Frozen = true; }
			dgv.Columns.Add(c);
		}
		dgv.CellMouseClick += Dgv_CellMouseClick;
		dgv.CurrentCellChanged += Dgv_CurrentCellChanged;
//		dgv.DataError += Dgv_DataError;
		form = new Form();
		form.FormBorderStyle = FormBorderStyle.None;
		form.Controls.Add(dgv);
		thread = new Thread(ThreadProc);
		thread.SetApartmentState(ApartmentState.STA);
		thread.Start(form);
	}

	public static void ThreadProc(Object obj){
		Form f = (Form)obj;
		Application.Run(f);
	}

	private void Dgv_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
		DataGridView d = (DataGridView)sender;
		if ( d.Rows.Count == 0 || e.RowIndex == -1 ){ return; }
		if (e.Button == MouseButtons.Middle) {
			if ( d.Rows[e.RowIndex].Height != rowHeight ){
				d.Rows[e.RowIndex].Height = rowHeight;
			}
			else { d.AutoResizeRow(e.RowIndex); }
			return;
		}
	}

	private void Dgv_CurrentCellChanged(object sender, EventArgs e) {
		DataGridView d = (DataGridView)sender;
		IntPtr ptr = IntPtr.Zero;
		if ( hTarget != IntPtr.Zero ) {
			try {
				COPYDATASTRUCT cds = new COPYDATASTRUCT();
				COL_ROW cr;
				cr.colIndex = d.CurrentCellAddress.X;
				cr.rowIndex = d.CurrentCellAddress.Y;
				if ( cr.colIndex != -1 && cr.rowIndex != -1 ){
					ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(COL_ROW)));
					Marshal.StructureToPtr(cr, ptr, false);
					cds.dwData = IntPtr.Zero;
					cds.cbData = Marshal.SizeOf(typeof(COL_ROW));
					cds.lpData = ptr;
					SendMessage(hTarget, WM_COPYDATA, d.Handle, ref cds);
				}
			}
			finally {
				if ( ptr != IntPtr.Zero ){ Marshal.FreeHGlobal(ptr); }
			}
		}
		return;
	}

	private void Dgv_DataError(object sender, DataGridViewDataErrorEventArgs anError){
	}

	int LoadHSFile(string fileName){
		string[] lines = File.ReadAllLines(fileName, System.Text.Encoding.GetEncoding(932));
		if ( lines == null ){ return 0;}
		int numIndex = 0, flag = 0, type = 0, typeTmp;
		string buf = ¥"¥";
		DataRow row = table.NewRow();
		DataRow rowDef = table.NewRow();
		int tagLen = tagNames.Length, len = lines.Length, len2;
		for ( int i = 0; i < len; i++ ){
			len2 = lines[i].Length;
			if ( len2 != 0 && (lines[i][0] == ';' || lines[i] == ¥"^¥" || lines[i] == ¥"^p¥") ){ continue; }
			typeTmp = -1;
			if ( len2 != 0 && lines[i][0] == '%' ){
				for ( int j = 0; j < tagLen; j++ ){
					if ( lines[i].IndexOf(tagNames[j], StringComparison.OrdinalIgnoreCase) == 1 ){
						typeTmp = j; break;
					}
				}
			}
			if ( flag != 0 ){
				if ( typeTmp == -1 && i != (len - 1)){ buf += ¥"¥¥r¥¥n¥" + lines[i]; continue; }
				flag = buf.LastIndexOf('¥¥n');
				if ( flag != -1 ) {
					if ( buf.Length == (flag + 1) ) { buf = buf.Substring(0, flag); }
				}
				switch ( type ){
					case 1: row[colNames[3]] = buf; break;
					case 2: row[colNames[4]] = buf; break;
					case 3: row[colNames[5]] = buf; break;
					case 4: row[colNames[6]] = buf; break;
					case 7: row[colNames[9]] = buf; break;
					case 8: row[colNames[10]] = buf; break;
					case 9: row[colNames[11]] = buf; break;
					case 10: row[colNames[12]] = buf; break;
					case 13: row[colNames[15]] = buf; break;
					case 14: row[colNames[16]] = buf; break;
				}
				flag = 0;
			}
			else if ( typeTmp == -1 ){ continue; }
			type = typeTmp;
			if ( len <= i + 1 ){ break; }
			switch ( type ){
				case 0:
					if ( numIndex == 0 ){ rowDef.ItemArray = row.ItemArray; }
					else {
						table.Rows.Add(row);
						row = table.NewRow();
						row.ItemArray = rowDef.ItemArray;
					}
					if ( len <= i + 2 ){ break; }
					row[colNames[17]] = fileName;
					numIndex++; i++; row[colNames[0]] = lines[i];
					i++; row[colNames[1]] = lines[i];
					break;
				case 1:
					if ( lines[i + 1] == ¥"¥" ){ break; }
					i++; row[colNames[2]] = lines[i]; buf = ¥"¥"; flag = 1;
					break;
				case 2:
				case 3:
				case 4: buf = ¥"¥"; flag = 1; break;
				case 5: i++; row[colNames[7]] = lines[i]; break;
				case 6: i++; row[colNames[8]] = lines[i]; break;
				case 7:
				case 8:
				case 9:
				case 10: buf = ¥"¥"; flag = 1; break;
				case 11: i++; row[colNames[13]] = lines[i]; break;
				case 12: i++; row[colNames[14]] = lines[i]; break;
				case 13:
				case 14:
				case 15: buf = ¥"¥"; flag = 1; break;
			}
		}
		if ( numIndex != 0 ){ table.Rows.Add(row); }
		return numIndex;
	}

	private int LoadHSDir(string dirName){
		int len = 0;
		string[] files = Directory.GetFiles(dirName, ¥"*.hs¥");
		foreach ( string s in files ){
			if ( LoadHSFile(s) != 0 ){ len++; }
		}
		return len;
	}
	private delegate int LoadHSDirDelegate(string dirName);
	public int LoadHS() {
		int ret = 0;
		FolderBrowserDialog folderDlg = new FolderBrowserDialog();
		folderDlg.Description = ¥"hsphelpフォルダを選択してください¥";
		folderDlg.SelectedPath = Directory.GetCurrentDirectory();
		if ( folderDlg.ShowDialog() == DialogResult.OK ) {
			table.Rows.Clear();
			ret = (int)form.Invoke(new LoadHSDirDelegate(LoadHSDir), new object[]{ folderDlg.SelectedPath });
		}
		folderDlg.Dispose();
		if ( ret == 0 ){ return 0; }
		return table.Rows.Count;
	}

	private int SetCell(int col, int row){
		dgv.CurrentCell = dgv[col, row];
		if ( dgv.CurrentCell == null ){ return 0; }
		return 1;
	}

	private int SetSymbolCell_(string key){
		string c;
		key = key.ToLowerInvariant();
		int len = dgv.Rows.Count, i;
		for ( i = 0; i < len; i++ ){
			c = dgv.Rows[i].Cells[0].Value.ToString().ToLowerInvariant();
			if ( c != "" && c == key ){
				dgv.CurrentCell = dgv[0, i];
				return 1;
			}
		}
		return 0;
	}
	private delegate int SetSymbolCellDelegate(string key);
	public int SetSymbolCell(string key) {
		return (int)form.Invoke(new SetSymbolCellDelegate(SetSymbolCell_), new object[]{ key });
	}

	public int GetWnd() {
		return (int)form.Handle;
	}

	public void SetTarget(int hWndTarget) {
		hTarget = (IntPtr)hWndTarget;
	}

	public int GetRows(){
		return table.Rows.Count;
	}

	public int GetRows2(){
		return bSrc.Count;
	}

	public void MoveWnd(int x, int y, int w, int h) {
		dgv.Left = x; dgv.Top = y; dgv.Width = w; dgv.Height = h;
	}

	public int LoadXml_(string fileName) {
		try {
			table.Rows.Clear();
			table.ReadXml(fileName);
		}
		catch {
			return 0;
		}
		bSrc.DataSource = table;
		dgv.DataSource = bSrc;
		return table.Rows.Count;
	}
	private delegate int LoadXmlDelegate(string fileName);
	public int LoadXml(string fileName) {
		return (int)form.Invoke(new LoadXmlDelegate(LoadXml_), new object[]{ fileName });
	}

	public int SaveXml_(string fileName) {
		try {
			table.WriteXml(fileName);
		}
		catch {
			return 0;
		}
		return 1;
	}
	private delegate int SaveXmlDelegate(string fileName);
	public int SaveXml(string fileName) {
		return (int)form.Invoke(new SaveXmlDelegate(SaveXml_), new object[]{ fileName });
	}

	public int SetFilter_(string sFilter) {
		try {
			if ( sFilter == ¥"¥" ) { 
				bSrc.RemoveFilter();
			}
			else {
				bSrc.Filter = sFilter;
			}
		}
		catch { return 0; }
		return bSrc.Count;
	}
	private delegate int SetFilterDelegate(string sFilter);
	public int SetFilter(string sFilter) {
		return (int)form.Invoke(new SetFilterDelegate(SetFilter_), new object[]{ sFilter });
	}

	public string GetSymbol(int rowIndex) {
		if ( rowIndex >= dgv.Rows.Count ) { return ¥"¥"; }
		return dgv.Rows[rowIndex].Cells[0].Value.ToString();
	}

	public string GetData(int rowIndex) {
		string s, s2;
		string sRet = ¥"¥¥r¥¥n¥";
		string sBar = ¥"--------------------------------¥";
		s = String.Format(¥"{2}{0}{3}{0}{0}解説{0}{1}{0}{4}{0}{0}書式{0}{1}{0}{2} {5}{0}{6}¥",
			sRet, sBar,
			dgv.Rows[rowIndex].Cells[0].Value.ToString(),
			dgv.Rows[rowIndex].Cells[1].Value.ToString(),
			dgv.Rows[rowIndex].Cells[4].Value.ToString(),
			dgv.Rows[rowIndex].Cells[2].Value.ToString(),
			dgv.Rows[rowIndex].Cells[3].Value.ToString());
		s2 = dgv.Rows[rowIndex].Cells[5].Value.ToString();
		if ( s2 != ¥"¥" ){ s += String.Format(¥"{0}{0}サンプル{0}{1}{0}{2}¥", sRet, sBar, s2); }
		s2 = dgv.Rows[rowIndex].Cells[6].Value.ToString();
		if ( s2 != ¥"¥" ){ s += String.Format(¥"{0}{0}関連項目{0}{1}{0}{2}¥", sRet, sBar, s2); }
		s2 = dgv.Rows[rowIndex].Cells[7].Value.ToString();
		if ( s2 != ¥"¥" ){ s += String.Format(¥"{0}{0}使用プラグイン{0}{1}{0}{2}¥", sRet, sBar, s2); }
		s2 = dgv.Rows[rowIndex].Cells[15].Value.ToString();
		if ( s2 != ¥"¥" ){ s += String.Format(¥"{0}{0}対応環境{0}{1}{0}{2}¥", sRet, sBar, s2); }
		s2 = dgv.Rows[rowIndex].Cells[16].Value.ToString();
		if ( s2 != ¥"¥" ){ s += String.Format(¥"{0}{0}移植のヒント{0}{1}{0}{2}¥", sRet, sBar, s2); }
		s += String.Format(¥"{0}{0}情報{0}{1}{0}グループ   {2}{0}著作者    {3}{0}作成日    {4}{0}バージョン  {5}{0}備考     {6}{0}URL    {7}{0}タイプ    {8}{0}HSファイル {9}{0}¥",
			sRet, sBar,
			dgv.Rows[rowIndex].Cells[14].Value.ToString(),
			dgv.Rows[rowIndex].Cells[10].Value.ToString(),
			dgv.Rows[rowIndex].Cells[9].Value.ToString(),
			dgv.Rows[rowIndex].Cells[8].Value.ToString(),
			dgv.Rows[rowIndex].Cells[12].Value.ToString(),
			dgv.Rows[rowIndex].Cells[11].Value.ToString(),
			dgv.Rows[rowIndex].Cells[13].Value.ToString(),
			dgv.Rows[rowIndex].Cells[17].Value.ToString());
		return s;
	}
}
"}

	sdim buf, 260
	aRefs = {"
System.dll
System.IO.dll
System.Data.dll
System.Xml.dll
System.Windows.Forms.dll
System.Drawing.dll
System.Runtime.InteropServices.dll
System.Threading.dll
System.Reflection.dll"}

	rowSelTmp = -1 : rowCnt1 = 0 : rowCnt2 = 0
	sdim bufIP, 1024
	sdim bufMB, 1024 * 64
	sdim buf, 1024

	screen 0, ginfo_dispx, ginfo_dispy, 2, -1, -1, 600, 400
	GetWindowLong hwnd, -16
	SetWindowLong hwnd, -16, stat | 0x00050000
	SetWindowPos hwnd, 0, 0, 0, 0, 0, 0x23
	title strf("HSPHelp (%3d/%3d)", rowCnt2, rowCnt1)
	objmode 2 : font "メイリオ", 10
	if ( CSMakeMod(cs) == 0 ){ dialog "err" : end }
	notesel aRefs
	repeat notemax
		noteget buf, cnt
		ret = CSCAddRef(cs, buf)
	loop
	if ( CSCNew(cs, src, "Dgv", cDGV) == 0 ){ dialog "err2" : end }
	v1 = "hsphelp.xml" : exist v1
	if ( strsize != -1 ){ gosub *BTN_LOAD2 }

	hDgv = CSCall(cDGV, "GetWnd")
	SetParent hDgv, hwnd
	GetWindowLong hDgv, -16
	SetWindowLong hDgv, -16, stat | 0x40000000
	MoveWindow hDgv, 0, 0, ginfo_winx, ginfo_winy, 1
	ShowWindow hDgv, 1
	v1 = hwnd : ret = CSCall1(cDGV, "SetTarget", v1)
	input bufIP, 0, 0 : hIP = objinfo(stat, 2)
	objsize 0, 0
	button gosub "Open", *BTN_OPEN : hBtnOpen = objinfo(stat, 2)
	button gosub "Load", *BTN_LOAD : hBtnLoad = objinfo(stat, 2)
	button gosub "Save", *BTN_SAVE : hBtnSave = objinfo(stat, 2)
	mesbox bufMB, 0, 0, 0 : hMB = objinfo(stat, 2)
	oncmd gosub *WM_SIZE,     0x0005
	oncmd gosub *WM_COPYDATA, 0x004a
	oncmd gosub *WM_COMMAND,  0x0111
	gosub *WM_SIZE : gsel 0, 1
	stop

*BTN_OPEN
 	rowCnt1 = CSCall(cDGV, "LoadHS")
 	rowCnt2 = CSCall(cDGV, "GetRows2")
 	title strf("HSPHelp (%3d/%3d)", rowCnt2, rowCnt1)
	rowSelTmp = -1
	return

*BTN_LOAD
	dialog "xml", 16
	if ( stat == 0 ){ return }
	v1 = refstr
*BTN_LOAD2
	rowCnt1 = CSCall1(cDGV, "LoadXml", v1)
 	rowCnt2 = CSCall(cDGV, "GetRows2")
	title strf("HSPHelp (%3d/%3d)", rowCnt2, rowCnt1)
	rowSelTmp = -1
	return

*BTN_SAVE
	dialog "xml", 17
	if ( stat == 0 ){ return }
	v1 = refstr
	ret = CSCall1(cDGV, "SaveXml", v1)
	return

*WM_SIZE
	x = ginfo_winx - 150 : y = (ginfo_winy - 24) / 2
	MoveWindow hIP, 0, 0, x, 24, 1
	MoveWindow hBtnOpen, x, 0, 50, 24, 1
	MoveWindow hBtnLoad, x + 50, 0, 50, 24, 1
	MoveWindow hBtnSave, x + 100, 0, 50, 24, 1
	MoveWindow hMB, 0, 24, ginfo_winx, y, 1
	MoveWindow hDgv, 0, 24 + y, ginfo_winx, y, 1
	return

*WM_COPYDATA
	dupptr dp, lparam, 12, 4
	if ( dp(2) ){
		dupptr dp2, dp(2), 8, 4
		if ( rowSelTmp != dp2(1) ){
			rowSelTmp = dp2(1)
			v1 = dp2(1) : buf = CSCall1(cDGV, "GetData", v1)
			sendmsg hMB, 0x000C, 0, varptr(buf)
		}
	}
	return

*WM_COMMAND
	if ( lparam == hIP ){
		hw = wparam >> 16
		if ( hw == 0x0300 ){
			sendmsg hIP,  0x000D, 1024, varptr(buf)
			v1 = buf
			if ( v1 != "" ){
				v2 = strf("シンボル名 LIKE '*%s*' or 解説文 LIKE '*%s*' or 関連項目 LIKE '*%s*'", v1, v1, v1)
			}
			else { v2 = "" }
			rowCnt2 = CSCall1(cDGV, "SetFilter", v2)
			if ( rowCnt2 ){ ret = CSCall1(cDGV, "SetSymbolCell", v1) }
			title strf("HSPHelp (%3d/%3d)", rowCnt2, rowCnt1)
		}
	}
	return
コメント ( 0 ) | Trackback ( 0 )

mod_CSharp.hsp

mod_CSharp.hsp
#ifndef MOD_CSHARP_HSP_
#define global MOD_CSHARP_HSP_

#include "kernel32.as"
#include "mod_HostCLR.hsp"

#ifndef SysAllocString
#uselib "Oleaut32.dll"
#func global SysAllocString        "SysAllocString"        wstr
#func global SysFreeString         "SysFreeString"         int
#func global VariantInit           "VariantInit"           var
#func global VariantClear          "VariantClear"          var
#func global VariantChangeType     "VariantChangeType"     var,var,int,int
#func global SafeArrayCreate       "SafeArrayCreate"       int,int,var
#func global SafeArrayCreateVector "SafeArrayCreateVector" int,int,int
#func global SafeArrayDestroy      "SafeArrayDestroy"      int
#func global SafeArrayAccessData   "SafeArrayAccessData"   int,var
#func global SafeArrayUnaccessData "SafeArrayUnaccessData" int
#func global SafeArrayGetElement   "SafeArrayGetElement"   int,var,var
#func global SafeArrayPutElement   "SafeArrayPutElement"   int,var,var
#func global SafeArrayPutElementP  "SafeArrayPutElement"   int,var,int
#endif

#ifndef IUnknown
#define global IID_IUnknown "{00000000-0000-0000-C000-000000000046}"
#usecom global IUnknown IID_IUnknown "{}"
#comfunc global IUnknown_QueryInterface  0 var,var
#comfunc global IUnknown_AddRef          1
#comfunc global IUnknown_Release         2
#endif

#ifndef IDispatch
#define global IID_IDispatch "{00020400-0000-0000-C000-000000000046}"
#usecom global IDispatch IID_IDispatch "{}"
#comfunc global IDispatch_QueryInterface    0 var,var
#comfunc global IDispatch_AddRef            1
#comfunc global IDispatch_Release           2
#comfunc global IDispatch_GetTypeInfoCount  3 var
#comfunc global IDispatch_GetTypeInfo       4 int,int,int
#comfunc global IDispatch_GetIDsOfNames     5 var,var,int,int,var
#comfunc global IDispatch_Invoke            6 int,var,int,int,var,int,int,int
#endif

#ifndef IEnumUnknown
#define global IID_IEnumUnknown "{00000100-0000-0000-C000-000000000046}"
#usecom global IEnumUnknown IID_IEnumUnknown "{}"
#comfunc global IEnumUnknown_Next   3 int,var,int
#comfunc global IEnumUnknown_Skip   4 int
#comfunc global IEnumUnknown_Reset  5
#comfunc global IEnumUnknown_Clone  6 var
#endif

#module mod_CSharp mCor, mApp, mCSPrm, mCSCode

#modinit str sVer, str sPath, str sPath2
	mCor = 0 : mApp = 0 : mCSPrm = 0 : mCSCode = 0
	dim mi, 16
	mi(0) = 0xcb2f6723, 0x11d2ab3a, 0xc000409c, 0x3e0aa34f
	mi(4) = 0xcb2f6722, 0x11d2ab3a, 0xc000409c, 0x3e0aa34f
	if ( sVer == "" ){ mi(8) = 0 }
	else { sdim buf, (strlen(sVer) + 1) * 2 : cnvstow buf, sVer : mi(8) = varptr(buf) }
	CorBindToRuntimeEx mi(8), 0, 3, mi, mi(4), mi(9)
	if ( stat >= 0 ){
		newcom mCor, ICorRuntimeHost, -1, mi(9) : ICorRuntimeHost_Start mCor : ICorRuntimeHost_CreateDomainSetup mCor, mi(8)
		if ( stat == 0 ){
			lNumAppp++ : newcom cMI1, AppDomainSetup, -1, mi(8)
			if ( sPath != "" ){
				SysAllocString sPath : mi(9) = stat : AppDomainSetup_SetApplicationBase cMI1, mi(9) : SysFreeString mi(9)
			}
			if ( sPath2 != "" ){
				SysAllocString sPath2 : mi(9) = stat : AppDomainSetup_SetPrivateBinPath cMI1, mi(9) : SysFreeString mi(9)
			}
			ICorRuntimeHost_CreateDomainEx mCor, "AppDomain" + lNumAppp, mi(8), 0, mi(10)
			if ( stat == 0 ){ newcom mApp, _AppDomain, -1, mi(10) }
			delcom cMI1
		}
	}
	buf = CSGetSysDir() + "System.dll"
	buf2 = "System.CodeDom.Compiler.CompilerParameters"
	if ( CSCNewObj(thismod, buf, buf2, mCSPrm) == 0 ){ return 0 }
	buf2 = "Microsoft.CSharp.CSharpCodeProvider"
	if ( CSCNewObj(thismod, buf, buf2, mCSCode) == 0 ){ return 0 }
	return 1

#modterm
	if ( vartype(mCSCode) == 6 ){ if ( varuse(mCSCode) ){ delcom mCSCode } }
	if ( vartype(mCSPrm) == 6 ){ if ( varuse(mCSPrm) ){ delcom mCSPrm } }
	if ( vartype(mCOR) == 6 ){ if ( varuse(mCOR) ){
		if ( vartype(mApp) == 6 ){ 	if ( varuse(mApp) ){ dupptr dpMI, varptr(mApp), 4, 4 : ICorRuntimeHost_UnloadDomain mCOR, dpMI : delcom mApp } }
		ICorRuntimeHost_Stop mCOR : delcom mCOR
	} }
	return

#modcfunc CSCNewObj str sFile, str sType, var cObj
	if ( vartype(mApp) != 6 ){ return 0 }
	if ( varuse(mApp) == 0 ){ return 0 }
	dim no, 8 : SysAllocString sFile : no(1) = stat : SysAllocString sType : no(2) = stat
	_AppDomain_CreateInstanceFrom mApp, no(1), no(2), no(3)
	if ( stat == 0 ){
		newcom cNO1, _ObjectHandle, -1, no(3) : no(4) = 0, 0, 0, 0 : _ObjectHandle_Unwrap cNO1, no(4)
		if ( stat == 0 ){
			if ( no(4) == 13 ){ newcom cNO2, IUnknown, -1, no(6) }
			else { if ( no(4) == 9 ){ newcom cNO2, IDispatch, -1, no(6) } }
			if ( no(4) == 9 || no(4) == 13 ){ querycom cObj, cNO2, _Object : if ( varuse(cObj) ){ no(0) = 1 } delcom cNO2 }
		}
		delcom cNO1
	}
	SysFreeString no(1) : SysFreeString no(2)
	if ( no(0) == 0 ){ return 0 }
	dupptr dpNO, varptr(cObj), 4, 4
	return dpNO

#modcfunc CSCSetTarget str sTarget
	dim stg, 4
	buf = CSGetProp(mCSPrm, "CompilerOptions")
	if ( vartype(buf) == 2 ){ stg = instr(buf, 0, "/target") : if ( stg == -1 ){ stg = instr(buf, 0, "/TARGET") } }
	else { stg = -1 : buf = "" }
	if ( stg != -1 ){
		stg(1) = stg + 7 : stg(2) = instr(buf, stg(1), "/")
		if ( stg(2) == -1 ){ buf2 = strmid(buf, 0, stg) }
		else { buf2 = strmid(buf, 0, stg) + " " : stg(3) = stg(1) + stg(2) : buf2 += strmid(buf, stg(3), strlen(buf) - stg(3)) }
	}
	else { buf2 = buf }
	stg = strlen(buf2)
	if ( stg ){ if ( peek(buf2, stg - 1) != ' ' ){ buf2 += " " } }
	buf2 += sTarget
	return CSCSetOption(thismod, buf2)

#modcfunc CSCGetOption
	return CSGetProp(mCSPrm, "CompilerOptions")

#modcfunc CSCSetOption str sData
	return CSSetPropStr(mCSPrm, "CompilerOptions", sData)

#modcfunc CSCGetGenExe
	return CSGetProp(mCSPrm, "GenerateExecutable")

#modcfunc CSCSetGenExe int bGen
	return CSSetProp2(mCSPrm, "GenerateExecutable", 11, bGen)

#modcfunc CSCGetGenMem
	return CSGetProp(mCSPrm, "GenerateInMemory")

#modcfunc CSCSetGenMem int bGen
	return CSSetProp2(mCSPrm, "GenerateInMemory", 11, bGen)

#modcfunc CSCGetIncDebugInfo
	return CSGetProp(mCSPrm, "IncludeDebugInformation")

#modcfunc CSCSetIncDebugInfo int bGen
	return CSSetProp2(mCSPrm, "IncludeDebugInformation", 11, bGen)

#modcfunc CSCGetMainClass
	return CSGetProp(mCSPrm, "MainClass")

#modcfunc CSCSetMainClass str sData
	return CSSetPropStr(mCSPrm, "MainClass", sData)

#modcfunc CSCGetOutputAsm
	return CSGetProp(mCSPrm, "OutputAssembly")

#modcfunc CSCSetOutputAsm str sData
	return CSSetPropStr(mCSPrm, "OutputAssembly", sData)

#modcfunc CSCGetWarnAsErr
	return CSGetProp(mCSPrm, "TreatWarningsAsErrors")

#modcfunc CSCSetWarnAsErr int bGen
	return CSSetProp2(mCSPrm, "TreatWarningsAsErrors", 11, bGen)

#modcfunc CSCGetWarnLv
	return CSGetProp(mCSPrm, "WarningLevel")

#modcfunc CSCSetWarnLv int nLevel
	return CSSetProp2(mCSPrm, "WarningLevel", 3, nLevel)

#modcfunc CSCRefInit var cObj
	dim ri, 5
	ri(4) = 0
	if ( CSGetProp3(mCSPrm, "ReferencedAssemblies", 0, ri) ){
		if ( ri == 13 ){ newcom cRI1, IUnknown, -1, ri(2) : querycom cObj, cRI1, _Object : if ( varuse(cObj) ){ ri(4) = 1 } else { delcom cObj } delcom cRI1 }
	}
	return ri(4)

#modcfunc CSCGetRef array aRef
	dim gr, 10
	if ( CSCRefInit(thismod, cGR1) == 0 ){ return 0 }
	if ( CSGetProp3(cGR1, "Count", 0, gr) ){
		SafeArrayCreateVector 12, 0, 1 : gr(4) = stat : gr(5) = 3, 0 : sdim aRef, 64, gr(2)
		repeat gr(2)
			gr(7) = cnt : SafeArrayPutElement gr(4), gr(6), gr(5)
			if ( CSGetProp3(cGR1, "Item", gr(4), gr) ){ if ( gr == 8 ){ aRef(cnt) = CSCCnvBstr(gr(2)) : gr(9)++ } }
		loop
		SafeArrayDestroy gr(4)
	}
	delcom cGR1
	return gr(9)

#modcfunc CSCAddRef str sData
	dim ar, 6
	if ( CSCRefInit(thismod, cAR1) == 0 ){ return 0 }
	SafeArrayCreateVector 12, 0, 1 : ar = stat
	SysAllocString sData : ar(1) = 8, 0, stat, 0
	SafeArrayPutElement ar, ar(5), ar(1)
	ar(1) = CSInvoke(cAR1, "Add", 28, 0, ar, ar(2))
	SafeArrayDestroy ar : delcom cAR1
	if ( ar(1) == 0 ){ return 0 }
	return 1

#modcfunc CSCClearRef
	if ( CSCRefInit(thismod, cCR1) == 0 ){ return 0 }
	dim cr, 5
	cr(4) = CSInvoke(cCR1, "Clear", 28, 0, 0, cr)
	delcom cCR1
	if ( cr(4) == 0 ){ return 0 }
	return 1

#modcfunc CSCl2 str sSrc, var cAsm, var cObjErr
	dim cle, 13
	SafeArrayCreateVector 12, 0, 2 : cle(1) = stat
	if ( cle(1) ){
		dupptr dpCSCL, varptr(mCSPrm), 4, 4 : cle(2) = 0, 13, 0, dpCSCL, 0 : SafeArrayPutElement cle(1), cle(2), cle(3) : SafeArrayCreateVector 8, 0, 1 : cle(7) = stat
		if ( cle(7) ){
			SysAllocString sSrc : cle(8) = stat : SafeArrayPutElementP cle(7), cle(2), cle(8) : cle(2) = 1, 0x2008, 0, cle(7) : SafeArrayPutElement cle(1), cle(2), cle(3) : cle = CSInvoke(mCSCode, "CompileAssemblyFromSource", 28, 0, cle(1), cle(9)) : SysFreeString cle(8) : SafeArrayDestroy cle(7)
			if ( cle ){
				newcom cCSCL1, IUnknown, -1, cle(11) : querycom cObjErr, cCSCL1, _Object
				if ( varuse(cObjErr) == 0 ){ cle = 0 }
				else { if ( CSCErrLen(thismod, cObjErr) == 0 ){ if ( CSGetProp3(cObjErr, "CompiledAssembly", 0, cle(2)) ){ if ( cle(2) == 9 ){ newcom cAsm, _Assembly, -1, cle(4) } if ( cle(2) == 13 ){ newcom cCSCL2, IUnknown, -1, cle(4) : querycom cAsm, cCSCL2, _Assembly : delcom cCSCL2 } } } }
				delcom cCSCL1
			}
		}
		SafeArrayDestroy cle(1)
	}
	return cle

#modcfunc CSCl str sSrc, var cAsm
	cle = CSCl2(thismod, sSrc, cAsm, cSC) : delcom cSC
	return cle

#modcfunc CSCMakeDll2 str sSrc, str sFile, var cObj, var cObjErr
	if ( CSCSetTarget(thismod, "/target:library") == 0 ){ return 0 }
	if ( CSCSetGenExe(thismod, 0) == 0 ){ return 0 }
	if ( CSCSetGenMem(thismod, 1) == 0 ){ return 0 }
	if ( CSCSetOutputAsm(thismod, sFile) == 0 ){ return 0 }
	if ( CSCl2(thismod, sSrc, cObj, cObjErr) == 0 ){ return 0 }
	if ( CSCErrLen(thismod, cObjErr) != 0 ){ return 0 }
	return 1

#modcfunc CSCMakeDll str sSrc, str sFile
	md = CSCMakeDLL2(thismod, sSrc, sFile, cMD1, cMD2) : cMD2 = 0 : cMD1 = 0
	return md

#modcfunc CSCMakeWin2 str sSrc, str sFile, var cObj, var cObjErr
	if ( CSCSetTarget(thismod, "/target:winexe") == 0 ){ return 0 }
	if ( CSCSetGenExe(thismod, 1) == 0 ){ return 0 }
	if ( CSCSetGenMem(thismod, 1) == 0 ){ return 0 }
	if ( CSCSetOutputAsm(thismod, sFile) == 0 ){ return 0 }
	if ( CSCl2(thismod, sSrc, cObj, cObjErr) == 0 ){ return 0 }
	if ( CSCErrLen(thismod, cObjErr) != 0 ){ return 0 }
	return 1

#modcfunc CSCMakeWin str sSrc, str sFile
	mw = CSCMakeWin2(thismod, sSrc, sFile, cMW1, cMW2) : cMW2 = 0 : cMW1 = 0
	return mw

#modcfunc CSCMakeCon2 str sSrc, str sFile, var cObj, var cObjErr
	if ( CSCSetTarget(thismod, "/target:exe") == 0 ){ return 0 }
	if ( CSCSetGenExe(thismod, 1) == 0 ){ return 0 }
	if ( CSCSetGenMem(thismod, 1) == 0 ){ return 0 }
	if ( CSCSetOutputAsm(thismod, sFile) == 0 ){ return 0 }
	if ( CSCl2(thismod, sSrc, cObj, cObjErr) == 0 ){ return 0 }
	if ( CSCErrLen(thismod, cObjErr) != 0 ){ return 0 }
	return 1

#modcfunc CSCMakeCon str sSrc, str sFile
	mc = CSCMakeCon2(thismod, sSrc, sFile, cMC1, cMC2) : cMC2 = 0 : cMC1 = 0
	return mc

#modcfunc CSCErrInit str sName, var cObjErr, var cObj
	if ( vartype(cObjErr) != 6 ){ return 0 }
	if ( varuse(cObjErr) == 0 ){ return 0 }
	dim ei, 5
	if ( CSGetProp3(cObjErr, sName, 0, ei) ){ if ( ei == 13 ){ newcom cEI1, IUnknown, -1, ei(2) : querycom cObj, cEI1, _Object : if ( varuse(cObj) ){ ei(4) = 1 } else { delcom cObj } delcom cEI1 } }
	return ei(4)

#modcfunc CSCErrLen var cObjErr
	if ( CSCErrInit(thismod, "Errors", cObjErr, cEL1) == 0 ){ return -1 }
	dim el, 5 : el(4) = CSGetProp3(cEL1, "Count", 0, el) : delcom cEL1
	if ( el(4) == 0 ){ VariantClear el : return -1 }
	return el(2)

#modcfunc CSCErrList var cObjErr, array aErrList
	sdim aErrList, 64, 5, 1
	if ( CSCErrInit(thismod, "Errors", cObjErr, cELT1) == 0 ){ return 0 }
	dim elt, 10
	if ( CSGetProp3(cELT1, "Count", 0, elt) ){
		sdim aErrList, 64, 5, elt(2) : SafeArrayCreateVector 12, 0, 1 : elt(4) = stat : elt(5) = 3, 0
		repeat elt(2)
			elt(7) = cnt : SafeArrayPutElement elt(4), elt(6), elt(5)
			if ( CSGetProp3(cELT1, "Item", elt(4), elt) ){
				if ( elt == 13 ){
					newcom cELT2, IUnknown, -1, elt(2) : querycom cELT3, cELT2, _Object
					if ( varuse(cELT3) ){
						aErrList(0, cnt) = CSGetProp(cELT3, "FileName") : aErrList(1, cnt) = str(CSGetProp(cELT3, "Column"))
						aErrList(2, cnt) = str(CSGetProp(cELT3, "Line")) : aErrList(3, cnt) = CSGetProp(cELT3, "ErrorNumber")
						aErrList(4, cnt) = CSGetProp(cELT3, "ErrorText") : elt(9)++ : delcom cELT3
					}
					delcom cELT3 : delcom cELT2
				}
			}
		loop
		SafeArrayDestroy elt(4)
	}
	delcom cELT1
	return elt(9)

#modcfunc CSCErrOutput var cObjErr, var sOutput
	if ( CSCErrInit(thismod, "Output", cObjErr, cEOP1) == 0 ){ return 0 }
	sOutput = "" : dim eop, 10
	if ( CSGetProp3(cEOP1, "Count", 0, eop) ){
		SafeArrayCreateVector 12, 0, 1 : eop(4) = stat : eop(5) = 3, 0
		repeat eop(2)
			eop(7) = cnt : SafeArrayPutElement eop(4), eop(6), eop(5)
			if ( CSGetProp3(cEOP1, "Item", eop(4), eop) ){
				if ( eop == 8 ){ sOutput += strf("%s¥n", CSCCnvBstr(eop(2))) : eop(9)++ }
			}
		loop
		SafeArrayDestroy eop(4)
	}
	delcom cEOP1
	return eop(9)

#modcfunc CSCLoad str sAsm, var cAsm
	dim cld, 3
	SysAllocString sAsm : cld = stat
	_AppDomain_Load_2 mApp, cld, cld(1) : cld(2) = stat
	if ( cld(2) == 0 ){ if ( cld(1) == 0 ){ cld(2) = -1 } }
	if ( cld(2) == 0 ){ newcom cAsm, _Assembly, -1, cld(1) }
	SysFreeString cld
	if ( cld(2) ){ return 0 }
	return 1

#modcfunc CSCInstance str sName, var cAsm, var cObj
	if ( vartype(cAsm) != 6 ){ return 0 }
	if ( varuse(cAsm) == 0 ){ return 0 }
	dim cit, 6 : SysAllocString sName : cit = stat
	_Assembly_CreateInstance cAsm, cit, cit(1) : cit(5) = stat
	if ( cit(5) == 0 ){ newcom cObj, _Object, -1, cit(3) }
	SysFreeString cit
	if ( cit(5) ){ return 0 }
	return 1

#modcfunc CSCNew str sSrc, str sName, var cObj
	if ( CSCSetTarget(thismod, "") == 0 ){ return 0 }
	if ( CSCSetGenExe(thismod, 0) == 0 ){ return 0 }
	if ( CSCSetGenMem(thismod, 1) == 0 ){ return 0 }
	if ( CSCSetOutputAsm(thismod, "") == 0 ){ return 0 }
	if ( CSCl2(thismod, sSrc, cNEW1, cNEW2) == 0 ){ return 0 }
	nw = 0
	if ( CSCErrLen(thismod, cNEW2) == 0 ){ if ( CSCInstance(thismod, sName, cNEW1, cObj) ){ nw = 1 } : delcom cNEW1 }
	delcom cNEW2
	return nw

#defcfunc CSMakeMod var modCS
#ifndef _debug
	newmod modCS, mod_CSharp, CSGetNewVer(), "", ""
	return stat
#else
	newmod modCS, mod_CSharp, CSGetNewVer(), dir_cur, ""
	return stat
#endif

#defcfunc CSCCnvBstr int pBstr
	lstrlenW pBstr : dupptr dpCVB, pBstr, (stat + 1) * 2, 2 : bufCVB = cnvwtos(dpCVB) : SysFreeString pBstr
	return bufCVB

#defcfunc CSCGetType var cObj, var cType
	if ( vartype(cObj) != 6 ){ return 0 }
	if ( varuse(cObj) == 0 ){ return 0 }
	gt = 0 : _Object_GetType cObj, gt
	if ( stat ){ return 0 }
	newcom cType, _Type, -1, gt
	return 1

#defcfunc CSPropInit var cObj, str sName, var cProp
	if ( CSCGetType(cObj, cGS1) == 0 ){ return 0 }
	dim gs, 3 : SysAllocString sName : gs = stat
	_Type_GetProperty_7 cGS1, gs, gs(1) : gs(2) = stat
	SysFreeString gs
	if ( gs(2) != 0 || gs(1) == 0 ){ delcom cGS1 : return 0 }
	newcom cProp, _PropertyInfo, -1, gs(1)
	delcom cGS1 : dupptr dpGS, varptr(cObj), 4, 4
	return dpGS

#defcfunc CSGetProp3 var cObj, str sName, int psaId, var vProp
	gs2 = CSPropInit(cObj, sName, cGS2)
	if ( gs2 ){ _PropertyInfo_GetValue cGS2, 13, 0, gs2, 0, psaId, vProp : gs2 = stat : delcom cGS2 }
	if ( gs2 ){ return 0 }
	return 1

#defcfunc CSGetProp2 var cObj, str sName, var vProp
	return CSGetProp3(cObj, sName, 0, vProp)

#defcfunc CSGetPropA var cObj, str sName, array aProp
	dim gs3, 6
	if ( CSGetProp3(cObj, sName, 0, gs3) == 0 ){ return 0 }
	if ( gs3 != 27 ){ VariantClear gs3 : return 0 }
	dupptr dpGS, gs3(2), 24, 4 : gs3(4) = dpGS(4)
	if ( dpGS >> 16 != 1 || dpGS(1) != 16 ){ SafeArrayDestroy gs3(2) : return 0 }
	SafeArrayAccessData gs3(2), gs3(5)
	dupptr dpGS, gs3(5), gs3(4) * 16, 4
	if ( dpGS == 8 ){ sdim aProp, 64, gs3(4) : repeat gs3(4) : aProp(cnt) = CSCCnvBstr(dpGS(cnt * 4 + 2)) : loop }
	else {
		if ( dpGS == 5 ){ ddim aProp, gs3(4) : repeat gs3(4) : dupptr dpGS2, varptr(dpGS(cnt * 4 + 2)), 8, 3 : aProp(cnt) = dpGS2 : loop }
		else { dim aProp, gs3(4) : repeat gs3(4) : aProp(cnt) = dpGS(cnt * 4 + 2) : loop }
	}
	SafeArrayUnaccessData gs3(2) : SafeArrayDestroy gs3(2)
	return gs3(4)

#defcfunc CSGetProp var cObj, str sName
	dim gs3, 4
	if ( CSGetProp3(cObj, sName, 0, gs3) == 0 ){ return 0 }
	if ( gs3 == 8 ){ return CSCCnvBstr(gs3(2)) }
	if ( gs3 == 5 ){ dupptr dpGS, varptr(gs3(2)), 8, 3 : return dpGS }
	return gs3(2)

#defcfunc CSSetProp3 var cObj, str sName, int psaId, var vProp
	gs2 = CSPropInit(cObj, sName, cGS2)
	if ( gs2 == 0 ){ return 0 }
	dupptr dpGS, varptr(vProp), 16, 4
	_PropertyInfo_SetValue cGS2, 13, 0, gs2, 0, dpGS(0), dpGS(1), dpGS(2), dpGS(3), psaId
	gs2 = stat : delcom cGS2
	if ( gs2 ){ return 0 }
	return 1

#defcfunc CSSetProp2 var cObj, str sName, int iVT, int iProp
	gs3 = iVT, 0, iProp, 0
	return CSSetProp3(cObj, sName, 0, gs3)

#defcfunc CSSetProp var cObj, str sName, var vProp
	dim gs3, 6 : gs3(4) = vartype(vProp)
	if ( gs3(4) == 2 ){ SysAllocString vProp : gs3(2) = stat : gs3 = 8 }
	else { if ( gs3(4) == 3 ){ gs3 = 4 : dupptr dpGS, varptr(gs3(2)), 8, 3 : dpGS = vProp } else { gs3 = 3 : gs3(2) = vProp } }
	gs3(5) = CSSetProp3(cObj, sName, 0, gs3)
	if ( gs3(4) == 2 ){ SysFreeString gs3(2) }
	return gs3(5)

#defcfunc CSSetPropStr var cObj, str sName, str sProp
	dim gs3, 5 : SysAllocString sProp : gs3 = 8, 0, stat, 0 : gs3(4) = CSSetProp3(cObj, sName, 0, gs3) : SysFreeString gs3(2)
	return gs3(4)

#defcfunc CSFieldInit var cObj, str sName, var cField
	if ( CSCGetType(cObj, cGS1) == 0 ){ return 0 }
	dim gs, 10 : SysAllocString sName : gs = stat : _Type_GetField_2 cGS1, gs, gs(1) : gs(2) = stat : SysFreeString gs
	if ( gs(2) != 0 || gs(1) == 0 ){ delcom cGS1 : return 0 }
	newcom cField, _FieldInfo, -1, gs(1) : delcom cGS1 : dupptr dpGS, varptr(cObj), 4, 4
	return dpGS

#defcfunc CSGetField2 var cObj, str sName, var vField
	gs2 = CSFieldInit(cObj, sName, cGS2)
	if ( gs2 == 0 ){ return 0 }
	_FieldInfo_GetValue cGS2, 13, 0, gs2, 0, vField : gs2 = stat : delcom cGS2
	if ( gs2 ){ return 0 }
	return 1

#defcfunc CSGetFieldA var cObj, str sName, array aField
	dim gs3, 6
	if ( CSGetField2(cObj, sName, gs3) == 0 ){ return 0 }
	if ( gs3 != 27 ){ VariantClear gs3 : return 0 }
	dupptr dpGS, gs3(2), 24, 4 : gs3(4) = dpGS(4)
	if ( dpGS >> 16 != 1 || dpGS(1) != 16 ){ SafeArrayDestroy gs3(2) : return 0 }
	SafeArrayAccessData gs3(2), gs3(5) : dupptr dpGS, gs3(5), gs3(4) * 16, 4
	if ( dpGS == 8 ){ sdim aField, 64, gs3(4) : repeat gs3(4) : aField(cnt) = CSCCnvBstr(dpGS(cnt * 4 + 2)) : loop }
	else {
		if ( dpGS == 5 ){ ddim aField, gs3(4) : repeat gs3(4) : dupptr dpgs3, varptr(dpGS(cnt * 4 + 2)), 8, 3 : aField(cnt) = dpgs3 : loop }
		else { dim aField, gs3(4) : repeat gs3(4) : aField(cnt) = dpGS(cnt * 4 + 2) : loop }
	}
	SafeArrayUnaccessData gs3(2) : SafeArrayDestroy gs3(2)
	return 1

#defcfunc CSGetField var cObj, str sName
	dim gs3, 3
	if ( CSGetField2(cObj, sName, gs3) == 0 ){ return 0 }
	if ( gs3 == 8 ){ return CSCCnvBstr(gs3(2)) }
	else {
		if ( gs3 == 5 ){ dupptr dpGS, varptr(gs3(2)), 8, 3 : return dpGS }
		else { return gs3(2) }
	}
	return 1

#defcfunc CSSetField3 var cObj, str sName, var vField
	gs2 = CSFieldInit(cObj, sName, cGS2)
	if ( gs2 == 0 ){ return 0 }
	dupptr dpGS, varptr(vField), 16, 4 : _FieldInfo_SetValue_2 cGS2, 13, 0, gs2, 0, dpGS(0), dpGS(1), dpGS(2), dpGS(3) : gs2 = stat : delcom cGS2
	if ( gs2 ){ return 0 }
	return 1

#defcfunc CSSetField2 var cObj, str sName, int iVT, int iField
	gs3 = iVT, 0, iField, 0
	return CSSetField3(cObj, sName, gs3)

#defcfunc CSSetField var cObj, str sName, var vField
	dim gs3, 6 : gs3(4) = vartype(vField)
	if ( gs3(4) == 2 ){ SysAllocString vField : gs3(2) = stat : gs3 = 8 }
	else {
		if ( gs3(4) == 3 ){ gs3 = 4 : dupptr dpGS, varptr(gs3(2)), 8, 3 : dpGS = vField }
		else { gs3 = 3 : gs3(2) = vField }
	}
	gs3(5) = CSSetField3(cObj, sName, gs3)
	if ( gs3(4) == 2 ){ SysFreeString gs3(2) }
	return gs3(5)

#defcfunc CSSetFieldStr var cObj, str sName, str sField
	SysAllocString sField : gs3 = 8, 0, stat, 0 : gs3(4) = CSSetField3(cObj, sName, gs3) : SysFreeString gs3(2)
	return gs3(4)

#defcfunc CSInvoke var cObj, str sName, int fBind, int psaTypes, int psaArgs, var vRet
	if ( CSCGetType(cObj, cIV1) == 0 ){ return 0 }
	dim iv, 12 : SysAllocString sName : iv(0) = stat
	if ( psaTypes ){ _Type_GetMethod cIV1, iv(0), fBind, 0, psaTypes, 0, iv(1) }
	else { _Type_GetMethod_2 cIV1, iv(0), fBind, iv(1) }
	iv(2) = stat
	if ( iv(2) == 0 ){ if ( iv(1) == 0 ){ iv(2) = -1 } }
	if ( iv(2) == 0 ){
		newcom cIV2, _MethodInfo, -1, iv(1) : dupptr dpIV, varptr(cObj), 4, 4
		_MethodInfo_Invoke_3 cIV2, 13, 0, dpIV, 0, psaArgs, vRet : iv(2) = stat : delcom cIV2
	}
	delcom cIV1
	if ( iv(2) ){ return 0 }
	return 1

#defcfunc CSMakeArgs var vArgs, int iNum
	dim ma, iNum * 4 + 4 : dupptr dpMA, varptr(vArgs), iNum * 8, 4
	repeat iNum
		ma = dpMA(cnt * 2), dpMA(cnt * 2 + 1)
		if ( ma == 2 ){ lstrlenA ma(1) : dupptr dpMA2, ma(1), stat + 1, 2 : SysAllocString dpMA2 : ma(cnt * 4 + 4) = 8, 0, stat, 0 }
		else {
			if ( ma == 3 ){ ma(cnt * 4 + 4) = 5, 0 : dupptr dpMA2, ma(1), 8, 3 : dupptr dpMA3, varptr(ma(cnt * 4 + 6)), 8, 3 : dpMA3 = dpMA2 }
			else { dupptr dpMA2, ma(1), 4, 4 : ma(cnt * 4 + 4) = 3, 0, dpMA2, 0 }
		}
	loop
	ma = iNum * 16 : dupptr dpMA, varptr(ma(4)), ma, 4 : SafeArrayCreateVector 12, 0, iNum : ma(1) = stat
	if ( ma(1) ){
		ma(3) = 1 : SafeArrayAccessData ma(1), ma(2)
		if ( stat == 0 ){ dupptr dpMA2, ma(2), ma, 4 : memcpy dpMA2, dpMA, ma : SafeArrayUnaccessData ma(1) }
		else { ma(3) = 0 }
	}
	if ( ma(3) == 0 ){
		repeat iNum : VariantClear dpMA(cnt * 4) : loop
		return 0
	}
	return ma(1)

#defcfunc CSCallRet var vRet
	dupptr dpCR, varptr(vRet), 16, 4
	if ( dpCR == 8 ){ return CSCCnvBstr(dpCR(2)) }
	else { if ( dpCR == 5 ){ dupptr dpCR2, varptr(dpCR(2)), 8, 3 : return dpCR2 } else{ return dpCR(2) } }
	return 0

#defcfunc CSCall var cObj, str sName
	dim cl, 4
	if ( CSInvoke(cObj, sName, 28, 0, 0, cl) == 0 ){ return 0 }
	vaRet = CSCallRet(cl) : VariantClear cl
	return vaRet

#defcfunc CSCall1 var cObj, str sName, var v1
	dim cl2, 8 : cl2(6) = vartype(v1), varptr(v1) : cl2(4) = CSMakeArgs(cl2(6), 1)
	if ( cl2(4) == 0 ){ return 0 }
	cl2(5) = CSInvoke(cObj, sName, 28, 0, cl2(4), cl2)
	if ( cl2(5) ){ vaRet = CSCallRet(cl2) : Variantclear cl2 }
	SafeArrayDestroy cl2(4)
	if ( cl2(5) == 0 ){ return 0 }
	return vaRet

#defcfunc CSCall2 var cObj, str sName, var v1, var v2
	dim cl2, 10
	cl2(6) = vartype(v1), varptr(v1), vartype(v2), varptr(v2) : cl2(4) = CSMakeArgs(cl2(6), 2)
	if ( cl2(4) == 0 ){ return 0 }
	cl2(5) = CSInvoke(cObj, sName, 28, 0, cl2(4), cl2)
	if ( cl2(5) ){ vaRet = CSCallRet(cl2) : Variantclear cl2 }
	SafeArrayDestroy cl2(4)
	if ( cl2(5) == 0 ){ return 0 }
	return vaRet

#defcfunc CSCall3 var cObj, str sName, var v1, var v2, var v3
	dim cl2, 12
	cl2(6) = vartype(v1), varptr(v1), vartype(v2), varptr(v2), vartype(v3), varptr(v3)
	cl2(4) = CSMakeArgs(cl2(6), 3)
	if ( cl2(4) == 0 ){ return 0 }
	cl2(5) = CSInvoke(cObj, sName, 28, 0, cl2(4), cl2)
	if ( cl2(5) ){ vaRet = CSCallRet(cl2) : Variantclear cl2 }
	SafeArrayDestroy cl2(4)
	if ( cl2(5) == 0 ){ return 0 }
	return vaRet

#defcfunc CSCall4 var cObj, str sName, var v1, var v2, var v3, var v4
	dim cl2, 14
	cl2(6) = vartype(v1), varptr(v1), vartype(v2), varptr(v2), vartype(v3), varptr(v3), vartype(v4), varptr(v4)
	cl2(4) = CSMakeArgs(cl2(6), 4)
	if ( cl2(4) == 0 ){ return 0 }
	cl2(5) = CSInvoke(cObj, sName, 28, 0, cl2(4), cl2)
	if ( cl2(5) ){ vaRet = CSCallRet(cl2) : Variantclear cl2 }
	SafeArrayDestroy cl2(4)
	if ( cl2(5) == 0 ){ return 0 }
	return vaRet

#defcfunc CSGetClassList var cAsm, array aList
	sdim aList, 64, 1 : dim gmd, 4
	_Assembly_GetTypes cAsm, gmd : gmd(1) = stat
	if ( gmd(1) == 0 && gmd != 0 ){
		dupptr dpGMD1, gmd, 24, 4
		if ( dpGMD1(4) ){
			sdim aList, 64, dpGMD1(4) : SafeArrayAccessData gmd, gmd(2) : dupptr dpGMD2, gmd(2), dpGMD1(4) * 4, 4
			repeat dpGMD1(4)
				newcom cGMD1, _Type, -1, dpGMD2(cnt)
				if ( CSGetProp(cGMD1, "IsClass") ){ aList(gmd(3)) = CSGetProp(cGMD1, "FullName") : gmd(3)++ }
				delcom cGMD1
			loop
			SafeArrayUnaccessData gmd
		}
		SafeArrayDestroy gmd
	}
	return gmd(3)

#defcfunc CSGetPropList var cObj, array aList
	sdim aList, 64, 2, 1
	if ( CSCGetType(cObj, cGPL1) == 0 ){ return 0 }
	dim gpl, 6
	_Type_GetProperties_2 cGPL1, gpl : gpl(1) = stat
	if ( gpl(1) == 0 && gpl != 0 ){
		dupptr dpGPL, gpl, 24, 4
		if ( dpGPL(4) ){
			SafeArrayAccessData gpl, gpl(2) : dupptr dpGPL2, gpl(2), dpGPL(4) * 4, 4 : sdim aList, 64, 2, dpGPL(4)
			repeat dpGPL(4)
				newcom cGPL2, _PropertyInfo, -1, dpGPL2(cnt) : _PropertyInfo_name cGPL2, gpl(3)
				if ( stat == 0 ){ aList(0, cnt) = CSCCnvBstr(gpl(3)) }
				_PropertyInfo_PropertyType cGPL2, gpl(3)
				if ( stat == 0 ){ newcom cGPL3, _Type, -1, gpl(3) : _Type_ToString cGPL3, gpl(4) : aList(1, cnt) = CSCCnvBstr(gpl(4)) : delcom cGPL3 }
				delcom cGPL2 : gpl(5)++
			loop
			SafeArrayUnaccessData gpl
		}
		SafeArrayDestroy gpl
	}
	delcom cGPL1
	return gpl(5)

#defcfunc CSGetFieldList var cObj, array aList
	sdim aList, 64, 2, 1
	if ( CSCGetType(cObj, cGFL1) == 0 ){ return 0 }
	dim gfl, 6 : _Type_GetFields_2 cGFL1, gfl : gfl(1) = stat
	if ( gfl(1) == 0 && gfl != 0 ){
		dupptr dpGFL, gfl, 24, 4
		if ( dpGFL(4) ){
			SafeArrayAccessData gfl, gfl(2) : dupptr dpGFL2, gfl(2), dpGFL(4) * 4, 4 : sdim aList, 64, 2, dpGFL(4)
			repeat dpGFL(4)
				newcom cGFL2, _FieldInfo, -1, dpGFL2(cnt) : _FieldInfo_name cGFL2, gfl(3)
				if ( stat == 0 ){ aList(0, cnt) = CSCCnvBstr(gfl(3)) }
				_FieldInfo_FieldType cGFL2, gfl(3)
				if ( stat == 0 ){ newcom cGFL3, _Type, -1, gfl(3) : _Type_ToString cGFL3, gfl(4) : aList(1, cnt) = CSCCnvBstr(gfl(4)) : delcom cGFL3 }
				delcom cGFL2 : gfl(5)++
			loop
			SafeArrayUnaccessData gfl
		}
		SafeArrayDestroy gfl
	}
	delcom cGFL1
	return gfl(5)

#defcfunc CSGetMethodList var cObj, array aList
	sdim aList, 64, 3, 1
	if ( CSCGetType(cObj, cGML1) == 0 ){ return 0 }
	dim gml, 9 : _Type_GetMethods_2 cGML1, gml
	if ( stat == 0 && gml != 0 ){
		dupptr dpGML, gml, 24, 4
		if ( dpGML(4) ){
			SafeArrayAccessData gml, gml(1) : dupptr dpGML2, gml(1), dpGML(4) * 4, 4 : sdim aList, 64, 3, dpGML(4)
			repeat dpGML(4)
				newcom cGML2, _MethodInfo, -1, dpGML2(cnt) : _MethodInfo_name cGML2, gml(3)
				if ( stat == 0 ){
					aList(0, cnt) = CSCCnvBstr(gml(3)) : _MethodInfo_returnType cGML2, gml(2)
					if ( stat == 0 && gml(2) != 0 ){ newcom cGML3, _Type, -1, gml(2) : _Type_FullName cGML3, gml(2) : aList(1, cnt) = CSCCnvBstr(gml(2)) : delcom cGML3 }
					_MethodInfo_GetParameters cGML2, gml(2)
					if ( stat == 0 && gml(2) != 0 ){
						dupptr dpGML3, gml(2), 24, 4
						if ( dpGML3(4) ){
							SafeArrayAccessData gml(2), gml(3) : dupptr dpGML4, gml(3), dpGML3(4) * 4, 4 : buf = ""
							repeat dpGML3(4)
								newcom cGML3, _ParameterInfo, -1, dpGML4(cnt) : 
								if ( CSGetProp3(cGML3, "ParameterType", 0, gml(4)) ){ newcom cGML4, _Type, -1, gml(6) : _Type_FullName cGML4, gml(3) : if ( buf != "" ){ buf += "," } : buf += CSCCnvBstr(gml(3)) : delcom cGML4 }
								delcom cGML3
							loop
							SafeArrayUnaccessData gml(2) : aList(2, cnt) = buf
						}
					}
					gml(8)++
				}
				delcom cGML2
			loop
			SafeArrayUnaccessData gml
		}
		SafeArrayDestroy gml
	}
	delcom cGML1
	return gml(8)

#defcfunc CSGetMetaHost var cMeta
	dim gmh, 9
	gmh(0) = 0x9280188d, 0x48670e8e, 0xa87f0cb3, 0xdee88438
	gmh(4) = 0xd332db9e, 0x4125b9b3, 0x48a10782, 0x1632f584
	CLRCreateInstance gmh(0), gmh(4), gmh(8)
	if ( stat ){ return 0 }
	newcom cMeta, ICLRMetaHost, -1, gmh(8)
	return 1

#defcfunc CSGetVerList array aList
	if ( CSGetMetaHost(cGVL1) == 0 ){ return 0 }
	dim gvl, 2 : sdim buf, 520 : sdim aList, 520, 1
	ICLRMetaHost_EnumerateInstalledRuntimes cGVL1, gvl(1)
	if ( stat == 0 ){
		newcom cGVL2, IEnumUnknown, -1, gvl(1)
		repeat
			IEnumUnknown_Next cGVL2, 1, gvl(1), 0
			if ( stat ){ break }
			newcom cGVL3, ICLRRuntimeInfo, -1, gvl(1) : gvl(1) = 260 : ICLRRuntimeInfo_GetVersionString cGVL3, buf, gvl(1) : gvl(1) = stat : delcom cGVL3
			if ( gvl(1) ){ break }
			aList(gvl) = cnvwtos(buf) : gvl++
		loop
		delcom cGVL2
	}
	delcom cGVL1
	return gvl

#defcfunc CSGetSysDir
	sdim bufGSD, 520 : prmGSD = 0 : GetCORSystemDirectory bufGSD, 260, prmGSD
	if ( stat ){ return "" }
	return cnvwtos(bufGSD)

#defcfunc CSGetVer
	sdim bufGV, 520 : prmGVR = 0 : GetCORVersion bufGV, 260, prmGVR
	if ( stat ){ return "" }
	return cnvwtos(bufGV)

#defcfunc CSGetNewVer
	dim gnv, 7
	if ( CSGetVerList(aList) == 0 ){ return "" }
	gnv = length(aList)
	if ( gnv == 1 ){ return aList(0) }
	buf = aList(0) : buf2 = strmid(aList(0), 1, strlen(aList(0)) - 1) : gnv--
	repeat gnv, 1
		split buf2, ".", sb
		if ( length(sb) != 3 ){ continue }
		gnv(1) = int(sb(0)), int(sb(1)), int(sb(2)) : buf3 = strmid(aList(cnt), 1, strlen(aList(cnt)) - 1) : split buf3, ".", sb
		if ( length(sb) != 3 ){ continue }
		gnv(4) = int(sb(0)), int(sb(1)), int(sb(2))
		if ( gnv(4) > gnv(1) ){ buf = aList(cnt) }
		else { if ( gnv(4) == gnv(1) ){ if ( gnv(5) > gnv(2) ){ buf = aList(cnt) } else { if ( gnv(5) == gnv(2) ){ if ( gnv(6) > gnv(3) ){ buf = aList(cnt) } } } } }
	loop
	aList = 0
	return buf

#global

#endif // MOD_CSHARP_HSP_
コメント ( 0 ) | Trackback ( 0 )

mod_HostCLR.hsp

mod_HostCLR.hsp
#ifndef MOD_HOSTCLR_HSP_
#define global MOD_HOSTCLR_HSP_

#ifndef CLRCreateInstance
#uselib "MSCorEE.dll"
#func global CLRCreateInstance       "CLRCreateInstance"       var,var,var
#func global CorBindToRuntimeEx      "CorBindToRuntimeEx"      int,int,int,var,var,var
#func global GetCORRequiredVersion   "GetCORRequiredVersion"   var,int,var
#func global GetCORSystemDirectory   "GetCORSystemDirectory"   var,int,var
#func global GetCORVersion           "GetCORVersion"           var,int,var
#func global GetRequestedRuntimeInfo "GetRequestedRuntimeInfo" int,int,int,int,int,var,int,var,var,int,var
#endif

#ifndef ICorRuntimeHost
#define global IID_ICorRuntimeHost  "{CB2F6722-AB3A-11d2-9C40-00C04FA30A3E}"
#define global CLSID_CorRuntimeHost "{CB2F6723-AB3A-11d2-9C40-00C04FA30A3E}"
#usecom global ICorRuntimeHost IID_ICorRuntimeHost CLSID_CorRuntimeHost
#comfunc global ICorRuntimeHost_CreateLogicalThreadState     3
#comfunc global ICorRuntimeHost_DeleteLogicalThreadState     4
#comfunc global ICorRuntimeHost_SwitchInLogicalThreadState   5 var
#comfunc global ICorRuntimeHost_SwitchOutLogicalThreadState  6 var
#comfunc global ICorRuntimeHost_LocksHeldByLogicalThread     7 var
#comfunc global ICorRuntimeHost_MapFile                      8 int,var
#comfunc global ICorRuntimeHost_GetConfiguration             9 var
#comfunc global ICorRuntimeHost_Start                       10
#comfunc global ICorRuntimeHost_Stop                        11
#comfunc global ICorRuntimeHost_CreateDomain                12 wstr,int,var
#comfunc global ICorRuntimeHost_GetDefaultDomain            13 var
#comfunc global ICorRuntimeHost_EnumDomains                 14 var
#comfunc global ICorRuntimeHost_NextDomain                  15 int,var
#comfunc global ICorRuntimeHost_CloseEnum                   16 int
#comfunc global ICorRuntimeHost_CreateDomainEx              17 wstr,int,int,var
#comfunc global ICorRuntimeHost_CreateDomainSetup           18 var
#comfunc global ICorRuntimeHost_CreateEvidence              19 var
#comfunc global ICorRuntimeHost_UnloadDomain                20 int
#comfunc global ICorRuntimeHost_CurrentDomain               21 var
#endif

#ifndef ICLRMetaHost
#define global IID_ICLRMetaHost  "{D332DB9E-B9B3-4125-8207-A14884F53216}"
#define global CLSID_CLRMetaHost "{9280188D-0E8E-4867-B30C-7FA83884E8DE}"
#usecom global ICLRMetaHost IID_ICLRMetaHost CLSID_CLRMetaHost
#comfunc global ICLRMetaHost_GetRuntime                        3 wstr,var,var
#comfunc global ICLRMetaHost_GetVersionFromFile                4 wstr,var,var
#comfunc global ICLRMetaHost_EnumerateInstalledRuntimes        5 var
#comfunc global ICLRMetaHost_EnumerateLoadedRuntimes           6 int,var
#comfunc global ICLRMetaHost_RequestRuntimeLoadedNotification  7 int
#comfunc global ICLRMetaHost_QueryLegacyV2RuntimeBinding       8 var,var
#comfunc global ICLRMetaHost_ExitProcess                       9 int
#endif

#ifndef ICLRRuntimeInfo
#define global IID_ICLRRuntimeInfo "{BD39D1D2-BA2F-486a-89B0-B4B0CB466891}"
#usecom global ICLRRuntimeInfo IID_ICLRRuntimeInfo "{}"
#comfunc global ICLRRuntimeInfo_GetVersionString         3 var,var
#comfunc global ICLRRuntimeInfo_GetRuntimeDirectory      4 var,var
#comfunc global ICLRRuntimeInfo_IsLoaded                 5 int,var
#comfunc global ICLRRuntimeInfo_LoadErrorString          6 int,var,var,int
#comfunc global ICLRRuntimeInfo_LoadLibrary              7 wstr,var
#comfunc global ICLRRuntimeInfo_GetProcAddress           8 wstr,var
#comfunc global ICLRRuntimeInfo_GetInterface             9 var,var,var
#comfunc global ICLRRuntimeInfo_IsLoadable              10 var
#comfunc global ICLRRuntimeInfo_SetDefaultStartupFlags  11 int,wstr
#comfunc global ICLRRuntimeInfo_GetDefaultStartupFlags  12 var,var,var
#comfunc global ICLRRuntimeInfo_BindAsLegacyV2Runtime   13
#comfunc global ICLRRuntimeInfo_IsStarted               14 var,var
#endif

#ifndef _AppDomain
#define global IID__AppDomain   "{05F696DC-2B29-3663-AD8B-C4389CF2A713}"
#define global CLSID__AppDomain "{5FE0A145-A82B-3D96-94E3-FD214C9D6EB9}"
#usecom global _AppDomain IID__AppDomain CLSID__AppDomain
#comfunc global _AppDomain_ToString                    7 int
#comfunc global _AppDomain_Equals                      8 int,int,int,int,var
#comfunc global _AppDomain_GetHashCode                 9 var
#comfunc global _AppDomain_GetType                    10 var
#comfunc global _AppDomain_InitializeLifetimeService  11 var
#comfunc global _AppDomain_GetLifetimeService         12 var
#comfunc global _AppDomain_Evidence                   13 var
#comfunc global _AppDomain_add_DomainUnload           14 int
#comfunc global _AppDomain_remove_DomainUnload        15 int
#comfunc global _AppDomain_add_AssemblyLoad           16 int
#comfunc global _AppDomain_remove_AssemblyLoad        17 int
#comfunc global _AppDomain_add_ProcessExit            18 int
#comfunc global _AppDomain_remove_ProcessExit         19 int
#comfunc global _AppDomain_add_TypeResolve            20 int
#comfunc global _AppDomain_remove_TypeResolve         21 int
#comfunc global _AppDomain_add_ResourceResolve        22 int
#comfunc global _AppDomain_remove_ResourceResolve     23 int
#comfunc global _AppDomain_add_AssemblyResolve        24 int
#comfunc global _AppDomain_remove_AssemblyResolve     25 int
#comfunc global _AppDomain_add_UnhandledException     26 int
#comfunc global _AppDomain_remove_UnhandledException  27 int
#comfunc global _AppDomain_DefineDynamicAssembly      28 int,int,var
#comfunc global _AppDomain_DefineDynamicAssembly_2    29 int,int,int,var
#comfunc global _AppDomain_DefineDynamicAssembly_3    30 int,int,int,var
#comfunc global _AppDomain_DefineDynamicAssembly_4    31 int,int,int,int,int,var
#comfunc global _AppDomain_DefineDynamicAssembly_5    32 int,int,int,int,var
#comfunc global _AppDomain_DefineDynamicAssembly_6    33 int,int,int,int,int,int,var
#comfunc global _AppDomain_DefineDynamicAssembly_7    34 int,int,int,int,int,int,var
#comfunc global _AppDomain_DefineDynamicAssembly_8    35 int,int,int,int,int,int,int,var
#comfunc global _AppDomain_DefineDynamicAssembly_9    36 int,int,int,int,int,int,int,int,var
#comfunc global _AppDomain_CreateInstance             37 int,int,var
#comfunc global _AppDomain_CreateInstanceFrom         38 int,int,var
#comfunc global _AppDomain_CreateInstance_2           39 int,int,int,var
#comfunc global _AppDomain_CreateInstanceFrom_2       40 int,int,int,var
#comfunc global _AppDomain_CreateInstance_3           41 int,int,int,int,int,int,int,int,int,var
#comfunc global _AppDomain_CreateInstanceFrom_3       42 int,int,int,int,int,int,int,int,int,var
#comfunc global _AppDomain_Load                       43 int,var
#comfunc global _AppDomain_Load_2                     44 int,var
#comfunc global _AppDomain_Load_3                     45 int,var
#comfunc global _AppDomain_Load_4                     46 int,int,var
#comfunc global _AppDomain_Load_5                     47 int,int,int,var
#comfunc global _AppDomain_Load_6                     48 int,int,var
#comfunc global _AppDomain_Load_7                     49 int,int,var
#comfunc global _AppDomain_ExecuteAssembly            50 int,int,var
#comfunc global _AppDomain_ExecuteAssembly_2          51 int,var
#comfunc global _AppDomain_ExecuteAssembly_3          52 int,int,int,var
#comfunc global _AppDomain_FriendlyName               53 var
#comfunc global _AppDomain_BaseDirectory              54 var
#comfunc global _AppDomain_RelativeSearchPath         55 var
#comfunc global _AppDomain_ShadowCopyFiles            56 var
#comfunc global _AppDomain_GetAssemblies              57 var
#comfunc global _AppDomain_AppendPrivatePath          58 int
#comfunc global _AppDomain_ClearPrivatePath           59
#comfunc global _AppDomain_SetShadowCopyPath          60 int
#comfunc global _AppDomain_ClearShadowCopyPath        61
#comfunc global _AppDomain_SetCachePath               62 int
#comfunc global _AppDomain_SetData                    63 int,int,int,int,int
#comfunc global _AppDomain_GetData                    64 int,var
#comfunc global _AppDomain_SetAppDomainPolicy         65 int
#comfunc global _AppDomain_SetThreadPrincipal         66 int
#comfunc global _AppDomain_SetPrincipalPolicy         67 int
#comfunc global _AppDomain_DoCallBack                 68 int
#comfunc global _AppDomain_DynamicDirectory           69 var
#endif

#ifndef AppDomainSetup
#define global IID_IAppDomainSetup  "{27FFF232-A7A8-40DD-8D4A-734AD59FCD41}"
#define global CLSID_AppDomainSetup "{3E8E0F03-D3FD-3A93-BAE0-C74A6494DBCA}"
#usecom global AppDomainSetup IID_IAppDomainSetup CLSID_AppDomainSetup
#comfunc global AppDomainSetup_GetApplicationBase         3 var
#comfunc global AppDomainSetup_SetApplicationBase         4 int
#comfunc global AppDomainSetup_GetApplicationName         5 var
#comfunc global AppDomainSetup_SetApplicationName         6 int
#comfunc global AppDomainSetup_GetCachePath               7 var
#comfunc global AppDomainSetup_SetCachePath               8 int
#comfunc global AppDomainSetup_GetConfigurationFile       9 var
#comfunc global AppDomainSetup_SetConfigurationFile      10 int
#comfunc global AppDomainSetup_GetDynamicBase            11 var
#comfunc global AppDomainSetup_SetDynamicBase            12 int
#comfunc global AppDomainSetup_GetLicenseFile            13 var
#comfunc global AppDomainSetup_SetLicenseFile            14 int
#comfunc global AppDomainSetup_GetPrivateBinPath         15 var
#comfunc global AppDomainSetup_SetPrivateBinPath         16 int
#comfunc global AppDomainSetup_GetPrivateBinPathProbe    17 var
#comfunc global AppDomainSetup_PrivateBinPathProbe       18 int
#comfunc global AppDomainSetup_GetShadowCopyDirectories  19 var
#comfunc global AppDomainSetup_SetShadowCopyDirectories  20 int
#comfunc global AppDomainSetup_GetShadowCopyFiles        21 var
#comfunc global AppDomainSetup_SetShadowCopyFiles        22 int
#endif

#ifndef _ObjectHandle
#define global IID__ObjectHandle   "{EA675B47-64E0-3B5F-9BE7-F7DC2990730D}"
#define global CLSID__ObjectHandle "{ABEB0459-03B9-35AF-96E1-66BB7BC923F7}"
#usecom global _ObjectHandle IID__ObjectHandle CLSID__ObjectHandle
#comfunc global _ObjectHandle_ToString                    7 var
#comfunc global _ObjectHandle_Equals                      8 int,int,int,int,var
#comfunc global _ObjectHandle_GetHashCode                 9 var
#comfunc global _ObjectHandle_GetType                    10 var
#comfunc global _ObjectHandle_GetLifetimeService         11 var
#comfunc global _ObjectHandle_InitializeLifetimeService  12 var
#comfunc global _ObjectHandle_CreateObjRef               13 int,var
#comfunc global _ObjectHandle_Unwrap                     14 var
#endif

#ifndef _Object
#define global IID__Object   "{65074F7F-63C0-304E-AF0A-D51741CB4A8D}"
#define global CLSID__OBJECT "{81C5FE01-027C-3E1C-98D5-DA9C9862AA21}"
#usecom global _Object IID__Object CLSID__OBJECT
#comfunc global _Object_ToString     7 var
#comfunc global _Object_Equals       8 int,int,int,int,var
#comfunc global _Object_GetHashCode  9 var
#comfunc global _Object_GetType     10 var
#endif

#ifndef _Assembly
#define global IID__Assembly   "{17156360-2F1A-384A-BC52-FDE93C215C5B}"
#define global CLSID__Assembly "{28E89A9F-E67D-3028-AA1B-E5EBCDE6F3C8}"
#usecom global _Assembly IID__Assembly CLSID__Assembly
#comfunc global _Assembly_ToString                      7 var
#comfunc global _Assembly_Equals                        8 int,int,int,int,var
#comfunc global _Assembly_GetHashCode                   9 var
#comfunc global _Assembly_GetType                      10 var
#comfunc global _Assembly_CodeBase                     11 var
#comfunc global _Assembly_EscapedCodeBase              12 var
#comfunc global _Assembly_GetName                      13 var
#comfunc global _Assembly_GetName_2                    14 int,var
#comfunc global _Assembly_FullName                     15 var
#comfunc global _Assembly_EntryPoint                   16 var
#comfunc global _Assembly_GetType_2                    17 int,var
#comfunc global _Assembly_GetType_3                    18 int,int,var
#comfunc global _Assembly_GetExportedTypes             19 var
#comfunc global _Assembly_GetTypes                     20 var
#comfunc global _Assembly_GetManifestResourceStream    21 int,int,var
#comfunc global _Assembly_GetManifestResourceStream_2  22 int,var
#comfunc global _Assembly_GetFile                      23 int,var
#comfunc global _Assembly_GetFiles                     24 var
#comfunc global _Assembly_GetFiles_2                   25 int,var
#comfunc global _Assembly_GetManifestResourceNames     26 var
#comfunc global _Assembly_GetManifestResourceInfo      27 int,var
#comfunc global _Assembly_Location                     28 var
#comfunc global _Assembly_Evidence                     29 var
#comfunc global _Assembly_GetCustomAttributes          30 int,int,var
#comfunc global _Assembly_GetCustomAttributes_2        31 int,var
#comfunc global _Assembly_IsDefined                    32 int,int,var
#comfunc global _Assembly_GetObjectData                33 int,int
#comfunc global _Assembly_add_ModuleResolve            34 int
#comfunc global _Assembly_remove_ModuleResolve         35 int
#comfunc global _Assembly_GetType_4                    36 int,int,int,var
#comfunc global _Assembly_GetSatelliteAssembly         37 int,var
#comfunc global _Assembly_GetSatelliteAssembly_2       38 int,int,var
#comfunc global _Assembly_LoadModule                   39 int,int,var
#comfunc global _Assembly_LoadModule_2                 40 int,int,int,var
#comfunc global _Assembly_CreateInstance               41 int,var
#comfunc global _Assembly_CreateInstance_2             42 int,int,var
#comfunc global _Assembly_CreateInstance_3             43 int,int,int,int,int,int,int,var
#comfunc global _Assembly_GetLoadedModules             44 var
#comfunc global _Assembly_GetLoadedModules_2           45 int,var
#comfunc global _Assembly_GetModules                   46 var
#comfunc global _Assembly_GetModules_2                 47 int,var
#comfunc global _Assembly_GetModule                    48 int,var
#comfunc global _Assembly_GetReferencedAssemblies      49 var
#comfunc global _Assembly_GlobalAssemblyCache          50 var
#endif

#ifndef _Module
#define global IID__Module   "{D002E9BA-D9E3-3749-B1D3-D565A08B13E7}"
#define global CLSID__Module "{128191C5-B188-3054-81B7-E4F588EACF0E}"
#usecom global _Module IID__Module CLSID__Module
#endif

#ifndef _Type
#define global IID__Type   "{BCA8B44D-AAD6-3A86-8AB7-03349F4F2DA2}"
#define global CLSID__Type "{6C9863DC-7207-327F-A048-C3BB63474BFC}"
#usecom global _Type IID__Type CLSID__Type
#comfunc global _Type_QueryInterface          0 var,var
#comfunc global _Type_AddRef                  1
#comfunc global _Type_Release                 2
#comfunc global _Type_GetTypeInfoCount        3 var
#comfunc global _Type_GetTypeInfo             4 int,int,int
#comfunc global _Type_GetIDsOfNames           5 var,var,int,int,var
#comfunc global _Type_Invoke                  6 int,var,int,int,var,int,int,int
#comfunc global _Type_ToString                7 var
#comfunc global _Type_Equals                  8 int,int,int,int,var
#comfunc global _Type_GetHashCode             9 var
#comfunc global _Type_GetType                10 var
#comfunc global _Type_MemberType             11 var
#comfunc global _Type_name                   12 var
#comfunc global _Type_DeclaringType          13 var
#comfunc global _Type_ReflectedType          14 var
#comfunc global _Type_GetCustomAttributes    15 int,int,var
#comfunc global _Type_GetCustomAttributes_2  16 int,var
#comfunc global _Type_IsDefined              17 int,int,var
#comfunc global _Type_Guid                   18 var
#comfunc global _Type_Module                 19 var
#comfunc global _Type_Assembly               20 var
#comfunc global _Type_TypeHandle             21 var
#comfunc global _Type_FullName               22 var
#comfunc global _Type_Namespace              23 var
#comfunc global _Type_AssemblyQualifiedName  24 var
#comfunc global _Type_GetArrayRank           25 var
#comfunc global _Type_BaseType               26 var
#comfunc global _Type_GetConstructors        27 int,var
#comfunc global _Type_GetInterface           28 int,int,var
#comfunc global _Type_GetInterfaces          29 var
#comfunc global _Type_FindInterfaces         30 int,int,int,int,int,var
#comfunc global _Type_GetEvent               31 int,int,var
#comfunc global _Type_GetEvents              32 var
#comfunc global _Type_GetEvents_2            33 int,var
#comfunc global _Type_GetNestedTypes         34 int,var
#comfunc global _Type_GetNestedType          35 int,int,var
#comfunc global _Type_GetMember              36 int,int,int,var
#comfunc global _Type_GetDefaultMembers      37 var
#comfunc global _Type_FindMembers            38 int,int,int,int,int,int,int,var
#comfunc global _Type_GetElementType         39 var
#comfunc global _Type_IsSubclassOf           40 int,var
#comfunc global _Type_IsInstanceOfType       41 int,int,int,int,var
#comfunc global _Type_IsAssignableFrom       42 int,var
#comfunc global _Type_GetInterfaceMap        43 int,var
#comfunc global _Type_GetMethod              44 int,int,int,int,int,var
#comfunc global _Type_GetMethod_2            45 int,int,var
#comfunc global _Type_GetMethods             46 int,var
#comfunc global _Type_GetField               47 int,int,var;
#comfunc global _Type_GetFields              48 int,var
#comfunc global _Type_GetProperty            49 int,int,var
#comfunc global _Type_GetProperty_2          50 int,int,int,int,int,int,var
#comfunc global _Type_GetProperties          51 int,var
#comfunc global _Type_GetMember_2            52 int,int,var
#comfunc global _Type_GetMembers             53 int,var
#comfunc global _Type_InvokeMember           54 int,int,int,int,int,int,int,int,int,int,int,var
#comfunc global _Type_UnderlyingSystemType   55 var
#comfunc global _Type_InvokeMember_2         56 int,int,int,int,int,int,int,int,int,var
#comfunc global _Type_InvokeMember_3         57 int,int,int,int,int,int,int,int,var
#comfunc global _Type_GetConstructor         58 int,int,int,int,int,var
#comfunc global _Type_GetConstructor_2       59 int,int,int,int,var
#comfunc global _Type_GetConstructor_3       60 int,var
#comfunc global _Type_GetConstructors_2      61 var
#comfunc global _Type_TypeInitializer        62 var
#comfunc global _Type_GetMethod_3            63 int,int,int,int,int,int,var
#comfunc global _Type_GetMethod_4            64 int,int,int,var
#comfunc global _Type_GetMethod_5            65 int,int,var
#comfunc global _Type_GetMethod_6            66 int,var
#comfunc global _Type_GetMethods_2           67 var
#comfunc global _Type_GetField_2             68 int,var
#comfunc global _Type_GetFields_2            69 var
#comfunc global _Type_GetInterface_2         70 int,var
#comfunc global _Type_GetEvent_2             71 int,var
#comfunc global _Type_GetProperty_3          72 int,int,int,int,var
#comfunc global _Type_GetProperty_4          73 int,int,int,var
#comfunc global _Type_GetProperty_5          74 int,int,var
#comfunc global _Type_GetProperty_6          75 int,int,var
#comfunc global _Type_GetProperty_7          76 int,var
#comfunc global _Type_GetProperties_2        77 var
#comfunc global _Type_GetNestedTypes_2       78 var
#comfunc global _Type_GetNestedType_2        79 int,var
#comfunc global _Type_GetMember_3            80 int,var
#comfunc global _Type_GetMembers_2           81 var
#comfunc global _Type_Attributes             82 var
#comfunc global _Type_IsNotPublic            83 var
#comfunc global _Type_IsPublic               84 var
#comfunc global _Type_IsNestedPublic         85 var
#comfunc global _Type_IsNestedPrivate        86 var
#comfunc global _Type_IsNestedFamily         87 var
#comfunc global _Type_IsNestedAssembly       88 var
#comfunc global _Type_IsNestedFamANDAssem    89 var
#comfunc global _Type_IsNestedFamORAssem     90 var
#comfunc global _Type_IsAutoLayout           91 var
#comfunc global _Type_IsLayoutSequential     92 var
#comfunc global _Type_IsExplicitLayout       93 var
#comfunc global _Type_IsClass                94 var
#comfunc global _Type_IsInterface            95 var
#comfunc global _Type_IsValueType            96 var
#comfunc global _Type_IsAbstract             97 var
#comfunc global _Type_IsSealed               98 var
#comfunc global _Type_IsEnum                 99 var
#comfunc global _Type_IsSpecialName         100 var
#comfunc global _Type_IsImport              101 var
#comfunc global _Type_IsSerializable        102 var
#comfunc global _Type_IsAnsiClass           103 var
#comfunc global _Type_IsUnicodeClass        104 var
#comfunc global _Type_IsAutoClass           105 var
#comfunc global _Type_IsArray               106 var
#comfunc global _Type_IsByRef               107 var
#comfunc global _Type_IsPointer             108 var
#comfunc global _Type_IsPrimitive           109 var
#comfunc global _Type_IsCOMObject           110 var
#comfunc global _Type_HasElementType        111 var
#comfunc global _Type_IsContextful          112 var
#comfunc global _Type_IsMarshalByRef        113 var
#comfunc global _Type_Eauals_2              114 int,var
#endif

#ifndef _MemberInfo
#define global IID__MemberInfo   "{F7102FA9-CABB-3A74-A6DA-B4567EF1B079}"
#define global CLSID__MemberInfo "{5AE028B5-9A3A-32A9-899C-1DEEFB85CC50}"
#usecom global _MemberInfo IID__MemberInfo CLSID__MemberInfo
#comfunc global _MemberInfo_ToString                7 var
#comfunc global _MemberInfo_Equals                  8 int,int,int,int,var
#comfunc global _MemberInfo_GetHashCode             9 var
#comfunc global _MemberInfo_GetType                10 var
#comfunc global _MemberInfo_MemberType             11 var
#comfunc global _MemberInfo_name                   12 var
#comfunc global _MemberInfo_DeclaringType          13 var
#comfunc global _MemberInfo_ReflectedType          14 var
#comfunc global _MemberInfo_GetCustomAttributes    15 int,int,var
#comfunc global _MemberInfo_GetCustomAttributes_2  16 int,var
#comfunc global _MemberInfo_IsDefined              17 int,int,var
#endif

#ifndef _PropertyInfo
#define global IID__PropertyInfo   "{F59ED4E4-E68F-3218-BD77-061AA82824BF}"
#define global CLSID__PropertyInfo "{BFDF1F57-230D-394A-B773-D9EC58CBEF9A}"
#usecom global _PropertyInfo IID__PropertyInfo CLSID__PropertyInfo
#comfunc global _PropertyInfo_ToString                7 var
#comfunc global _PropertyInfo_Equals                  8 int,int,int,int,var
#comfunc global _PropertyInfo_GetHashCode             9 var
#comfunc global _PropertyInfo_GetType                10 var
#comfunc global _PropertyInfo_MemberType             11 var
#comfunc global _PropertyInfo_name                   12 var
#comfunc global _PropertyInfo_DeclaringType          13 var
#comfunc global _PropertyInfo_ReflectedType          14 var
#comfunc global _PropertyInfo_GetCustomAttributes    15 int,int,var
#comfunc global _PropertyInfo_GetCustomAttributes_2  16 int,var
#comfunc global _PropertyInfo_IsDefined              17 int,int,var
#comfunc global _PropertyInfo_PropertyType           18 var
#comfunc global _PropertyInfo_GetValue               19 int,int,int,int,int,var
#comfunc global _PropertyInfo_GetValue_2             20 int,int,int,int,int,int,int,int,var
#comfunc global _PropertyInfo_SetValue               21 int,int,int,int,int,int,int,int,int
#comfunc global _PropertyInfo_SetValue_2             22 int,int,int,int,int,int,int,int,int,int,int,int
#comfunc global _PropertyInfo_GetAccessors           23 int,var
#comfunc global _PropertyInfo_GetGetMethod           24 int,var
#comfunc global _PropertyInfo_GetSetMethod           25 int,var
#comfunc global _PropertyInfo_GetIndexParameters     26 var
#comfunc global _PropertyInfo_Attributes             27 var
#comfunc global _PropertyInfo_CanRead                28 var
#comfunc global _PropertyInfo_CanWrite               29 var
#comfunc global _PropertyInfo_GetAccessors_2         30 var
#comfunc global _PropertyInfo_GetGetMethod_2         31 var
#comfunc global _PropertyInfo_GetSetMethod_2         32 var
#comfunc global _PropertyInfo_IsSpecialName          33 var
#endif

#ifndef _FieldInfo
#define global IID__FieldInfo   "{8A7C1442-A9FB-366B-80D8-4939FFA6DBE0}"
#define global CLSID__FieldInfo "{98BA57DC-4CF2-3ED1-B4A2-890C21BBBF4B}"
#usecom global _FieldInfo IID__FieldInfo CLSID__FieldInfo
#comfunc global _FieldInfo_ToString               7 var
#comfunc global _FieldInfo_Equals                 8 int,int,int,int,var
#comfunc global _FieldInfo_GetHashCode            9 var
#comfunc global _FieldInfo_GetType               10 var
#comfunc global _FieldInfo_MemberType            11 var
#comfunc global _FieldInfo_name                  12 var
#comfunc global _FieldInfo_DeclaringType         13 var
#comfunc global _FieldInfo_ReflectedType         14 var
#comfunc global _FieldInfo_GetCustomAttributes   15 int,int,var
#comfunc global _FieldInfo_GetCustomAttributes_2 16 int,var
#comfunc global _FieldInfo_IsDefined             17 int,int,var
#comfunc global _FieldInfo_FieldType             18 var
#comfunc global _FieldInfo_GetValue              19 int,int,int,int,var
#comfunc global _FieldInfo_GetValueDirect        20 int,int,int,int,var
#comfunc global _FieldInfo_SetValue              21 int,int,int,int,int,int,int,int,int,int,int
#comfunc global _FieldInfo_SetValueDirect        22 int,int,int,int,int,int,int,int
#comfunc global _FieldInfo_FieldHandle           23 var
#comfunc global _FieldInfo_Attributes            24 var
#comfunc global _FieldInfo_SetValue_2            25 int,int,int,int,int,int,int,int
#comfunc global _FieldInfo_IsPublic              26 var
#comfunc global _FieldInfo_IsPrivate             27 var
#comfunc global _FieldInfo_IsFamily              28 var
#comfunc global _FieldInfo_IsAssembly            29 var
#comfunc global _FieldInfo_IsFamilyAndAssembly   30 var
#comfunc global _FieldInfo_IsFamilyOrAssembly    31 var
#comfunc global _FieldInfo_IsStatic              32 var
#comfunc global _FieldInfo_IsInitOnly            33 var
#comfunc global _FieldInfo_IsLiteral             34 var
#comfunc global _FieldInfo_IsNotSerialized       35 var
#comfunc global _FieldInfo_IsSpecialName         36 var
#comfunc global _FieldInfo_IsPinvokeImpl         37 var
#endif

#ifndef _MethodInfo
#define global IID__MethodInfo   "{FFCC1B5D-ECB8-38DD-9B01-3DC8ABC2AA5F}"
#define global CLSID__MethodInfo "{0E22CC27-CA1E-3138-9640-BE831F721659}"
#usecom global _MethodInfo IID__MethodInfo CLSID__MethodInfo
#comfunc global _MethodInfo_ToString                      7 var
#comfunc global _MethodInfo_Equals                        8 int,int,int,int,var
#comfunc global _MethodInfo_GetHashCode                   9 var
#comfunc global _MethodInfo_GetType                      10 var
#comfunc global _MethodInfo_MemberType                   11 var
#comfunc global _MethodInfo_name                         12 var
#comfunc global _MethodInfo_DeclaringType                13 var
#comfunc global _MethodInfo_ReflectedType                14 var
#comfunc global _MethodInfo_GetCustomAttributes          15 int,int,var
#comfunc global _MethodInfo_GetCustomAttributes_2        16 int,var
#comfunc global _MethodInfo_IsDefined                    17 int,int,var
#comfunc global _MethodInfo_GetParameters                18 var
#comfunc global _MethodInfo_GetMethodImplementationFlags 19 var
#comfunc global _MethodInfo_MethodHandle                 20 var
#comfunc global _MethodInfo_Attributes                   21 var
#comfunc global _MethodInfo_CallingConvention            22 var
#comfunc global _MethodInfo_Invoke_2                     23 int,int,int,int,int,int,int,int,var
#comfunc global _MethodInfo_IsPublic                     24 var
#comfunc global _MethodInfo_IsPrivate                    25 var
#comfunc global _MethodInfo_IsFamily                     26 var
#comfunc global _MethodInfo_IsAssembly                   27 var
#comfunc global _MethodInfo_IsFamilyAndAssembly          28 var
#comfunc global _MethodInfo_IsFamilyOrAssembly           29 var
#comfunc global _MethodInfo_IsStatic                     30 var
#comfunc global _MethodInfo_IsFinal                      31 var
#comfunc global _MethodInfo_IsVirtual                    32 var
#comfunc global _MethodInfo_IsHideBySig                  33 var
#comfunc global _MethodInfo_IsAbstract                   34 var
#comfunc global _MethodInfo_IsSpecialName                35 var
#comfunc global _MethodInfo_IsConstructor                36 var
#comfunc global _MethodInfo_Invoke_3                     37 int,int,int,int,int,var
#comfunc global _MethodInfo_returnType                   38 var
#comfunc global _MethodInfo_ReturnTypeCustomAttributes   39 var
#comfunc global _MethodInfo_GetBaseDefinition            40 var
#endif

#ifndef _ParameterInfo
#define global IID__ParameterInfo   "{993634C4-E47A-32CC-BE08-85F567DC27D6}"
#define global CLSID__ParameterInfo "{E5CE8078-0CA7-3578-80DB-F20FCA8786A6}"
#usecom global _ParameterInfo IID__ParameterInfo CLSID__ParameterInfo
#comfunc global _ParameterInfo_GetTypeInfoCount 3 var
#comfunc global _ParameterInfo_GetTypeInfo      4 int,int,int
#comfunc global _ParameterInfo_GetIDsOfNames    5 var,var,int,int,var
#comfunc global _ParameterInfo_Invoke           6 int,var,int,int,var,int,int,int
#endif

#endif // MOD_HOSTCLR_HSP_
コメント ( 0 ) | Trackback ( 0 )

ImageCapture

SetLayeredWindowAttributes
SetLayeredWindowAttributes関数の第2引数に指定するカラーキーが、
青と赤の値が同じ場合と違う場合で挙動が変わる。DWM上での仕様?
青と赤が同じ値
SetLayeredWindowAttributes hWnd, 0x110011, 0, LWA_COLORKEY
色が0x110011の場合、透明化。クリック時、後ろのウィンドウに通知。
色が0x110011以外の場合、不透明化。クリック時、hWndに通知。
青と赤が違う値
SetLayeredWindowAttributes hWnd, 0x110022, 0, LWA_COLORKEY
色が0x110022の場合、透明化。クリック時、hWndに通知。
色が0x220011の場合、不透明化。クリック時、後ろのウィンドウに通知。
色が0x110022、0x220011以外の場合、不透明化。クリック時、hWndに通知。
bgscr + WS_THICKFRAME
bgscrをサイズ変更可能にした時、クライアントエリア上部に空白が表示される。 DWM上での仕様?
改善例は、ImageCapture.hsp内のmod_Bgscr2参照。
#include "user32.as"

	bgscr 0, 300, 200
	SetWindowLong hwnd, -16, 0x90040000
	color : boxf : color 255, 255, 255
	mes "左クリック:移動 右クリック:終了"
	oncmd gosub *WM_LBUTTONDONW, 0x0201
	oncmd *WM_RBUTTONUP, 0x205
	stop

*WM_LBUTTONDONW
	sendmsg hwnd, 0xa1, 2, 0
	return

*WM_RBUTTONUP
	end
ImageCapture.hsp
概要
画面上の任意のサイズイメージをコピー、保存(JPG固定)。
操作
左クリック 左クリックドラッグでウィンドウ移動。
右クリック ポップアップメニュー表示
左ダブルクリック イメージのコピーと表示の切り替え。
ホイール イメージを拡大・縮小。
ホイールクリック 前面表示切り替え。
ポップアップメニュー
コピー ウィンドウ内に表示されているイメージをコピー。
表示 コピーを破棄して、ウィンドウ内を透過。
新規 新しいウィンドウを作成。
保存 イメージの保存。
通常サイズ 拡大率を100%に戻す。
前面表示 常に前面に表示する。
閉じる ウィンドウを閉じる。最後のウィンドウの場合、終了。
終了 アプリケーションの終了。
その他
WIC、Direct2Dを使用。
screen, bgscr命令直後のシステム変数hwndが、別のウィンドウハンドルに変わっている事がある。 とりあえず、gselで対応。
/* ---------------------------------------------------------
	#include
   --------------------------------------------------------- */
#include "user32.as"
#include "kernel32.as"
#include "gdi32.as"

/* ---------------------------------------------------------
	#uselib
   --------------------------------------------------------- */
#uselib "dwmapi.dll"
#func global DwmExtendFrameIntoClientArea "DwmExtendFrameIntoClientArea" int,var

#uselib "d2d1.dll"
#func global D2D1CreateFactory "D2D1CreateFactory" int,var,int,var

/* ---------------------------------------------------------
	#usecom
   --------------------------------------------------------- */
#define global IID_IWICImagingFactory  "{ec5ec8a9-c395-4314-9c77-54d7a935ff70}"
#define global CLSID_WICImagingFactory "{cacaf262-9370-4615-a13b-9f5539da4c0a}"
#usecom global IWICImagingFactory IID_IWICImagingFactory CLSID_WICImagingFactory
#comfunc global IWICImagingFactory_CreateEncoder            8 var,int,var
#comfunc global IWICImagingFactory_CreateFormatConverter   10 var
#comfunc global IWICImagingFactory_CreateStream            14 var
#comfunc global IWICImagingFactory_CreateBitmapFromHBITMAP 21 int,int,int,var

#define global IID_IWICBitmap "{00000121-a8f2-4877-ba0a-fd2b6645fb94}"
#usecom global IWICBitmap IID_IWICBitmap "{}"

#define global IID_IWICFormatConverter "{00000301-a8f2-4877-ba0a-fd2b6645fb94}"
#usecom global IWICFormatConverter IID_IWICFormatConverter "{}"
#comfunc global IWICFormatConverter_GetSize    3 var,var
#comfunc global IWICFormatConverter_Initialize 8 int,var,int,int,double,int

#define global IID_IWICStream "{135FF860-22B7-4ddf-B0F6-218F4F299A43}"
#usecom global IWICStream IID_IWICStream "{}"
#comfunc global IWICStream_InitializeFromFilename  15 wstr,int

#define global IID_IWICBitmapEncoder "{00000103-a8f2-4877-ba0a-fd2b6645fb94}"
#usecom global IWICBitmapEncoder IID_IWICBitmapEncoder "{}"
#comfunc global IWICBitmapEncoder_Initialize              3 int,int
#comfunc global IWICBitmapEncoder_CreateNewFrame         10 var,var
#comfunc global IWICBitmapEncoder_Commit                 11
#comfunc global IWICBitmapEncoder_GetMetadataQueryWriter 12 var

#define global IID_IWICBitmapFrameEncode "{00000105-a8f2-4877-ba0a-fd2b6645fb94}"
#usecom global IWICBitmapFrameEncode IID_IWICBitmapFrameEncode "{}"
#comfunc global IWICBitmapFrameEncode_Initialize              3 int
#comfunc global IWICBitmapFrameEncode_WriteSource            11 int,var
#comfunc global IWICBitmapFrameEncode_Commit                 12
#comfunc global IWICBitmapFrameEncode_GetMetadataQueryWriter 13 var

#define global IID_IWICMetadataQueryWriter "{A721791A-0DEF-4d06-BD91-2118BF1DB10B}"
#usecom global IWICMetadataQueryWriter IID_IWICMetadataQueryWriter "{}"
#comfunc global IWICMetadataQueryWriter_SetMetadataByName    7 wstr,var

#define global IID_IPropertyBag2 "{22F55882-280B-11d0-A8A9-00A0C90C2004}"
#usecom global IPropertyBag2 IID_IPropertyBag2 "{}"
#comfunc global IPropertyBag2_Read  3 int,var,int,var,var
#comfunc global IPropertyBag2_Write 4 int,var,var

#ifndef IID_ID2D1Factory
#define global IID_ID2D1Factory "{06152247-6F50-465A-9245-118BFD3B6007}"
#usecom global ID2D1Factory IID_ID2D1Factory "{}"
#comfunc global ID2D1Factory_CreateDCRenderTarget 16 var,var

#ifndef IID_ID2D1DCRenderTarget
#define global IID_ID2D1DCRenderTarget "{1c51bc64-de61-46fd-9899-63a5d8f03950}"
#usecom global ID2D1DCRenderTarget IID_ID2D1DCRenderTarget "{}"
#comfunc global ID2D1DCRenderTarget_CreateBitmapFromWicBitmap 5 int,int,var
#comfunc global ID2D1DCRenderTarget_DrawBitmap 26 int,int,int,int,int
#comfunc global ID2D1DCRenderTarget_Clear      47 var
#comfunc global ID2D1DCRenderTarget_BeginDraw  48
#comfunc global ID2D1DCRenderTarget_EndDraw    49 int,int
#comfunc global ID2D1DCRenderTarget_BindDC     57 int,var

#ifndef ID2D1Bitmap
#define global IID_ID2D1Bitmap "{a2296057-ea42-4099-983b-539fb6505426}"
#usecom global ID2D1Bitmap IID_ID2D1Bitmap "{}"

/* ---------------------------------------------------------
	mod_Bgscr2
   --------------------------------------------------------- */
#module mod_Bgscr2

#deffunc Bgscr2Ex int id, int w2, int h2, int mode, int x, int y, int w, int h
	if ( nHit == 0 ){
		dim pt, 2 : dim rc, 4 : dim nHit, 3, 3
		nHit(0, 0) = 13, 12, 14
		nHit(0, 1) = 10, 1, 11
		nHit(0, 2) = 16, 15, 17
		dim rcFrm, 4
		AdjustWindowRectEx varptr(rcFrm), 0x94040000, 0, 0
		rcFrm(0) *= -1 : rcFrm(1) *= -1
	}
	bgscr id, w2, h2, mode, x, y, w, h
	gsel id, 0 : hWndTmp = hwnd
	SetWindowLong hWndTmp, -16, 0x94040000
	oncmd gosub *OnNCCalcSize, 0x0083
	oncmd gosub *OnNCHitTest, 0x0084
	oncmd gosub *OnNCActivate, 0x0086
	SetWindowPos hWndTmp, 0, 0, 0, 0, 0, 0x23
	return hWndTmp

#deffunc Bgscr2 int id, int w, int h, int mode
	Bgscr2Ex id, ginfo_dispx, ginfo_dispy, mode, -1, -1, w, h
	return stat

*OnNCCalcSize
	return 0

*OnNCHitTest
	gsel ginfo(24), 0
	pt = lparam & 0xffff, lparam >> 16
	ScreenToClient hwnd, varptr(pt)
	GetClientRect hwnd, varptr(rc)
	x = 1 : y = 1
	if ( pt(0) < rcFrm(0) ){ x = 0 }
	if ( pt(0) > (rc(2) - rcFrm(2)) ){ x = 2 }
	if ( pt(1) < rcFrm(1) ){ y = 0 }
	if ( pt(1) > (rc(3) - rcFrm(3)) ){ y = 2 }
	return nHit(x, y)

*OnNCActivate
	return 1

#global

/* ---------------------------------------------------------
	mod_d2f
   --------------------------------------------------------- */
#module mod_d2f
#defcfunc d2f double d
	if( dtof == 0 ){
		d_ = 0.0 : f_ = 0
		dim prm, 2 : dim dtof,4
		dtof(0) = 0x0424448b, 0x4c8b00dd, 0x19d90824, 0x000000c3
		VirtualProtect varptr(dtof), 16, 0x40, varptr(r)
		prm = varptr(d_), varptr(f_)
	}
	d_ = d
	r = callfunc(prm, varptr(dtof), 2)
	return f_
#global

/* ---------------------------------------------------------
	mod_ImgCap
   --------------------------------------------------------- */
#module mod_ImgCap mhWnd, mbTop, mWicFC, mImgX, mImgY

#define IMGCAP_BORDERX     2
#define IMGCAP_BORDERY     2
#define IMGCAP_TITLE      10
#define IMGCAP_BORDRCOLOR 16, 32, 64
#define IMGCAP_CRKEY      2, 1, 1
#define IMGCAP_CRKEY2     0x010102

#deffunc ImgCapInit
	if ( vartype(arImgCap) != 5 ){
		dimtype arImgCap, 5, 1
		bBgsrc0 = 0
		wndNum = 0
		dim prm, 16
	}
	if ( vartype(cWicFactory) != 6 ){
		newcom cWicFactory, IWICImagingFactory
	}
	if ( d2dFactory == 0 ){
		prm(1) = 0x6152247, 0x465a6f50, 0x8b114592, 0x7603bfd
		dstFmt24bgr = 0x6fddc324, 0x4bfe4e03, 0x773d85b1, 0xec98d76
		D2D1CreateFactory 0, prm(1), 0, prm
		if ( stat == 0 ){
			newcom cD2dFactory, ID2D1Factory, -1, prm
			prm(1) = 0, 87, 3, 0, 0, 2, 0
			ID2D1Factory_CreateDCRenderTarget cD2dFactory, prm(1), prm
			if ( stat == 0 ){
				newcom cDCRender, ID2D1DCRenderTarget, -1, prm
			}
		}
	}
	if ( hMenuPop == 0 ){
		CreatePopupMenu : hMenuPop = stat
		prm = 48, 0x42
		strMenu = "コピー(&C)", "新規(&N)", "保存(&S)", "通常サイズ(&D)", "前面表示(&T)", "閉じる(&Q)", "終了(&X)"
		repeat length(strMenu)
			prm(4) = 0x8000 + cnt : prm(9) = varptr(strMenu(cnt))
			InsertMenuItem hMenuPop, cnt, 1, varptr(prm)
		loop
	}
	if ( hToolTip == 0 ){
		CreateWindowEx 8, "tooltips_class32", "", 0x90000000, 0, 0, 0, 0, 0, 0, hinstance, 0
		hToolTip = stat
	}
	return

#deffunc ImgCapTerm int p
	prm = 0
	foreach arImgCap
		if ( varptr(arImgCap(cnt)) == p ){
			delmod arImgCap(cnt) : prm = 1
		}
	loop
	return prm

#deffunc ImgCapExit onexit
	if ( vartype(arImgCap) == 5 ){
		foreach arImgCap
			delcom arImgCap(cnt)
		loop
	}
	if ( vartype(cWicFactory) == 6 ){ delcom cWicFactory }
	if ( vartype(cD2dFactory) == 6 ){ delcom cD2dFactory }
	if ( vartype(cDCRender) == 6 ){ delcom cDCRender }
	if ( hMenuPop ){ DestroyMenu hMenuPop }
	if ( hToolTip ){ DestroyWindow hToolTip }
	return

#defcfunc ImgCapCreate int x, int y, int w, int h
	ImgCapInit
	newmod arImgCap, mod_ImgCap
	dupptr dp, stat, 16, 5
	return ImgCap_Create(dp, x, y, w, h)

#defcfunc ImgCapExitFlag int flag
	if ( flag == 0 ){ exitFlag = 0 }
	else {
		if ( flag > 0 ){ exitFlag = 1 }
	}
	return exitFlag

#defcfunc ImgCapGetDp int id, var dpImgCap
	gsel id, 0
	GetProp hwnd, "ImgCapMod"
	if ( stat == 0 ){ return 0 }
	dupptr dpImgCap, stat, 16, 5
	return 1

#modinit
	mhWnd = 0 : mbTop = 0 : mWicFC = 0 : mImgX = 0 : mImgY = 0
	return varptr(thismod)

#modterm
	if ( mWicFC ){ prm = ImgCap_ImgDel(thismod, mWicFC) }
	if ( hToolTip ){
		prm = 48, 0x11, mhWnd, mhWnd
		sendmsg hToolTip, 0x405, 0, varptr(prm)
	}
	RemoveProp mhWnd, "ImgCapMod"
	return

#modcfunc ImgCap_SetLayered int flag
	GetWindowRect mhWnd, varptr(prm)
	prm(2) -= prm(0) : prm(3) -= prm(1)
	GetWindowLong mhWnd, -20
	if ( flag == 0 ){
		SetWindowLong mhWnd, -20, stat ^ 0x80000
		RedrawWindow mhWnd, 0, 0, 0x485
		prm(0) += IMGCAP_BORDERX
		prm(1) += IMGCAP_BORDERY + IMGCAP_TITLE
		prm(2) -= (IMGCAP_BORDERX * 2)
		prm(3) -= (IMGCAP_BORDERY * 2 + IMGCAP_TITLE)
	}
	else {
		SetWindowLong mhWnd, -20, stat | 0x80000
		SetLayeredWindowAttributes mhWnd, IMGCAP_CRKEY2, 0, 1
		prm(0) -= IMGCAP_BORDERX
		prm(1) -= (IMGCAP_BORDERY + IMGCAP_TITLE)
		prm(2) += (IMGCAP_BORDERX * 2)
		prm(3) += (IMGCAP_BORDERY * 2 + IMGCAP_TITLE)
	}
	SetWindowPos mhWnd, 0, prm(0), prm(1), prm(2), prm(3), 0x20
	return stat

#modcfunc ImgCap_Create int x, int y, int w, int h
	idTmp = ginfo(25)
	gsel 0, 0
	if ( exitFlag == 0 && bBgsrc0 == 0 ){
		GetProp hwnd, "ImgCapMod"
		if ( stat == 0 ){ idTmp = 0 : bBgsrc0 = 1 }
	}
	Bgscr2Ex idTmp, ginfo_dispx, ginfo_dispy, 0, x, y, w, h
	mhWnd = stat
	prm = 1, 1, 1, 1
	DwmExtendFrameIntoClientArea mhWnd, prm
	GetClassLong mhWnd, -26
	SetClassLong mhWnd, -26, stat | 8
	SetProp mhWnd, "ImgCapMod", varptr(thismod)
	if ( stat == 0 ){
		gsel idTmp, -1 : return 0
	}
	buf = "test"
	prm = 48, 0x11, mhWnd, mhWnd
	prm(8) = hinstance, 0
	sendmsg hToolTip, 0x404, 0, varptr(prm)
	wndNum++
	oncmd gosub *WM_SIZE, 0x0005
	oncmd gosub *WM_CLOSE, 0x0010
	oncmd gosub *WM_COMMAND, 0x0111
	oncmd gosub *WM_LBUTTONDOWN, 0x0201
	oncmd gosub *WM_LBUTTONDBLCLK, 0x0203
	oncmd gosub *WM_RBUTTONDOWN, 0x0204
	oncmd gosub *WM_MBUTTONDOWN, 0x0207
	oncmd gosub *WM_MOUSEWHEEL, 0x020A
	if ( ImgCap_SetLayered(thismod, 1) == 0 ){ return 0 }
	return 1

#modcfunc ImgCap_Close
	ImgCapTerm varptr(thismod)
	if ( wndNum ){ wndNum-- }
	if ( wndNum == 0 ){
		if ( exitFlag == 0 ){ return 1 }
	}
	return 0

#modcfunc ImgCap_ImgCreate
	prm(10) = 0
	GetClientRect mhWnd, varptr(prm)
	ClientToScreen mhWnd, varptr(prm)
	prm(4) = IMGCAP_BORDERX * 2
	prm(5) = IMGCAP_BORDERY + IMGCAP_TITLE
	prm(6) = prm(5) + IMGCAP_BORDERY
	if ( prm(2) <= prm(4) || prm(3) <= prm(6) ){ return 0 }
	prm(0) = prm(0) + IMGCAP_BORDERX
	prm(1) = prm(1) + prm(5)
	prm(2) = prm(2) - prm(4)
	prm(3) = prm(3) - prm(6)
	GetDesktopWindow : prm(4) = stat
	GetDC prm(4) : prm(5) = stat
	CreateCompatibleDC prm(5) : prm(6) = stat
	CreateCompatibleBitmap prm(5), prm(2), prm(3) : prm(7) = stat
	SelectObject prm(6), prm(7) : prm(8) = stat
	BitBlt prm(6), 0, 0, prm(2), prm(3), prm(5), prm(0), prm(1), 0xcc0020
	ReleaseDC prm(4), prm(5)
	SelectObject prm(6), prm(8)
	DeleteDC prm(6)
	IWICImagingFactory_CreateBitmapFromHBITMAP cWicFactory, prm(7), 0, 2, prm(9)
	if ( stat == 0 ){
		newcom comTmp, IWICBitmap, -1, prm(9)
		IWICImagingFactory_CreateFormatConverter cWicFactory, prm(10)
		if ( stat == 0 ){
			newcom comTmp2, IWICFormatConverter, -2, prm(10)
			IWICFormatConverter_Initialize comTmp2, prm(9), dstFmt24bgr, 1, 0, 0.0, 0
			if ( stat ){ prm = ImgCap_ImgDel(thismod, prm(10)) }
			delcom comTmp2
		}
		delcom comTmp
	}
	DeleteObject prm(7)
	return prm(10)

#modcfunc ImgCap_ImgDel int img
	if ( img == 0 ){ return 0 }
	newcom comTmp, IWICFormatConverter, -1, img
	delcom comTmp
	return 1

#modcfunc ImgCap_ImgGetSize int img, var x, var y
	newcom comTmp, IWICFormatConverter, -2, img
	IWICFormatConverter_GetSize comTmp, x, y
	prm = stat
	delcom comTmp
	if ( prm ){ return 0 }
	return 1

#modcfunc ImgCap_CopyView
	if ( mWicFC ){
		if ( ImgCap_ImgDel(thismod, mWicFC) == 0 ){ return 0 }
		mWicFC = 0
		if ( ImgCap_SetLayered(thismod, 1) == 0 ){ return 0 }
	}
	else {
		prm(11) = ImgCap_ImgCreate(thismod)
		if ( prm == 0 ){ return 0 }
		if ( ImgCap_ImgGetSize(thismod, prm(11), prm(12), prm(13)) == 0 ){
			prm = ImgCap_ImgDel(thismod, prm(11))
			return 0
		}
		mWicFC = prm(11) : mImgX = prm(12) : mImgY = prm(13)
		if ( ImgCap_SetLayered(thismod, 0) == 0 ){ return 0 }
	}
	return 1

#modcfunc ImgCap_Size
	redraw 0
	GetClientRect mhWnd, varptr(prm)
	GetWindowLong mhWnd, -21
	gsel stat, 0
	if ( mWicFC ){
		ID2D1DCRenderTarget_BindDC cDCRender, hdc, prm
		ID2D1DCRenderTarget_BeginDraw cDCRender
		prm(4) = 0, 0, 0, 0x3f800000
		ID2D1DCRenderTarget_Clear cDCRender, prm(4)
		if ( (prm(2) * prm(3) * mImgX * mImgY) != 0 ){
			ID2D1DCRenderTarget_CreateBitmapFromWicBitmap cDCRender, mWicFC, 0, prm(4)
			if ( stat == 0 ){
				newcom comTmp, ID2D1Bitmap, -2, prm(4)
				d1 = 1.0 * prm(2) / mImgX
				d2 = 1.0 * prm(3) / mImgY
				if ( d1 > d2 ){
					prm(1) = 0
					prm(5) = int(1.0 * prm(3) * mImgX / mImgY)
					prm(0) = (prm(2) - prm(5)) / 2
					prm(2) = prm(0) + prm(5)
				}
				else {
					prm(0) = 0
					prm(5) = int(1.0 * prm(2) * mImgY / mImgX)
					prm(1) = (prm(3) - prm(5)) / 2
					prm(3) = prm(1) + prm(5)
				}
				prm(5) = d2f(prm(0)), d2f(prm(1)), d2f(prm(2)), d2f(prm(3))
				ID2D1DCRenderTarget_DrawBitmap cDCRender, prm(4), varptr(prm(5)), 0x3f800000, 1, 0
				delcom comTmp
			}
		}
		ID2D1DCRenderTarget_EndDraw cDCRender, 0, 0
		prm(2) -= prm(0) : prm(3) -= prm(1)
		d1 = 1.0 * prm(2) / mImgX * 100
		buf = strf("%3d%% %5d x %5d (%5d x %5d)", int(d1), prm(2), prm(3), mImgX, mImgY)
	}
	else {
		color IMGCAP_BORDRCOLOR : boxf
		color IMGCAP_CRKEY
		prm(0) = IMGCAP_BORDERX
		prm(1) = IMGCAP_BORDERY + IMGCAP_TITLE
		prm(4) = prm(2) - (IMGCAP_BORDERX * 2)
		prm(5) = prm(3) - prm(1) - IMGCAP_BORDERY
		prm(2) = prm(0) + prm(4) - 1
		prm(3) = prm(1) + prm(5) - 1
		boxf prm(0), prm(1), prm(2), prm(3)
		buf = strf("%5d x %5d", prm(4), prm(5))
	}
	redraw 1
	prm = 48, 0x11, mhWnd, mhWnd
	prm(8) = hinstance, varptr(buf)
	sendmsg hToolTip, 0x40c, 0, varptr(prm)
	return 1

#modcfunc ImgCap_SetDefSize
	if ( mWicFC == 0 ){ return 0 }
	SetWindowPos mhWnd, 0, 0, 0, mImgX, mImgY, 0x2
	return 1

#modcfunc ImgCap_TopWnd
	mbTop ^= 1
	if ( mbTop ){ prm = -1 }
	else { prm = -2 }
	SetWindowPos mhWnd, prm, 0, 0, 0, 0, 0x23
	return stat

#modcfunc ImgCap_MouseWheel int w, int l
	GetClientRect mhWnd, varptr(prm)
	ClientToScreen mhWnd, varptr(prm)
	prm(4) = w >> 16
	if ( mWicFC == 0 ){
		prm(5) = int(0.1 * prm(2)), int(0.1 * prm(3))
		if ( prm(4) < 0 ){ prm(2) -= prm(5) : prm(3) -= prm(6) }
		else { prm(2) += prm(5) : prm(3) += prm(6) }
	}
	else {
		d1 = 1.0 * prm(2) / mImgX + 0.09
		d2 = 1.0 * prm(3) / mImgY + 0.09
		if ( d1 > d2 ){ prm(5) = int(d2 * 10) }
		else { prm(5) = int(d1 * 10) }
		if ( prm(4) < 0 ){ prm(5)-- }
		else { prm(5)++ }
		if ( prm(5) <= 0 ){ prm(5) = 1 }
		if ( prm(5) > 300 ){ prm(5) = 300 }
		d1 = 10.0 * prm(5) / 100.0
		prm(2) = int(d1 * mImgX)
		prm(3) = int(d1 * mImgY)
	}
	prm(0) += prm(2) / 2 : prm(1) += prm(3) / 2
	SetCursorPos prm(0), prm(1)
	SetWindowPos mhWnd, 0, 0, 0, prm(2), prm(3), 0x2
	return 1

#modcfunc ImgCap_Save
	wicTmp = mWicFC
	if ( wicTmp == 0 ){ wicTmp = ImgCap_ImgCreate(thismod) }
	if ( wicTmp == 0 ){ return 0 }
	dialog "jpg", 17
	if ( stat == 0 ){ return 0 }
	fileName = refstr
	prm(5) = 0
	prm(12) = 0x19e4a5aa, 0x4fc55662, 0x5817c0a0, 0x57108e02
	IWICImagingFactory_CreateEncoder cWicFactory, prm(12), 0, prm(0)
	if ( stat == 0 ){
		IWICImagingFactory_CreateStream cWicFactory, prm(1)
		if ( stat == 0 ){
			newcom comTmp, IWICBitmapEncoder, -1, prm(0)
			newcom comTmp2, IWICStream, -1, prm(1)
			IWICStream_InitializeFromFilename comTmp2, fileName, 0x40000000
			if ( stat == 0 ){
				IWICBitmapEncoder_Initialize comTmp, prm(1), 2
				if ( stat == 0 ){
					IWICBitmapEncoder_CreateNewFrame comTmp, prm(2), prm(3)
					if ( stat == 0 ){
						newcom comTmp3, IWICBitmapFrameEncode, -1, prm(2)
						newcom comTmp4, IPropertyBag2, -1, prm(3)
						IWICBitmapFrameEncode_Initialize comTmp3, prm(3)
						if ( stat == 0 ){
							newcom comTmp5, IWICFormatConverter, -2, wicTmp
							IWICFormatConverter_GetSize comTmp5, prm(2), prm(3)
							if ( stat == 0 ){
								prm = 0, 0
								IWICBitmapFrameEncode_WriteSource comTmp3, wicTmp, prm
								if ( stat == 0 ){
									IWICBitmapFrameEncode_Commit comTmp3
									if ( stat == 0 ){
										IWICBitmapEncoder_Commit comTmp
										if ( stat == 0 ){ prm(5) = 1 }
									}
								}
							}
							delcom comTmp5
						}
						delcom comTmp3 : delcom comTmp4
					}
				}
			}
			delcom comTmp : delcom comTmp2
		}
	}
	if ( wicTmp != mWicFC ){ prm = ImgCap_ImgDel(thismod, wicTmp) }
	return prm(5)

#modcfunc ImgCap_SetPopMenuItem
	if ( hMenuPop == 0 ){ return 0 }
	prm = 48
	prm(1) = 0x40 : prm(9) = varptr(strMenu(0))
	if ( mWicFC ){ strMenu(0) = "表示(&V)" }
	else { strMenu(0) = "コピー(&C)" }
	SetMenuItemInfo hMenuPop, 0, 1, varptr(prm)
	prm(1) = 1 : prm(3) = 0
	if ( mWicFC ){
		GetClientRect mhWnd, varptr(prm(12))
		if ( prm(14) == mImgX && prm(15) == mImgY ){ prm(3) = 8 }
	}
	SetMenuItemInfo hMenuPop, 3, 1, varptr(prm)
	if ( mbTop ){ prm(3) = 8 } else { prm(3) = 0 }
	SetMenuItemInfo hMenuPop, 4, 1, varptr(prm)
	return 1

*WM_SIZE
	if ( ImgCapGetDp(ginfo(24), dp ) == 0 ){ return }
	prm = ImgCap_Size(dp)
	return

*WM_CLOSE
	idTmp = ginfo(24)
	gsel idTmp, -1
	if ( ImgCapGetDp(idTmp, dp ) == 0 ){ return }
	if ( ImgCap_Close(dp) ){ return }
	return 0

*WM_COMMAND
	idTmp = ginfo(24)
	gsel idTmp, 0
	lw = wparam & 0xffff
	if ( lw == 0x8001 ){
		GetWindowRect hwnd, varptr(prm)
		prm(2) -= prm(0) : prm(3) -= prm(1)
		prm(0) += 20 : prm(1) += 20
		prm = ImgCapCreate(prm(0), prm(1), prm(2), prm(3))
		return
	}
	if ( lw == 0x8005 ){ sendmsg hwnd, 0x10, 0, 0 : return }
	if ( lw == 0x8006 ){ end : end }
	if ( ImgCapGetDp(idTmp, dp ) == 0 ){ return }
	if ( lw == 0x8000 ){ prm = ImgCap_CopyView(dp) : return }
	if ( lw == 0x8002 ){ prm = ImgCap_Save(dp) : return }
	if ( lw == 0x8003 ){ prm = ImgCap_SetDefSize(dp) : return }
	if ( lw == 0x8004 ){ prm = ImgCap_TopWnd(dp) : return }
	return

*WM_LBUTTONDOWN
	gsel ginfo(24), 0
	sendmsg hwnd, 0xa1, 2, 0
	return

*WM_LBUTTONDBLCLK
	if ( ImgCapGetDp(ginfo(24), dp ) == 0 ){ return }
	prm = ImgCap_CopyView(dp)
	return

*WM_RBUTTONDOWN
	if ( ImgCapGetDp(ginfo(24), dp ) == 0 ){ return }
	prm = ImgCap_SetPopMenuItem(dp)
	GetCursorPos varptr(prm)
	TrackPopupMenu hMenuPop, 0, prm(0), prm(1), 0, hwnd, 0
	return

*WM_MBUTTONDOWN
	if ( ImgCapGetDp(ginfo(24), dp ) == 0 ){ return }
	prm = ImgCap_TopWnd(dp)
	return

*WM_MOUSEWHEEL
	if ( ImgCapGetDp(ginfo(24), dp ) == 0 ){ return }
	prm = ImgCap_MouseWheel(dp, wparam, lparam)
	return

#global

/* ---------------------------------------------------------
	Main
   --------------------------------------------------------- */
	if ( ImgCapCreate(100, 100, 300, 200) == 0 ){
		dialog "err" : end
	}
	stop
コメント ( 0 ) | Trackback ( 0 )

DirectWrite 2

サンプル
#include "mod_DWMes.hsp"
	font "メイリオ", 40
	mes "0123456789 mes"
	DWMesFont "メイリオ", 40
	DWMes "0123456789 DWMes"
	stop
#include "mod_DWMes.hsp"
	DWMesClear 200, 200, 200
	DWMesFont msgothic, 32
	DWMesColor 0, 0, 0
	repeat 6
		tmp = cnt * 20
		DWMesOpacity tmp
		DWMes strf("DWMesOpacity %d", tmp)
	loop
	stop
#include "mod_DWMes.hsp"
	screen 0, 300, 300
	onexit *ONEXIT_
	txtNum = 50
	sdim txt, txtNum, 64
	dim txtColor, txtNum
	dim txtPos, txtNum, 4
	w = ginfo_winx : h = ginfo_winy
	repeat txtNum
		txt(cnt) = strf("%c%c%c", rnd(26)+65, rnd(26)+65,rnd(26)+65)
		txtColor(cnt) = rnd(255) | rnd(255) << 8 | rnd(255) << 16
		txtPos(cnt, 0) = rnd(w)
		txtPos(cnt, 1) = rnd(h)
		txtPos(cnt, 2) = rnd(500)
		txtPos(cnt, 3) = rnd(2)
	loop

	DWMes2Make dw, hdc, msmincho, 32, 800, 0, 0, 0
	repeat
		DWMes2Begin dw, 0, 0, w, h
		DWMes2Clear dw, 30, 30, 30
		repeat txtNum
			d = 1.0 * txtPos(cnt, 2) / 100.0
			DWMesScale d, d, w / 2, h / 2
			DWMes2Color dw, txtColor(cnt) & 0xff, (txtColor(cnt) >> 8) & 0xff, (txtColor(cnt) >> 16) & 0xff
			DWMes2 dw, txt(cnt), txtPos(cnt, 0), txtPos(cnt, 1), w, h
			if ( txtPos(cnt, 3) ){
				txtPos(cnt, 2) += 3 : if ( txtPos(cnt, 2) > 500 ){ txtPos(cnt, 3) = 0 }
			}
			else {
				txtPos(cnt, 2) -= 5 : if ( txtPos(cnt, 2) < 0 ){ txtPos(cnt, 3) = 1 }
			}
		loop
		DWMes2End
		redraw 1
		await 20
	loop
	stop

*ONEXIT_
	DWMes2Free dw
	end
#include "mod_DWMes.hsp"
	s = {"Hello World !!
		DirectWrite
		mod_DWMes.hsp"}

	screen 0, 300, 300
	DWMesFont "メイリオ", 30, 800
	DWMesColor 255, 255, 255
	repeat
		redraw 0
		color : boxf
		pos 50, 50
		DWMesSkew cnt, cnt, 150, 150
		DWMes s
		redraw 1
		await 20
	loop
	stop
#include "mod_DWMes.hsp"
	s  = "2.プログラミングガイド¥n¥n2.1.スクリプトの形式¥n"
	s += " HSPはプログラム(命令と実行の順序を記したもの)によって動作します。"
	s += "そのもとになるのがスクリプト(ソースファイル)です。"
	s += "これはテキストファイルの形式で、拡張子は .hsp または、.as になります。"
	s += "(拡張子 .hsp は、HSP3.0から追加されたものです。)"
	s += "スクリプトはHSPに付属しているHSPスクリプトエディタ(HSED3.EXE)や、"
	s += "テキストエディタなどのアプリケーションで作成することができます。"

	screen 0, 300, 300
	DWMesFont "メイリオ", 14
	DWMesVertical
	DWMes s
	stop
#include "mod_DWMes.hsp"
	screen 0, 200, 100
	DWMesFont msgothic, 32
	DWMesSetTrimming 1, 1
	x = 0
	repeat
		redraw 0
		color 255, 255, 255 : boxf
		pos x, 30
		DWMes "あいうえお"
		redraw 1
		await 20
		x++
		if ( x > ginfo_winx ){ x = -200 }
	loop
	stop
簡易説明
DWMesは、現在選択されているウィンドウのカレントポジションのX、Yに文字を描画します。 DWMesFontでフォントの変更、DWMesColorで文字色の変更、DWMesOpacityで文字の透明度の設定、DWMesWordWrappingで自動改行の設定、 DWMesTabStopでタブストップの設定。

DWMes2は、任意のデバイスコンテキスト(hdc)の任意の範囲内に文字を描画します。 DWMes2から始まる命令を使用します。
状況にもよりますが、DWMesより高速です。
    使用例
  1. DWMes2Makeで描画用変数を初期化する
  2. DWMes2Beginで描画開始
  3. DWMes2で文字表示
  4. DWMes2Endで描画終了
  5. DWMes2Freeで描画用変数を解放する
mesの表示時間を1とした時、DWMesは40、DWMes2は2。
DWMesが遅いのは、ID2D1DCRenderTarget::BeginDrawとID2D1DCRenderTarget::EndDrawを毎回呼び出ししている事が原因です。

DWMesは、mes同様、カレントポジションのY座標(ginfo_cy)を移動します。 しかし、Transform関連の命令後は正確に反映されないことがあります。
コメント ( 0 ) | Trackback ( 0 )
« 前ページ