Tim's profileAlwaysPhotosBlogListsMore ![]() | Help |
|
December 29 netstatC:>netstat /? -a Displays all connections and listening ports. (Server-side connections are normally not shown). -e Displays Ethernet statistics. This may be combined with the -s option. -n Displays addresses and port numbers in numerical form. -p proto Shows connections for the protocol specified by proto; proto may be tcp or udp. If used with the -s option to display per-protocol statistics, proto may be tcp, udp, or ip. -r Displays the contents of the routing table. -s Displays per-protocol statistics. By default, statistics are shown for TCP, UDP and IP; the -p option may be used to specify a subset of the default.interval Redisplays selected statistics, pausing interval seconds between each display. Press CTRL+C to stop redisplaying statistics. If omitted, netstat will print the current configuration information once. Static global variableGlobal 變數被宣告成static之後會變成只有在該file才能使用該變數
其他有關Static的小雜記
-A static member function does not have a this pointer.
The compiler does not allow the member access operation this-> in static member function because this member function has been declared as static, and therefore does not have a this pointer.
-A static member function cannot be declared with the keywords virtual, const, volatile, or const volatile.
-A static member function can access only the names of static members, enumerators, and nested types of the class in which it is declared. Suppose a static member function f() is a member of class X. The static member function f() cannot access the nonstatic members X or the nonstatic members of a base class of X. December 28 PostMessage和SendMessage的不同SendMessage會直接送Message給指定的視窗而不經過訊息佇列,他會等到該視窗處裡完訊息回傳處裡的結果屬於sync call
而PostMessage會把Message送給訊息佇列而且馬上return傳送成功或失敗屬於async call 把CE上面的WMP叫到前景HWND hwnd=NULL; hwnd=FindWindow(_T("WMP for Mobile Devices"),_T("Windows Media")); if (hwnd != NULL){ SetForegroundWindow(hwnd); } String 轉換 極簡版1、char*轉換成CString 若將char*轉換成CString,除了直接賦值外,還可使用CString::Format進行。例如: CODE: char chArray[] = "This is a test"; 或char * p = "This is a test"; CODE: LPSTR p = "This is a test"; 或在已定義Unicode應的用程式中CODE: TCHAR * p = _T("This is a test"); 或CODE: LPTSTR p = _T("This is a test"); 2、CString轉換成char*CString theString = chArray; theString.Format(_T("%s"), chArray); theString = p; 若將CString類轉換成char*(LPSTR)類型,常常使用下列三種方法: 方法一,使用強制轉換。例如: CODE: CString theString( "This is a test" ); 方法二,使用strcpy。例如:LPTSTR lpsz =(LPTSTR)(LPCTSTR)theString; CODE: CString theString( "This is a test" ); 需要說明的是,strcpy(或可移值Unicode/MBCS的_tcscpy)的第二個參數是 const wchar_t* (Unicode)或const char* (ANSI),系統編譯器將會自動對其進行轉換。LPTSTR lpsz = new TCHAR[theString.GetLength()+1]; _tcscpy(lpsz, theString); 方法三,使用CString::GetBuffer。例如: CODE: CString s(_T("This is a test ")); 3、BSTR轉換成char*LPTSTR p = s.GetBuffer(); // 在這裏添加使用p的代碼 if(p != NULL) *p = _T('\0'); s.ReleaseBuffer(); // 使用完後及時釋放,以便能使用其他的CString成員函數 方法一,使用ConvertBSTRToString。例如: CODE: #include 方法二,使用_bstr_t的賦值運算符重載。例如:#pragma comment(lib, "comsupp.lib") int _tmain(int argc, _TCHAR* argv[]) { BSTR bstrText = ::SysAllocString(L"Test"); char* lpszText2 = _com_util::ConvertBSTRToString(bstrText); SysFreeString(bstrText); // 用完釋放 delete[] lpszText2; return 0; } CODE: _bstr_t b = bstrText; 4、char*轉換成BSTRchar* lpszText2 = b; 方法一,使用SysAllocString等API函數。例如: CODE: BSTR bstrText = ::SysAllocString(L"Test"); 方法二,使用COleVariant或_variant_t。例如:BSTR bstrText = ::SysAllocStringLen(L"Test",4); BSTR bstrText = ::SysAllocStringByteLen("Test",4); CODE: //COleVariant strVar("This is a test"); 方法三,使用_bstr_t,這是一種最簡單的方法。例如:_variant_t strVar("This is a test"); BSTR bstrText = strVar.bstrVal; CODE: BSTR bstrText = _bstr_t("This is a test"); 方法四,使用CComBSTR。例如:CODE: BSTR bstrText = CComBSTR("This is a test"); 或CODE: CComBSTR bstr("This is a test"); 方法五,使用ConvertStringToBSTR。例如:BSTR bstrText = bstr.m_str; CODE: char* lpszText = "Test"; 5、CString轉換成BSTRBSTR bstrText = _com_util::ConvertStringToBSTR(lpszText); 通常是通過使用CStringT::AllocSysString來實現。例如: CODE: CString str("This is a test"); 6、BSTR轉換成CStringBSTR bstrText = str.AllocSysString(); … SysFreeString(bstrText); // 用完釋放 一般可按下列方法進行: CODE: BSTR bstrText = ::SysAllocString(L"Test"); 或CStringA str; str.Empty(); str = bstrText; CODE: CStringA str(bstrText); 7、ANSI、Unicode和寬字元之間的轉換方法一,使用MultiByteToWideChar將ANSI字元轉換成Unicode字元,使用WideCharToMultiByte將Unicode字元轉換成ANSI字元。 方法二,使用“_T”將ANSI轉換成“一般”類型字串,使用“L”將ANSI轉換成Unicode,而在託管C++環境中還可使用S將ANSI字串轉換成String*物件。例如: CODE: TCHAR tstr[] = _T("this is a test"); 方法三,使用ATL 7.0的轉換宏和類。ATL7.0在原有3.0基礎上完善和增加了許多字串轉換巨集以及提供相應的類,它具有如圖3所示的統一形式:wchar_t wszStr[] = L"This is a test"; String* str = S”This is a test”; 其中,第一個C表示“class”,以便於ATL 3.0宏相區別,第二個C表示常量,2表示“to”,EX表示要開闢一定大小的緩衝。SourceType和DestinationType可以是A、T、W和OLE,其含義分別是ANSI、Unicode、“一般”類型和OLE字串。例如,CA2CT就是將ANSI轉換成一般類型的字串常量。下面是一些示例代碼: CODE: LPTSTR tstr= CA2TEX<16>("this is a test");
LPCTSTR tcstr= CA2CT("this is a test"); wchar_t wszStr[] = L"This is a test"; char* chstr = CW2A(wszStr); 結語 http://140.118.175.207/Discuz/upload/viewthread.php?tid=39&extra=page%3D1 [轉錄]CString,string,char*的综合比较(2)e) 增加
f) 截取
g) 移除
h) 转换大小写
i) 与其他类型转换
j) 格式化
k) 得到长度
l) 判断为空
m) 重定义大小
n) 释放资源
(五) 安全性 CString > string > char*; (六) 灵活性 CString > string >char*; (七) 可移植性 char* = string > CString (九) 总结 综上所述,我个人认为,在MFC、ATL中使用字符串尽量使用CString,毕竟都是微软的孩子,各方面都比其它更有优势,而在非微软平台上或对移植性要求较高的场合推荐使用string,标准模板库提供了那么强大的泛型算法,没必要再自己去造车轮。 (十) 参考文献 主要参考的是MSDN,就不一一列出了。 [轉錄]CString,string,char*的综合比较(一) 概述 string和CString均是字符串模板类,string为标准模板类(STL)定义的字符串类,已经纳入C++标准之中; CString(typedef CStringT<TCHAR, StrTraitMFC<TCHAR>> CString)为Visual C++中最常用的字符串类,继承自CSimpleStringT类,主要应用在MFC和ATL编程中,主要数据类型有char(应用于ANSI),wchar_t(unicode),TCHAR(ANSI与unicode均可); char*为C编程中最常用的字符串指针,一般以’\0’为结束标志; (二) 构造 ² string是方便的,可以从几乎所有的字符串构造而来,包括CString和char*; ² CString次之,可以从基本的一些字符串变量构造而来,包括char*等; ² char*没有构造函数,仅可以赋值; ² 举例: char* psz = “joise”; CString cstr( psz ); string str( cstr ); (三) 运算符重载 a) operator= ² string是最方便的,几乎可以直接用所有的字符串赋值,包括CString和char*; ² CString次之,可以直接用些基本的字符串赋值,包括char*等; ² char*只能由指针赋值,并且是极危险的操作,建议使用strcpy或者memcpy,而且char*在声明的时候如未赋初值建议先设为NULL,以避免野指针,令你抓狂; ² 举例: char *psz = NULL; psz = new char[10]; //当然,以上的直接写成char *psz = new char[10];也是一样 memset( psz, 0, 10 ); strcpy( psz, “joise” ); CString cstr; cstr = psz; string str; str = psz; str = cstr; delete []psz; b) operator+ ² string与CString差不多,可以直接与char*进行加法,但不可以相互使用+运算符,即string str = str + cstr是非法的,须转换成char*; ² char*没有+运算,只能使用strcat把两个指针连在一起; ² 举例: char* psz = “joise”; CString cstr = psz; cstr = cstr + psz; string str = psz; str = str + str + psz; strcat( psz, psz ); strcat( psz, cstr );//合法 strcat( psz, str );//非法,由此可见,CString可自动转换为const char*,而string不行 c) operator += ² string是最强大的,几乎可以与所有的字符串变量+=,包括CString和char*; ² CString次之,可以与基本的一些字符串变量进行+=而来,包括char*等; ² char*没有+=运算符,只能使用strcat把两个指针连在一起; d) operator[] ² CString最好,当越界时会抛出断言异常; ² string与char*下标越界结果未定义; ² 举例: char* psz = “joise”; CString cstr = psz; cout << cstr[8]; string str = psz; cout << str[8]; cout << psz[8]; e) operator== 、operator!=、operator> 、operator< 、operator>= 、perator<= ² CString与string之间不可以进行比较,但均可以与char*进行比较,并且比较的是值,而不是地址; cout << ( psz == cstr ); cout << ( psz == str ); cout << ( str == psz ); cout << ( cstr == psz );//以上代码返回均为1 (四) 常用算法 a) 查找
注:find_if中是把范围内的值挨个代入匹配函数直至返回true b) 比较
注:返回值如果<0则前面的值小于后面的值,反之亦然 c) 替换
d) 插入
[轉錄]基本類型轉換整理int i = 100;
二、字符串转换为其它数据类型
三、其它数据类型转换到CString
四、BSTR、_bstr_t与CComBSTR
五、VARIANT 、_variant_t 与 COleVariant
六、其它一些COM数据类型
七、ANSI与Unicode
八、其它
九、注意事项
December 26 [轉錄]#pragma once的缺點The programmer must rely on the compiler to handle And, it is not recognized by all preprocessors, so you cannot rely on it in a portable program. December 21 [轉錄]手機簡史--
首先是1G. 2G. 3G的這個G字,其實就是Generation,也就是世代的意思,所以3G很多人可能會誤以為有三個G開頭的字(類似我們今天稱呼triple W or I triple E),但其實真的就只是3rd Generation的意思,怎麼樣?單純到有點出乎你的意料吧? 簡單來說,從1G進步到2G,主要的改變是從類比訊號轉為數位訊號,在1G通訊標準時期,最著名的規格是AMPS (Advanced Mobile Phone System),早期的黑金剛即屬此種規格下的產品,其實Advanced指的進階,只是比一般的室內電話更進步一點,所以就跟室內電話一樣,AMPS也是類比的語音傳輸,而AMPS所採用的處理技術為FDMA (Frequency Division Multiple Access,分頻多工存取)。 後來2G則進步到數位訊號,其中的規格並不只有一種,所採用的技術也可以粗淺的分為TDMA與CDMA兩種。歐洲、台灣等地所使用的GSM (Global System For Mobile Communication)與日本採用的PDC (Personal Digital Cellular)都屬於TDMA(Time Division Multiple Access,分時多工存取)的技術,而美國則由Qualcomm公司發展出一套嶄新的傳輸標準CDMA (Code Division Multiple Access,分碼多工存取),此時的CDMA其實仍然屬於2G的範圍,後來則被通稱為所謂的窄頻CDMA (narrow-band CDMA),以便於跟3G的新一代CDMA技術做區別。 至於3G與2G的差異,最主要的地方在於資料傳輸的速度,換句話說也就是頻寬的增加。3G的通訊標準不一而足,但主要都是從CDMA技術為藍圖而發展出來的,最著名的包括了W-CDMA (Wide-band CDMA)、CDMA 2000、以及大陸積極推動的TDS-CDMA。這些都只是資料傳輸技術的不同。 至於FOMA (Freedom Of Multimedia Access),本身並不是一種技術,而是日本NTT DoCoMo所推出的3G行動上網服務,這也是全球第一個真正商業運行的3G服務,FOMA本身採用W-CDMA的技術,基地台設備則由Ericsson提供。所以拿FOMA來跟W-CDMA、CDMA 2000或是TDMA來比是有概念化上的缺失,就好像拿橘子跟椅子比一樣,而日本第二大系統業者KDDI所推動的3G服務,則是以CDMA 2000為架構。 而所謂的WAP與GPRS,其實兩者之間也無法真正被拿來作比較,這也是目前很多很多人的一個誤解,以為GPRS是拿來與WAP相提並論的。WAP (Wireless Application Protocol,無線應用協定)是一種通訊協定,就好像internet上用的是HTTP一樣,而在WAP協定下所使用的程式語言則為WML (Wireless Mark-Up Language),這也相對於一般internet所使用的HTML。 而在介紹GPRS以前,我們應該要對幾個概念正名一下(這可不是什麼台灣正名運動的正名),一般我們說的WAP手機,其實應該是指WAP Over Circuit-Switched Data,或是簡單一點說成WAP Over GSM Circuit也行,但我們所說的GPRS手機上網,其實是屬於WAP Over Packet-Switched Data,或是WAP Over GPRS。從這邊我們可以看出來,GPRS相對的概念其實並不是WAP,而應該是傳統GSM線路的傳輸方式。 GPRS (General Packet Radio Service,通用封包無線傳輸服務),根本上的技術是從之前GSM線路傳輸的9.6Kbps,改用封包傳輸的技術,分開傳送、同步處理,使得傳輸速度得以大幅度提升,理論上可以達到100Kbps,但目前實作出來的速度約略是在40~50Kbps左右(依所利用到的Time Slot而定)。至於為什麼GSM線路傳輸的速度只有9.6Kbps而不是96Kbps,這可真的是一個大哉問了,我只能說,一開始GSM規格在制定的時候,一個時槽(Time Slot)所劃分的頻寬扣掉容錯碼後就只剩9.6Kbps(因為一開始GSM仍然是拿來講電話的,當初誰會想到要用這玩意上網?),而GPRS技術則可以一次利用單一頻率中全部的八個時槽來傳輸資料,至於傳送的方式則是拆開成封包同步傳輸,後端再把封包組裝起來形成原始的資料(想像成WinRAR或是Love Machine的多個壓縮檔就能理解了),但這邊又有一個技術要跟GPRS釐清不同的地方,那就是所謂的HSCSD (High Speed Circuit Switched Data Service),HSCSD與GPRS類似的地方是都能同時使用超過一個的時槽進行資料傳輸,但相異的地方在於HSCSD仍然是採用傳統GSM的線路傳輸技術而非GPRS的封包傳送,所以如果覺得GPRS上網太貴的人,不妨去看看新加坡HSCSD服務的費率吧,包管你看了以後不寒而慄。至於把GPRS稱作2.5G,其實是一個有些投機取巧的做法,因為真的要探究邏輯性思考的話(沒辦法,進研究所以後一天到晚在那邊討論邏輯思考,弄的我都有點神經質),顯然2.5G是一個有很大問題的名詞,因為Generation這個字的意思本身就是無法被分割的,就好像考試的成績,第一名後面就是第二名,沒有什麼2.5名這種東西,既然有2.5名那他就是第三名!會拿2.5G來稱呼GPRS,無非是因為GPRS大幅度提升了GSM系統架構下資料傳輸的速度,可是這個速度又還沒達到3G的要求,只好給它硬塞一個2.5G的名詞,至於2.7G,那就更Kuso了,為什麼是2.7不是2.8呢?其實我也不知道,相信搞出這個名詞的人也不知道。 |
|
|