LearnHouse

Archive for the '程式&軟體' Category

又挑戰了一個不可能

感動的都快哭了!!! 聲音的串流竟然讓我給兜出來了~~~
哀~不過說實在的這該開心還是該可悲
研究生應該研究發現新結果而感動
我卻是因為coding出來而開心
有空再來詳述我怎麼包JM codec和faad的opensource code

準備材料:h.264 codecAAC decoder、Visual Studio 2005、MFC、C/C++
製造流程:
aac的adts header是透過ff f1 68 89區分
h.264的每張frame透過00 00 00 01區分

posted by yuchin in 程式&軟體 and have No Comments

[C/C++]MFC ComboBox 使用方法

Step1 首先當然是要在工具箱拉Combo Box出來
在Data屬性中可以放入你想要放的值或資料,只要用分號『;』隔開,例如:10;20;30;40

Step2 再來設定變數
CComboBox *m_sTimeout;  //宣告Combo Box物件位址變數
CString strCBTimeout; //宣告所選的值或資料變數
int SetTimeout = 0;    //宣告轉換字串成整數值變數

Step3取得Combo Box物件資料
m_sTimeout = (CComboBox *)GetDlgItem(IDC_COMBOTIMEOUT);

if(m_sTimeout->GetCurSel() >=0)  //當有取到值的時候執行會回傳選取的編號
{
m_sTimeout->GetLBText(m_sTimeout->GetCurSel(), strCBTimeout); //剛選取的編號值放入字串
SetTimeout = atoi(strCBTimeout); //將選取的字串值轉成整數值
}
else
SetTimeout = 8000;

可參考下面解說http://www.codersource.net/mfc/mfc-tutorials/ccombobox-example.aspx

CComboBox Example

Minimize

Combo box controls are space savers. Wherever there is no need for a multi-select from a list of items, combo box is a good choice in such places. This article " CComboBox Example" explains how to use the MFC CComboBox class for manipulation of a list of strings.

CComboBox Example - Initializing a Combo Box:

It is assumed that the readers of the sample have already created a dialog box (either in a dialog based application or SDI/MDI application) and placed a combo box control from the controls toolbox on the Resource Editor.

After placing the combo box control on the dialog box, open the class wizard by pressing Ctrl + W keys or Menu --> View --> ClassWizard. In the Member Variables tab, Add a Variable for the CComboBox class. This CComboBox example assumes that the variable name is,

CComboBox  m_cbExample;

This m_cbExample will be used further in our CComboBox example MFC code.

CComboBox Example - Adding Items to a Combo Box:

The function AddString is used for adding items to a combo box. If there is a constant set of data, these values can also be added in the Resource Editor itself. The Combo Box control properties dialog has a tab for adding data. Otherwise the data can be added as follows.

m_cbExample.AddString("StringData1");
m_cbExample.AddString("StringData2");
m_cbExample.AddString("StringData3");

CComboBox Example - Retrieving Items from a Combo Box:

Usually a requirement for retrieving items from the combo box will arise from selecting the data. This article also assumes the same. Now the data selected in a combo box needs to be retrieved.

To do this, the first step is to find out the index of the selected item inside the combo box control. Then the item at the corresponding position needs to be pulled out as follows.

int nIndex = m_cbExample.GetCurSel();
CString strCBText;
m_cbExample.GetLBText( nIndex, strCBText);

In the above CComboBox example code, the value will be retrieved and stored in strCBText variable. There is another overloaded version for GetLBText. But the version which uses CString is the easiest one.

CComboBox Example - Finding Items inside a Combo Box:

This kind of Find operations on a Combo box will most probably be useful in programs that dynamically modify the values in a combo box. The function FindStringExact is used to find the exact string match inside a combo box.

int nIndex = m_cbExample.FindStringExact(0, "Value to be found");

The string position inside the combo box control is the return value. It returns CB_ERR if it was unsuccessful in finding the string.

CComboBox Example - Deleting Items from a Combo Box:

This operation can be done by using the CCombobox member function DeleteString. This function needs the index of the item inside the combo box.

m_cbExample.DeleteString(nIndex);

posted by yuchin in 程式&軟體 and have No Comments

[C/C++]C語言新手十誡(The Ten Commandments for Newbie C Programmers)[轉載]

(1) 本篇旨在提醒新手,避免初學常犯的錯誤(其實老手也常犯:-Q)。
但不能取代完整的學習,請自己好好研讀一兩本 C 語言的好書,
並多多實作練習。

(2) 強烈建議新手先看過此文再發問,你的問題極可能此文已經提出並
解答了。

(3) 以下所舉的錯誤例子如果在你的電腦上印出和正確例子相同的結果,
那只是不足為恃的一時僥倖。

(4) 不守十誡者,輕則執行結果的輸出數據錯誤,或是程式當掉,重則
引爆核彈、毀滅地球(如果你的 C 程式是用來控制核彈發射器的話)。

