星期三, 7月 25, 2012

在msbuild中取得system32位置,不分64還是32位元windows

<PropertyGroup>
  <X64SystemDir>$(SystemRoot)\Sysnative</X64SystemDir>
  <X32SystemDir>$(SystemRoot)\System32</X32SystemDir>
</PropertyGroup>

<Choose>
  <When Condition="Exists('$(X64SystemDir)')">
    <PropertyGroup>
      <SystemDir>$(X64SystemDir)</SystemDir>
    </PropertyGroup>
  </When>
  <Otherwise>
    <PropertyGroup>
      <SystemDir>$(X32SystemDir)</SystemDir>
    </PropertyGroup>
  </Otherwise>
</Choose>

星期三, 3月 14, 2012

C++11: make_shared<T>()

Sample:

#include <memory>
#include <iostream>

using namespace std;

class MyClass{
public:
int m_i;
MyClass(int i):m_i(i){  cout << "constructor" << endl;
}
~MyClass(){
cout << "destructor" << endl;
}
};

void _tmain(int argc, _TCHAR* argv[])
{
cout << "enter main" << endl;
auto a = make_shared<MyClass>(10);
cout << a->m_i << endl;
cout << "leave main" << endl;
}


output:



enter main

constructor

10

leave main

destructor

星期二, 11月 22, 2011

利用sregex_iterator找出所有符合指定regular expression的子字串

<<程式>>


#include <regex>
#include <string>
#include <iostream>
using namespace std;
 
int _tmain(int argc, _TCHAR* argv[])
{
 try{
  regex re("\\d++");
  string input("123 23 435 asd 000");
  sregex_iterator ite(input.begin(), input.end(), re);
  sregex_iterator iteEnd;
  for(; ite != iteEnd; ++ite){
   cout << "found: " << ite->str() << " at " << ite->position() << " length " << ite->length() << endl;
  }
 } catch(regex_error& e){
  cout << "Error: " << e.what() << endl;
 }
 return 0;
}


<<輸出>>


found: 123 at 0 length 3
found: 23 at 4 length 2
found: 435 at 7 length 3
found: 000 at 15 length 3

星期一, 5月 09, 2011

在c#中正確處理Unicode

程式碼:

string s = "哈\uD950\uDF21高";   Console.WriteLine("string length:" + s.Length);  
TextElementEnumerator textEnum =
   StringInfo.GetTextElementEnumerator(s);   while (textEnum.MoveNext())   {   
   Console.WriteLine("word {0}: {1}",
     textEnum.ElementIndex, 
     textEnum.Current.ToString());  
}
* This source code was highlighted with Source Code Highlighter.

輸出:
string length:4
word 0: 哈
word 1: ??
word 3: 高

重點:

  • UTF-32等同於UCS-4 (Universal Character Set –4 ), 編碼範圍在0~7F FF FF FF
  • UTF-16不等同於UCS-2。USC-2只涵蓋部分USC-4的字元。而UTF-16可以涵蓋所有UTF-32的字元
  • UTF-16利用surrogate機制,讓某些UTF-32的字元以一對UTF-16編碼的形式來表示
  • USC-2跟UTF-16的差別在於有無surrogate機制上
  • .Net使用的char型別存放的是UTF-16

星期二, 1月 25, 2011

Doxgen筆記

格式:

/**
  * @warning A Warning!!
  */

星期一, 1月 10, 2011

在Microsoft Access筆記中

參照到使用者介面物件

  • [Forms]![Questions]![RawData 子表單].Form![answer]

取得目前使用者

星期日, 10月 24, 2010

Visual Studio的編譯會受Windows SDK版本設定的影響

幾個簡單檢視目前Windows SDK版本的方法:

  • 方法一: 開啟Visual Studio Command Prompt, 下echo %windowssdkdir%指令
  • 方法二: 開啟vc專案,找到”Include Directories”之類的設定項目,在編輯畫面的Macros中檢視 $(WindowsSDKDir)

