跳到主要內容

發表文章

目前顯示的是 2010的文章

What Is A Kernel Module?

引述自  The Linux Kernel Module Programming Guide 原文 : What exactly is a kernel module? Modules are pieces of code that can be loaded and unloaded into the kernel upon demand. They extend the functionality of the kernel without the need to reboot the system. For example, one type of module is the device driver, which allows the kernel to access hardware connected to the system. Without modules, we would have to build monolithic kernels and add new functionality directly into the kernel image. Besides having larger kernels, this has the disadvantage of requiring us to rebuild and reboot the kernel every time we want new functionality.   自譯 :         Kernel module 其實就是一段程式碼,根據需求(service),module 可以載入 kernel 裡,或是從 kernel 中卸除,並不需要重新啟動作業系統(Linux),module 擴展了 kernel 的功能。         舉例,假設有一個 module 是屬於 device driver 類型,那麼這個 module 在 kernel 中可以直接存取與系統連線的硬體;相對地,若是 kernel 沒有提供 module 這樣的機制,我們必須在建置一個單體核心(ex. Linux)時,選擇直接加入新的功能到 kernel 裡,除此之外,kern...

在程式裡嵌入二進位檔(VC++)

Import: 1. 切換到 Resource Tab 2. (VC6)在專案名稱上按下 mouse 右鍵,選擇 "Import..." 2. (VC2005)在專案名稱上按下 mouse 右鍵,選擇 Add,再選擇 Resource,或是直接選擇 rc 按下右鍵,選擇 Add Resource,點下 "Import..." 3. 點選所要嵌入的檔案後,Resource Type 填入 RCDATA,存檔/編譯即完成。 解開: int ExtractFile(int nResourceId, LPCTSTR lpType, LPCTSTR strOutputName) {     DWORD dwWritten = 0;     HRSRC hRsrc = FindResource(NULL, MAKEINTRESOURCE(nResourceId), lpType);     if(NULL == hRsrc)     {         OutputDebugString(_T("FindResource fail !!!"));         return 1;     }     DWORD dwImageSize = SizeofResource(NULL, hRsrc);     if(dwImageSize == 0)     {         OutputDebugString(_T("FSize is 0 !!!"));         return 1;     }     HGLOBAL hBinImage = LoadResource(NU...

C-style String & C++ String & CString

C-style string to C++ string C-style string to CString char str[] = "Hello World"; string str = string(str); char str[] = "Hello World"; CString cs = CString(str); C++ string to C-style string CString to C-style string string str = string("Hello World"); char *ptr = str.c_str(); CString str = CString("Hello World"); char *ptr = str.GetBuffer(str.GetLength()); str.ReleaseBuffer();

在視窗中繪圖

這裡只簡單建立幾個要點,有時間再補完整一點。 Windows 中負責圖形輸出的部份為圖形裝置介面(Graphic Device Interface, GDI),GDI 使用簡單 的機制來確保每個在視窗中執行的程式都根據此規則運作。而這個機制就是 DC(Device Context)。 DC 是一種 Windows 的資料結構,它含有一個描述所有 GDI 需要知道有關顯示平面資的欄位,而該 顯示平面則關聯到實際的輸出裝置,在螢幕上畫出任何東西之前,Windows 程式必須透過 GDI 來取 得 DC 的 handle。 DC 讓 GDI 能夠成為一個「與裝置無關」的工具,只要給予程式一個 DC,GDI 函式就可以在各種不 同的輸出裝置中繪圖。 CWnd::GetDC 它會傳回一個指向 Windows DC 的 CDC 物件指標,由 CWnd::GetDC 產生的 DC 必須在 繪圖完成後由 CWnd::ReleaseDC 來釋放;在 OnPaint 處理函式中,就必須用 CWnd::BeginPaint 及 CWnd::EndPaint 來取 GetDC 及 ReleaseDC,以確保對 WM_PAINT 做出適當的處理。 ex. CDC *pDC = GetDC(); // do something ReleaseDC(pDC); PAINTSTRUCT ps; CDC *pDC = BeginPaint(&ps); // do something EndPaint(&ps); 特殊目的之 DC 類別 類別名稱 內容描述 CPaintDC 可在視窗中的client area繪圖(僅用在 OnPaint 訊息處理函式中) CClientDC 可在視窗中 client area 繪圖(可用在除了 OnPaint 外的任何地方) CWindowDC 可在視窗中的任何地方(包含 non-client area)繪圖 CMetaFileDC 可在 GDI metafile 中繪圖 CPaintDC Class It performs a CWnd::BeginPaint at construction time and CWnd::EndPaint...

Hello, MFC

一個典型的 MFC 應用程式並沒有 WinMain 函式,也不會呼叫 RegisterClass 或是 CreateWindow 這兩個函式。 MFC 是一組由 Microsoft 所提供的 C++ 類別函式庫,它將 Windows API 用物件導向的方式包裝起來。 MFC 以全域函式的形式提供了一組 API,它們的名稱都以 Afx 開頭。 下面是書中 MFC 的範例應用程式碼 /////////////////////////////////////////// // Hello.h class CMyApp : public CWinApp { public:     virtual BOOL InitInstance(); }; class CMainWindow : public CFrameWnd { public:     CMainWindow();     protected:     afx_msg void OnPaint();     DECLARE_MESSAGE_MAP() }; /////////////////////////////////////////// // Hello.cpp #include #include "Hello.h" CMyApp myApp; // CMyApp member functions BOOL CMyApp::InitInstance() {     m_pMainWnd = new CMainWindow;     m_pMainWnd->ShowWindow(m_nCmdShow);     m_pMainWnd->UpdateWindow();     return TRUE; } // CMainWindow message map and member functions BEGIN_MESSAGE_MAP(CMainWin...

windows programming for GUI

在 windows 裡,所有控制項幾乎每一個都是從 WNDCLASS Structure設定好結構,再用 CreateWindow 建立起相對的 window / control,所以從另一個角度來看,每一個控制項(control),都可以看成是 wnidow,以下這個網站提供了一個不使用 MFC,單純用 win32 API 來做教學。 http://zetcode.com/tutorials/winapi/

UAC VC2005

The assembly identity The name The type The description The attributes in the requestedExecutionLevel Application Manifest Schema: ========================================================== Windows Vista only <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="IsUserAdmin" type="win32"/> <description>Description of your application</description> <!-- Identify the application security requirements. --> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges> <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> </requestedPrivileges...

Static 修飾

用於: 1. Member function (method of Class):     函式裡,包含引數,不能用到 non-static 變數及函式。     沒有 this 指標、函式不能宣告為 const 及 virtual。     其宣告時前面加上 static,若在 Class 作用區域外實作(定義),則不需再加上 static 修飾字,     其於用法限制同一般成員函式。 2. Member variable     只能在 Class 作用區域內宣告,若要給定初值,則需到 Class 作用區域外定義,也是不用     再加上 static 修飾字。 另外整數型 const static 成員較特別,可以直接在 Class 作用區域內給定初值。 static 變數,若只是宣告,且未存取它時,可不用指定初值,compiler 及 linker 可以順利通過,反之,則必需給定一個初值,否則會 linker error。 static variable initialization example: [data type] [class name]:: [static variable name] = [value];

Pointers 指標

對於 const 修飾詞 1. Pointers to const [point to const object of pointers] (指向 const 物件的指標)     // ptr is nonconst pointer and ptr point to const object of double type.     const double *ptr;         ptr 無法知道它所指向的物件是否真的為 const,所以它將它所指向的物件一律視為 const。         這裡有一段話, pointers to const 所指物件並未保證一定不被改變 。     事實上我們可以透過 const pointer 賦予給 nonconst pointer,不過若指向的物件是 const     則一定不會被改變。 2. Const pointers [const of pointers] (本身為 const 的指標)     // ptr is const pointer and ptr point to nonconst object of double type.     double const *ptr;  // 等同 double *const ptr;         如同其它 const 變數一樣,在建立 const pointer 時就該把它初始化。

快速鍵

Eclipse 選取變大寫   [Ctrl] + [Shift] + [x] 選取變小寫   [Ctrl] + [Shift] + [y] 刪除一整行 [Ctrl] + [d] GOTO [Ctrl] + [L] Visual Studio C++ 選取變大寫   [Ctrl] + [Shift] + [u] 選取變小寫   [Ctrl] + [u] 刪除一整行 [Ctrl] + [L]

mount iso file mount -o loop -t iso9660 filename.iso /media/iso mount windows shared folder mount -t cifs //172.20.20.39/temp -o username=linux,password=linux /mnt/ntserver smbmount //172.20.20.39/temp /mnt/ntserver -o username=linux,password=linux 計算目錄大小 du -s directory compare directory diff -r dir1 dir2 PKG_CONFIG_PATH 變數,可自行設定非預設的 *.pc 檔所在路徑。 Update ld.so.cache command /sbin/ldconfig /etc/ld.so.conf 可將非預設的 library 路徑加入此檔,或是改變 LD_LIBRARY_PATH 變數

宣告(Declarations) 和定義(Definitions)

宣告:            1. 可以有 N 個重覆宣告式            2. 讓 Compiler 知道資料型態及變數型態            3. 加上 extern 修飾可以變成單純的宣告式 定義:            1. 只能定義一次            2. 為該變數配置足夠的儲存空間            3. 只要帶了初值,它就是定義式 extern int i;  // 宣告 i,但不定義 i int i;             // 宣告並定義 i extern double pi = 3.1415926; // 定義式 double pi = 3.1415926;            // 也是定義式,且編譯出錯,重覆出現定義式 標頭檔放的是宣告而非定義

win32 sample code

#ifndef UNICODE #define UNICODE #endif #include <windows.h> #include <tchar.h> LRESULT CALLBACK MainWindowProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,                    LPSTR lpCmdLine, int nCmdShow) {     // register windows class     WNDCLASSEX wndclassex = {NULL};     wndclassex.cbSize = sizeof(WNDCLASSEX);     wndclassex.style = CS_HREDRAW | CS_VREDRAW;     wndclassex.lpfnWndProc = MainWindowProc;     //wndclassex.cbClsExtra = 0;     //wndclassex.cbWndExtra = 0;     wndclassex.hInstance = hInstance;     wndclassex.hIcon = LoadIcon(NULL, IDI_APPLICATION);     wndclassex.hCursor = LoadCursor(NULL,IDC_ARROW);     wndclassex.hbrBackground = (HBRUS...