使用hook function的時候需要餵入一個function pointer
hook function的參數要求是
2018年6月12日 星期二
2018年3月25日 星期日
c# delegate instance 被回收
MIL 的process 範例中有這一段
MIL_DIG_HOOK_FUNCTION_PTR ProcessingFunctionPtr = new MIL_DIG_HOOK_FUNCTION_PTR(ProcessingFunction);
MIL_DIG_HOOK_FUNCTION_PTR ProcessingFunctionPtr = new MIL_DIG_HOOK_FUNCTION_PTR(ProcessingFunction);
MIL.MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize, MIL.M_START, MIL.M_DEFAULT, ProcessingFunctionPtr, GCHandle.ToIntPtr(hUserData));
其中
public delegate MIL_INT MIL_DIG_HOOK_FUNCTION_PTR(MIL_INT HookType, MIL_ID EventId, IntPtr UserDataPtr);
但如果是用在winform 應用程式裡面,如果把上面那段放在Form的Initial中,需要把 ProcessingFunctionPtr 定義成在 Form的Class底下的static member
MyForm:Form
{
static MIL_DIG_HOOK_FUNCTION_PTR ProcessingFunctionPtr;
void MyForm()
{
...
ProcessingFunctionPtr = new MIL_DIG_HOOK_FUNCTION_PTR(ProcessingFunction);
MIL.MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize, MIL.M_START, MIL.M_DEFAULT, ProcessingFunctionPtr, GCHandle.ToIntPtr(hUserData));
}
}
否則在執行期ProcessingFunctionPtr會被Gabage collection清掉而產生error
但在C# 2.0 好像可以直接寫成
ProcessingFunctionPtr = ProcessingFunction;
c# delegate instance 被回收
2016年12月21日 星期三
[C#] class/function 前面的方括號
在看ApplicationSetting所產生的code的時候發現一段code
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string filePath {
get {
return ((string)(this["filePath"]));
}
set {
this["filePath"] = value;
}
}
public string filePath{}前面的[]們,原來是Attribute。寫專案還沒時間看,先筆記一下
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string filePath {
get {
return ((string)(this["filePath"]));
}
set {
this["filePath"] = value;
}
}
public string filePath{}前面的[]們,原來是Attribute。寫專案還沒時間看,先筆記一下
[C#] class/function 前面的方括號
vs debug 時期路徑
因為debug的時候exe會因為x86/x64....的原因build到不同的位子去
如果有使用相對路徑去讀取檔案就可能會需要很多份
要找Resource們也會很困難
一個簡單的方法是去設定debug的路徑
如果有使用相對路徑去讀取檔案就可能會需要很多份
要找Resource們也會很困難
一個簡單的方法是去設定debug的路徑
vs debug 時期路徑
2016年12月16日 星期五
c# constructor 呼叫順序
在繼承關係中,constructor的呼叫順序是
1. 所有參數預設值會先被設定
class MyClass
{
int para1 = 1;...
}
因此在constructor被呼叫時,para1已經是1了
2. 最base的constructor被呼叫
3. 一層層往上呼叫
4. 最derived的最後被呼叫
5. 最後執行Object and collection initializer
(new myClass{para1 = 2; para2 = 3;...})初始會陣列就是用這個操作方式
c# constructor 呼叫順序
2016年11月25日 星期五
[VS] 程式快捷鍵
[VS]取消textbox的輸入狀態
在form中加入了快捷鍵的功能後在textBox中輸入文字竟然也會觸發快鍵
難怪快捷鍵都設定成ctrl+blablabla
但是我就是為了方便程式運作不用用滑鼠按按鈕,所以快捷鍵只想按鍵盤上的一個鍵,因此在textbox輸入時要阻止form的快捷鍵運作。
[VS]取消textbox的輸入狀態
[VS]設定透明Label
將Label背景設定為透明
label.Parent = pictureBox_lowerLayerObject;
label.BackColor = Color.Transparent;
label.Parent = pictureBox_lowerLayerObject;
label.BackColor = Color.Transparent;
[VS]設定透明Label
2016年11月13日 星期日
C++ c# raw string literal 原始字串
在C++字串中為了可以表示換行,tab等特殊操作,因此有跳脫字元\
好死不死資料夾路徑也用很多'\'
以前都會使用兩個("\\")表示\,但這樣的問題是在複製路徑後需要經過加工有點麻煩
ex: c:\testFile.txt 需要以 "c:\\testFile.txt"表示,麻煩
C++ 11裡面提供Raw String
表示
R"\a\b\c"
相當於
"\\a\\b\\c"
蠻方便的
在c#中則可以用 @"\a\b\c"
相當於"\\a\\b\\c"
好死不死資料夾路徑也用很多'\'
以前都會使用兩個("\\")表示\,但這樣的問題是在複製路徑後需要經過加工有點麻煩
ex: c:\testFile.txt 需要以 "c:\\testFile.txt"表示,麻煩
C++ 11裡面提供Raw String
表示
R"\a\b\c"
相當於
"\\a\\b\\c"
蠻方便的
在c#中則可以用 @"\a\b\c"
相當於"\\a\\b\\c"
C++ c# raw string literal 原始字串
2016年11月2日 星期三
Interface, abstract class
今天試著寫grabber跟processor
本來是寫用Mil作grabber, vidi作processor
後來想想說把他抽象化,趁機研究了一下abstract, Interface跟呼叫base的contructor
Interface, abstract class
2016年10月18日 星期二
2016年8月4日 星期四
在c++/cli專案中使用c# dll
因為廠商提供的專案是c++,但是轉檔的utility是c#所以研究了一下
google會看到很多用COM物件或是其他看起來有點麻煩的方法
研究後發現是很困難,but還是有些不踏實的地方
後來覺得小東西也是可以整個重寫就好啦XD
google會看到很多用COM物件或是其他看起來有點麻煩的方法
研究後發現是很困難,but還是有些不踏實的地方
後來覺得小東西也是可以整個重寫就好啦XD
在c++/cli專案中使用c# dll
2016年8月3日 星期三
[小技巧]忽略字串中的跳脫字串
一般C#中以\作為跳脫字串的起始,所以若要輸入路徑,則要輸入
可以用@""忽略跳脫字串
例如:
這樣直接copy path再貼到程式中
"C:\\a\\b\\c"可以用@""忽略跳脫字串
例如:
@"C:\a\b\c"這樣直接copy path再貼到程式中
[小技巧]忽略字串中的跳脫字串
2016年7月22日 星期五
將object的properties/fields取出
今天想寫一個自動把所有object(已實體化 instanced)中的member抽取出來的功能。抽取的目的是要將object的members全部放入一個List中,其他東西呼叫的時候可以直接呼叫List就好。但在coding的時候又可以有class memeber的防呆特性。
將object的properties/fields取出
C#利用Type建立物件
BaseClass bd = new DClass();
BaseClass newB = (BaseClass)System.Activator.CreateInstance(bd.GetType());
這時候bd.GetType()會得到DClass
BaseClass newB = (BaseClass)System.Activator.CreateInstance(bd.GetType());
這時候bd.GetType()會得到DClass
C#利用Type建立物件
2016年7月21日 星期四
用enum value作為array index in C#
為了免code看不懂,可以用enum去指定array的index
ex:
cars[0] = .....
-> cars[(int)carNames.MrsOliver] = ....
好處是在遙遠的另一邊不用去猜0號車到底是MrsOliver還是MrsMarry
範例:
Schedule[] schedules = new int[Enum.GetNames(typeof(WeekDay)).Length];
enum WeekDay
{
sun = 0;
mon = 1;
tue = 2;
...
}
schedules[(int)weekDay.sun] = ....
當然也可以建立個key是enum type的 dictionary
Dictionary<WeekDay, Schedule> schedules = new Dictionary<WeekDay, Schedule>();
就可以直接存取
schedules[weekDay.sun] = ....
ex:
cars[0] = .....
-> cars[(int)carNames.MrsOliver] = ....
好處是在遙遠的另一邊不用去猜0號車到底是MrsOliver還是MrsMarry
範例:
Schedule[] schedules = new int[Enum.GetNames(typeof(WeekDay)).Length];
enum WeekDay
{
sun = 0;
mon = 1;
tue = 2;
...
}
schedules[(int)weekDay.sun] = ....
當然也可以建立個key是enum type的 dictionary
Dictionary<WeekDay, Schedule> schedules = new Dictionary<WeekDay, Schedule>();
就可以直接存取
schedules[weekDay.sun] = ....
用enum value作為array index in C#
2016年7月20日 星期三
news in C#6.0 CS 6.0新增功能
What's new in C# 6.0
觀看筆記
沒啥大改,有一些可以讓程式碼乾淨點的小東西
auto properties, static members, String interpolation, Expression bodied methods, Index initializer, Null-conditional operators, The nameof operator, Exception filters
觀看筆記
沒啥大改,有一些可以讓程式碼乾淨點的小東西
auto properties, static members, String interpolation, Expression bodied methods, Index initializer, Null-conditional operators, The nameof operator, Exception filters
news in C#6.0 CS 6.0新增功能
2016年7月13日 星期三
pointer in c#
在manage code中使用pointer的方法
這裡會用到
System.Runtime.InteropServices.GCHandle類別,提供從unmanaged memory中存取manage object的方式
使用命名空間
using System.Runtime.InteropServices;
這裡會用到
System.Runtime.InteropServices.GCHandle類別,提供從unmanaged memory中存取manage object的方式
使用命名空間
using System.Runtime.InteropServices;
pointer in c#
訂閱:
文章 (Atom)