Windows SDK版本設定如果不正確,可能會導致vc專案編譯失敗,出現類似像windows.h找不到的錯誤訊息。

修正方式:

  • 在windows SDK目錄下,使用以下命令來設定(以下命令將SDK版本設定為v7.0A):
    C:\Program Files\Microsoft SDKs\Windows\v7.1\Setup>WindowsSdkVer.exe -version:v7.0A

參考資料

星期二, 8月 10, 2010

嘗試在VS2010中使用C++0x的shared_ptr以及lambda expression搭配STL container

#include <iostream>
#include <vector>
#include <memory>
#include <algorithm>

using namespace std;

class Base{
public:
    int m_i;
    Base(int i):m_i(i) {}
    ~Base(){ cout << m_i << "~Base()" << endl; }
};

class Derived: public Base{
public:
    Derived(int i):Base(i) { }
    ~Derived(){
        cout << "~Derived()" << endl;
    }
};

int main()
{
    vector< shared_ptr<Base> > v;
    v.push_back(shared_ptr<Base>(new Derived(1)));
    v.push_back(shared_ptr<Base>(new Derived(2)));
    sort(v.begin(), v.end(), [](shared_ptr<Base> a, shared_ptr<Base> b){
        return a->m_i > b->m_i;
    });

    for_each(v.begin(), v.end(), [](shared_ptr<Base> a){
        cout << a->m_i << "\t";
    });
    cout << endl;
    return 0;
}

星期四, 7月 08, 2010

莫名其妙的簡繁轉換

葉:叶
舊:旧
盡:尽

星期日, 6月 06, 2010

在VS2010中,指定clean solution或project前執行某些指令

由於vs2010 IDE似乎沒有直接支援這樣設定,因此採用Import Project的方式,以便明確地看出這是額外加上去的指令。

  1. 在 *.vcxproj file中Import Project:
    <Import Project="Extra.targets"/>
  2. 建立Extra.targets file, 內容為:
    <?xml version="1.0" encoding="utf-8"?>
    <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3.   <Target Name="BeforeCppClean">
        <Exec Command="echo Hello World" />
      </Target>
    </Project>

相關資料:

  • C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets and Microsoft.CppClean.targets
  • MSBuild Schema Reference

星期四, 12月 24, 2009

64 bit windows registry redirector and reflection

定義:

  • redirector: 讓32 bit與64 bit程式使用相同的registry key存取不同的registry實體
  • reflection: 自動同步相同registry key的32 bit與64 bit registry實體

各registry key詳細的redirection與reflection狀況需參考 Registry Keys Affected by WOW64

其他注意事項:

  • registry寫入時,如果開頭為%ProgramFiles%或%commonprogramfiles%,會視情況自動改寫為"%ProgramFiles(x86)%"或"%commonprogramfiles(x86)%"。
  • 以下目錄也會視情況被改寫: %windir%\system32, %SystemRoot%\system32,  C:\windows\system32

參考

星期三, 12月 23, 2009

64 bit windows file system redirector

32bit軟體存取路徑時的重新導向原則

  • %windir%\System32 -> %windir%\SysWOW64
  • %windir%\lastgood\system32 -> %windir%\lastgood\SysWOW64
  • %windir%\regedit.exe –> %windir%\SysWOW64\regedit.exe
  • 注意: 如果過程中觸發了UAC prompt, 則上述重新導向都不會發生。將會發生32bit軟體試圖執行64bit DLL或其他程式的問題。
    • 若要避免此問題,需在該32bit程式中直接引用SysWOW64

其他注意事項

星期四, 12月 10, 2009

在Webdashboard上建立link直接連接到造成此次build的subversion revision頁面

在header.xsl的<xsl:template match="/cruisecontrol/modifications/modification">區塊中加入以下片段:

<xsl:if test="changeNumber">
<tr>
  <td class="header-label" valign="top">
    <nobr>ChangeSet of XXXXX</nobr>
  </td>
  <td class="header-data">
      <a>
        <xsl:attribute name="href">