Read more...

posted by yuchin in 程式&軟體 and have No Comments

[C/C++]Native Language 上實作RTP protocol

一直以來都知道RTP 這個protocol,但從沒去思考他能拿來做什麼

RTP他使用UDP來傳送資料,同時他擁有順序編號和時間戳記

也就是說你可以不用去管收到封包的順序,該協定會自動幫你做好

我已經用自己的方式,利用hash table的方式來解決接收端收到封包順序不一樣的問題

今天突發起想找找看有沒有RTP release出來的source code,找到一個不錯的lib,JRTPLIB

他支援多種平台上的開發,且提供sample code

Currently, the library is known to work on the following platforms:

  • GNU/Linux
  • MS-Windows (both Win32 and WinCE)
  • Solaris
  • posted by yuchin in 程式&軟體 and have No Comments

    TCPMP rebuild

    搞了好久 PDA上的h.264的撥放還是很LAG

    所以又跑回用TCPMP自己重建測試一下

    先從官方下載source code http://picard.exceed.hu/tcpmp/test/

    編譯後只要把副檔名為plg與common.dll丟到PDA上

    還需放置語言檔lang_en.txt或lang_cht.txt,否則會出現Language files(*.txt,*.tgz) are missing!

    也須放置lang_std.txt,否則會出現ERR_FFFFFFF3或FILE protocol not supported!或FILE 通訊協定不支援!

     

     

    posted by yuchin in 程式&軟體 and have Comment (1)

    [C/C++]free釋放記憶體函試的重要觀念

    這一篇其實沒什麼!! 只是要告訴大家一個free的重要觀念

    也可能我是新手,才會遇到這種問題

    因為我在這邊卡了很久,不知道為什麼資料透過socket傳送出去後,資料就進不來了

    我們知道可以用佇列來儲存資料,通常會用malloc來產生每一個節點

    並把前端節點與後端節點指標指向它(如果不知道佇列是什麼的就直接跳綠色的字看)

    但當資料只剩下一個的時候,我們會用free的方式將最後一個節點記憶體釋放

    但這時的後端指向的記憶體並沒有隨之釋放

    因為free函數僅僅是告訴操作系統,這一塊記憶體被釋放了,可以用來作其它用途

    但是,由於你沒有重新對這塊記憶體進行寫入,所以記憶體中的變量數值並沒有發生變化。

    所以後端節點指向的值不變,恆會一直保有一個節點

    因此最好的方式記得當最後一個節點free之後,並把後端節點也指向NULL

    posted by yuchin in 程式&軟體 and have No Comments

    [C/C++]整數轉字串 不能用itoa ??

    神奇了!!為什麼不能用itoa的函數呢??明明已經include stdio.h和stdlib.h

    但還是找不到定義!! 不知道是否是因為WinCE上不提供這個API,只提供字串轉整數的atoi

    由於我想把整數的值寫入文字檔,勢必要把值轉成字串才能寫入

    google了一下,發現竟然有人自己寫itoa,不過我已經忘了我在哪看到的了

    下面是itoa的function

    void itoa(int num, char str[])
    {
        int sign = num,i = 0,j = 0;
        char temp[11];
       
        if(sign<0)//判斷是否是一個負數
        {
            num = -num;
        }
       
        do
        {
            temp[i] = num%10+'0';
            num/=10;
            i++;

        }while(num>0);

        if(sign<0)
        {
            temp[i++] = '-';
        }

        temp[i] = '';
        i--;
       
        while(i>=0)
        {
            str[j] = temp[i];
            j++;
            i--;
        }
       
        str[j] = '';
    }

    2009.4.7更新

    其實WinCE上有替代的function,用法一樣

    _itoa(tempint, tempchar, 16);


    From C++ library:
    Parameters:

    value:
    Number to be converted

    string:
    String result

    radix:
    Base of value; must be in the range 2 10 16

     

     

    posted by yuchin in 程式&軟體 and have No Comments

    [Java/WinAPI]Java和Windows的執行緒(Thread)

    可能兜系統兜慣了有時候被問到很基本的問題,都會變得很不確定

    今天大學的同學問我要怎樣一台主機模擬多個主機同時在做事情 然後要分配給不同的系統去做事

    我直覺想它應該是想要說執行緒吧,可是他說他會在執行緒使用while loop

    他不是很確定是否可以這樣做,我那時候想執行緒應該就是用來解決類似這樣的問題吧?

    由於我同學是使用java,因此我就寫了一個小小的程式來測試

    ThreadTest.java

    public class ThreadTest{

        public static void main(String[] args) {
            ThreadRun r1 = new ThreadRun();
            ThreadRun r2 = new ThreadRun();
           
            Thread t1 = new Thread(r1, "執行緒A");
            Thread t2 = new Thread(r2, "執行緒B");
            t1.start();
            t2.start();
        }
    }

    class ThreadRun implements Runnable{
       
        @Override
        public void run() {
            String ThreadID;
            int i = 1;
           
            while(true){           
                ThreadID = Thread.currentThread().getName()+"迴圈執行第"+i+"次!!";
                System.out.println(ThreadID);
               
                i++;
            }       
        }

    由於我是寫C/C++的,所以又用C/C++寫個小測試

    #include <windows.h>

    int _tmain(int argc, _TCHAR* argv[])
    {
        DWORD ThreadId;
        HANDLE Thread;
     
        //啟動多個執行緒
        Thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread1, NULL, 0, &ThreadId);
        Thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread2, NULL, 0, &ThreadId);

        void thread1()
       {
          while(true)
          printf("執行緒A\n");
       }
        void thread2()
       {
          while(true)
          printf("執行緒B\n");
       }

    }

    透過以上就能看出執行緒A與B是互相並行執行的,會一起爭取CPU的可用資源

    有空再來寫一篇如何用CreateThread帶入多個參數。

    posted by yuchin in 程式&軟體 and have No Comments

    [WinCE]EVC to VS2005

    在上一篇大費周章的好不容易已經解決可以編譯問題

    但將編譯完後的檔案丟到手機去,卻發現根本不能使用Cry

    挖勒~現在是怎樣,覺得我的時間很多嗎Yell

    只好改把專案丟到Visual Studio 2005去編譯看看

    果然跟預期的一樣,一堆錯誤和警告..................

    原來MOBIL5.0開始,EVC4開發的程式就無法進行DEBUG了

    而必須使用VS.NET2005中的VC++來實現

    透過VS2005開啟專案Test.vcw,會跳出要你轉換成目前的VC++的專案格式

    選擇是後就可以開始編譯了,首先會先看到第一個錯誤Please use the /MD switch for _AFXDLL builds

    專案->屬性->組態屬性->C/C++->程式碼產生->執行階段程式庫->多執行緒偵錯(/MTd)改成多執行緒偵錯DLL(/MDd)

    再編譯一次,錯誤就不一樣了,從本來的一個error變成很多個io的錯誤second C linkage of overloaded function '_setmode' not allowed

    由於都沒有調用到_setmode這個函式原型,因此我乾脆就把它註解掉,讓只剩錯誤cannot open include file 'wceres.rc'

    這個一樣把#include "wceres.rc"註解掉,但卻會出現無法解析的外部符號 wWinMain 在函式 wWinMainCRTStartup 中被參考

    一樣到專案->屬性,這次去連結器的進階將進入點wWinMainCRTStartup改成WinMainCRTStartup 

    再編譯一次會出現無法啟動程式'%CSIDL_PROGRAM_FILES%Test\Test.exe'

    老樣子,又回到專案->屬性->組態屬性->一般其中MFC的使用從使用MFC的共用DLL改成使用MFC的靜態程式庫

    這樣就OK啦~~~~大功告成   可惡花我這麼多時間

    如果還有其他的問題可以參考這篇http://www.wretch.cc/blog/awaysu/23455768

    posted by yuchin in 程式&軟體 and have Comments (2)

    [WinCE]編譯H263視訊原始碼

    由於研究的工具一直換來換去的,現在改要追蹤H263的程式碼了

    這個H263的Source Code是從大陸的網站找到的,可以從我的部落格下載

    原碼提供Server端PC上的H263 Encode和WinCE上的H263 Decode

    剛剛好符合我研究要的所有需求,真是大大的簡化開發時間

    只是老闆最近又看上嵌入式的版子,希望與廠商合作

    底層的部份交給廠商來完成,上層的部分由我們來做應用

    古話有說老師和學長的話不會錯,做就對了,所以我兩個就都來測試看看

    一開始玩就碰壁了 = =" 那整個專案WinCE的部份是用EVC撰寫出來的

    所以我只好去找eMbedded Visual C++ 4.0的MicroSoft官方載點

    本來以為應該是免費的,但安裝竟然要序號 Sealed

    因此就隨意的上網找了一段序號來用BKV3P-2YKCK-F8V3H-XJR3Y-K8YWY

    安裝完後解決無法啟動模擬器的錯誤後就開始編繹了

    註:無法啟動模擬器只要根據提示就能解決

    編譯的時候出現CVTRES : fatal error CVT1102: out of memory; 41 bytes required

    只要將Microsoft eMbedded C++ 4.0\Common\EVC\Bin中的CVTRES.EXE
    複製到
    Microsoft eMbedded C++  4.0\EVC\wce400\bin
    Microsoft eMbedded C++  4.0\EVC\wce410\bin
    Microsoft eMbedded C++  4.0\EVC\wce420\bin
    Microsoft eMbedded C++  4.0\EVC\wce500\bin
    中即可解决上述問題。

    posted by yuchin in 程式&軟體 and have No Comments