Execute Batch file in Silent mode (no cmd window) / 以無 dos 命令列視窗執行 .bat

June 21st, 2010 Phanix

今天無意中看到正解,沒想到超簡單,不必用以前的蠢方法啦!

----- without a window-----
@echo off
start /B Myapp.exe

---- minimized ----
@echo off
start /MIN Myapp.exe

C# ActiveX Development, Deploying and Web Execution

May 30th, 2010 Phanix

最近在用 C# 開發 ActiveX 來擺在網頁上面執行,查了一些資料之後終於做出來了,來整理一下放在下面。

Read the rest of this entry / 繼續閱讀 »

Drag a virtual file from C# winform to Explorer and other applications

May 24th, 2010 Phanix

從 c# winform 上拖曳一個 virtual file (比方說一個 label)到 explorer 或其他程式(例如 ultraedit, photoshop)開啟

Read the rest of this entry / 繼續閱讀 »

Calling Managed .NET C# COM Objects from Unmanaged C++

February 8th, 2010 Phanix

從 VC++ 中呼叫 C# 所寫的 COM 物件,主要的可以分成三項需要注意的事情。

1. 怎麼讓 C# class library 在編譯出 DLL 的同時同時產生 COM 物件
2. 怎麼讓系統認得這個這個 COM 物件
3. 怎麼在 VC++ 中用這個 COM 物件

這個網頁裡頭寫得非常清楚,同時還有範例下載。

讓 .Net WebService 可以在 remote 機器上用瀏覽器執行

January 21st, 2010 Phanix

Invoke a .Net WebService on a remote browser.

方法其實很簡單,打開 webservice 的目錄裡頭的 web.config 加入下面這些就可以了 :D

<configuration>
    <system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    </system.web>
</configuration>

[C#] Threading with Parameters / 帶參數的執行緒

December 10th, 2009 Phanix

主要有兩種方式,第一種為使用 ParameterizedThreadStart,但是這不是一個安全的方式。第二種方法是將要交給執行緒執行的方法與參數封裝到類別裡頭去,建立該類別的 Instance 之後就可以交給執行緒去執行,以下為 sample code… (另外要注意的是 Threading.Join() 的使用)

using System;
using System.Threading;

//ThreadWithState 類別裡包含執行任務的方法
public class ThreadWithState {
    //要用到的屬性,也就是我們要傳遞的參數
    private string boilerplate;
    private int value;

    //包含參數的 Constructor
    public ThreadWithState(string text, int number)
    {
        boilerplate = text;
        value = number;
    }

    //要丟給執行緒執行的方法,無 return value 就是為了能讓ThreadStart來呼叫
    public void ThreadProc()
    {
        //這裡就是要執行的任務, 只顯示一下傳入的參數
         Console.WriteLine(boilerplate, value);
    }
}

//Main entrance
public class Example {
    public static void Main()
    {
        //實例化ThreadWithState類別,為執行緒提供參數
        ThreadWithState tws = new ThreadWithState(
            "This report displays the number {0}.", 42);

        // 創建執行任務的執行緒,並執行
        Thread t = new Thread(new ThreadStart(tws.ThreadProc));
        t.Start();
        Console.WriteLine("Main thread does some work, then waits.");
        t.Join();
        Console.WriteLine(
            "Independent task has completed; main thread ends.");
    }
}

C# Wrapping Library of Google AJAX Search API

November 26th, 2009 Phanix

以前在程式裡頭用到 Google Search 的機會比較少,所以都是直接把 search term 丟給 Google search,然後 parsing 回傳 page 這樣土法硬幹的方式。

不過最近使用量比較大,所以就乾脆來找 Google Search API ,沒想到 Google 說現在一般的 Search API 已經不接受申請了,比較建議使用 AJAX API。

看了一下說明文件,對於要寫網頁程式的話確實蠻方便的,不過對於要寫 Windows / Console 程式來說就不是這麼好用… 「該不會要自己來寫一個 library 把這個 AJAX Search API 包起來吧?」

正當腦子裡才冒出這個念頭的時候,另外一個聲音響起,「不對,這事情一定也有人想過,然後很好心地做出來了」… 果不其然,找了一下就找到了 http://gapidotnet.codeplex.com/ 這個 wrapping api… 真是太棒了… XD

C# Make a window program in system tray, hidden in task bar, and hidden in alt-tab list

September 18th, 2009 Phanix

讓視窗程式只在 system tray 中顯示, 不會出現在工作列(task bar)中, 也不會出現在 alt-tab 清單裡頭

Read the rest of this entry / 繼續閱讀 »

C# mount / unmount UNC (network folder / drive) 連結網路磁碟機

September 8th, 2009 Phanix

有些時候為了 security 問題或者想要詳細紀錄使用者存取網路磁碟機或目錄中資料的情況, 所以會另外建立帳號並透過程式來存取網路磁碟機, 而不讓使用者直接用他的帳號密碼來存取, 這時候就需要讓程式可以建立網路磁碟機與中斷連線.

我自己比較喜歡第一個方式, 相對來說簡單許多.
Read the rest of this entry / 繼續閱讀 »

Visual Studio .Net 設定 DLL / EXE 版本編號

August 12th, 2009 Phanix

in Properties\AssemblyInfo.cs

[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]