http://xxxx/changeset/<xsl:value-of select="changeNumber"/>
        </xsl:attribute>changeSet <xsl:value-of select="changeNumber"/>
      </a>
  </td>
</tr>
</xsl:if>

星期二, 12月 01, 2009

windows上Python第一次使用步驟

編輯與執行python程式

  1. 下載python
  2. 執行IDLE (Python GUI)
  3. Ctrl+N編輯新python程式或Ctrl+O開啟已經存在的python程式
  4. F5執行

撰寫python unit test程式

import sys
import unittest

def SayHello(name):
    return "hello " + name

class TestSayHello(unittest.TestCase):
    def testHelloAska(self):
        self.assertEqual("hello Aska", SayHello("Aska"))
    def testHelloWorld(self):
        self.assertEqual("hello World", SayHello("World"))
if __name__ == "__main__":
    if len(sys.argv) < 2:
        unittest.main()
    else:
        SayHello(sys.argv[1]);

星期二, 9月 01, 2009

Tomcat安裝後無法進入管理介面

預設的C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\tomcat-users.xml有問題,需修改成類似以下的內容:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user name="管理者名稱" password="管理者密碼" roles="admin,manager" />
</tomcat-users>

星期二, 10月 21, 2008

某些測試在特定機器上老是出現假警報怎麼辦

在指定機器上關掉該假警報測試

[Test]
public void Test(){

if (Environment.MachineName.ToUpper() == "BAD MACHINE")
    Assert.Ignore("this test caused false alarms on BAD MACHINE");

}

星期三, 4月 16, 2008

限制TRAC report中出現的ticket的時間

changetime - strftime('%s','2008-04-01 02:34:56')

星期五, 4月 11, 2008

使用Microsoft Virtual PC 2007 來輔助測試安裝檔

準備工作

  1. 使用MS Virtual PC安裝一個乾淨的Windows XP
  2. Install Virtual Machine Additions
  3. 在設定中開啟"Enable Undo Disks"。(為了還原硬碟狀態)
  4. 在設定中指定一個Shared Folder。 (為了複製程式到Virtual Machine中)
  5. 複製一些需要的安裝工具到Shared Folder,安裝這些工具到Virtual Machine中。
  6. 確認一切無誤後,關閉virtual machine,選擇"Turn Off and Save Changes"。記得勾選"Commit Changes to the Virtual Hard Disk"。

測試安裝檔

  1. 包裝安裝檔
  2. 開啟virtual machine。
  3. 複製安裝檔在Virtual Machine用的Shared Folder。
  4. 安裝安裝檔
  5. 要關閉Virtual Machine重新測試時,請選擇"Turn Off and Delete Changes"。表示要關掉virtual machine,但不要將硬碟的改變存回去。

注意:

  • Virtual PC能夠undo的只有硬碟的狀態,也就是所謂的"changes"
  • 至於"state"則只能凍結目前CPU, Ram的狀態,下次重開virtual machine時,會回到上次凍結的狀態。"state"目前測試的結果是不能undo的。

星期六, 3月 22, 2008

Nunit中避免category寫錯的小技巧

一般category的使用方式如下:

[Test, Category("IntegrationTest")]
void Test1(){.....}

----------------

一個避免寫錯與免記憶負擔的技巧:

建立一個namespace,內含一些class,用來表示所有測試的category:

namespace TestCategory
{
    class UnitTest : CategoryAttribute { }

    class IntegrationTest : CategoryAttribute { }
}

使用方式:

[Test, TestCategory.IntegrationTest]
void Test1(){.....}

星期六, 3月 01, 2008

vim簡易使用說明

  • 插入:i
  • 附加:a
  • 左右:hl
  • 上下:kj
  • 複製游標所在行:yy
  • 還原:u
  • 貼上:p
  • 不儲存直接離開::q!
  • 刪除游標所在字元:x
  • 刪除游標所在文字,然後進入插入模式:ciw