• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            concentrate on c/c++ related technology

            plan,refactor,daily-build, self-discipline,

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              37 Posts :: 1 Stories :: 12 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(9)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            1) 使用windows 頭文件
            API 頭文件允許32位和64位應用程序,包含了ANSI版本和UNICODE版本的聲明。
            如果安裝更新SDK的話,那么就可能有頭文件的多個版本在機器上面。
            一些函數的使用可能會通過使用條件編譯代碼依賴于某個特定版本的操作系統,為了編譯成功,你得定義比較合適的macro.頭文件使用宏來指示哪個版本系統支持編程元素。
            http://msdn2.microsoft.com/en-us/library/aa383745(VS.85).aspx
            2) 初始化類中的成員模板
            i) 使用非模板的方式
            template <typename Argtype>
            class Option
            {
            public:
            Option( void (*func_name)(Argtype), Argtype Arg1 )
              : MenuFunction<Argtype>( (*func_name)(Argtype), Argtype Arg1 )
             {
             } 
            private:
             MenuFunction<Argtype> function;
            };
            template <typename Argtype>
            Option<Argtype> makeOption(void (*func_name)(Argtype), Argtype Arg1 )
            {
            return Option<Argtype>(func_name, Arg1);
            }

            ii) 使用多態
            class Option
            {
            private:
            class FunctionBase
            {
            public:
            virtual ~FunctionBase() {}
            virtual void call() = 0;
            };

            template <typename Argtype>
            class Function : public FunctionBase
            {
            public:
            Function(void (*func_name)(Argtype), Argtype arg) :
            m_func(func_name, arg)
            {
            }
            void call()
            {
            m_func(); // or whatever
            }
            private:
            MenuFunction<Argtype> m_func;
            };

            public:
            template<typename Argtype> Option( void (*func_name)(Argtype), Argtype Arg1 )
            {
             // of course, this means you need a destructor, copy constructor, and assignment operator
            // function->call() would invoke the function
            function = new Function<Argtype>(func_name, Arg1);

            }  
            FunctionBase * function;
            };
            3 大小寫字符串比較大小(考慮區域性語言的問題)
            #include <iostream>
            #include<algorithm>
            #include<functional>
            #include<boost/bind.hpp>
            #include<string>
            #include<locale>

            struct CaseSensitiveString
            {
              public:
                   bool operator()(const std::string & lhs,const std::string & rhs)
                   {
                          std::string lhs_lower;
                          std::string rhs_lower;
                          std::transform(lhs.begin(),lhs.end(),std::back_inserter(lhs_lower),bind(std::tolower<char>,_1,_loc));
                          std::transform(rhs.begin(),rhs.end(),std::back_inserter(rhs_lower),bind(std::tolower<char>,_1,_loc));
                          return lhs_lower < rhs_lower;
                   }
                  CaseSensitiveString(const std::locale & loc):_loc(loc){}
                 private:
                   std::locale _loc;
            };
            詳細內容見:
            http://learningcppisfun.blogspot.com/2008/04/case-insensitive-string-comparison.html

            4 找不到msctf.h問題
            在用DX自帶的dxut做界面程序的時候,整個程序編制下來就出現了這個錯誤
            fatal error C1083: Cannot open include file: 'msctf.h': No such file or directory
            很詭異的,在dxsdk里面也找不到,想了很久,才發現自己沒有安裝platform sdk.因為win32程序之類的,最好都要安裝這些sdk之類的。具體的信息可以在這里得到
            http://www.gamedev.net/community/forums/topic.asp?topic_id=481358
            5 重載 , 覆蓋,隱藏
            重載與覆蓋有以下的區別:
            重載:同一類,相同函數名,不同函數參數,不一定要有virtual 關鍵字
            覆蓋:子類和父類,相同函數名,  相同函數參數,一定要有virtual 關鍵字
            隱藏:1)如果派生類的函數名與基類的函數名相同,但是參數不同,不論有無virtual關鍵字,基類的函數將被隱藏(與重載區別開來)
                        2)如果派生類的函數名與基類的函數名相同,并且參數相同,但是基類沒有virtual關鍵字,基類的函數將被隱藏(與覆蓋區別開來)
            6 快速加載文件
            在游戲里面,一般對從硬盤或者DVD加載資源要求比較高的,一般采用這樣的方法:

            for(int i = 0; < NumBlocks; i++)
            {
               // VirtualAlloc() creates storage that is page aligned
               // and so is disk sector aligned
               blocks[i] = static_cast<char *>
                  (VirtualAlloc(0, BlockSize, MEM_COMMIT, PAGE_READWRITE));

               ZeroMemory(&overlapped[i], sizeof(OVERLAPPED));
               overlapped[i].hEvent = CreateEvent(0, false, false, 0);
            }

            HANDLE hFile = CreateFile(FileName, GENERIC_READ, 0, 0, OPEN_EXISTING,
               FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING |
               FILE_FLAG_OVERLAPPED | FILE_FLAG_SEQUENTIAL_SCAN, 0);

            int iWriterPos = 0;
            int iReaderPos = 0;
            int iIOPos = 0;
            int iPos = 0;

            do
            {
               while(iWriterPos - iReaderPos != NumBlocks && iIOPos < FileSize)
               {
                  overlapped[iWriterPos & NumBlocksMask].Offset = iIOPos;

                  int iLeft = FileSize - iIOPos;
                  int iBytesToRead = iLeft > BlockSize ? BlockSize: iLeft;

                  const int iMaskedWriterPos = iWriterPos & NumBlocksMask;
                  ReadFile(hFile, blocks[iMaskedWriterPos], iBytesToRead, 0,
                     &overlapped[iMaskedWriterPos]);

                  iWriterPos++;
                  iIOPos += iBytesToRead;
               }

               const int iMaskedReaderPos = iReaderPos & NumBlocksMask;

               WaitForSingleObject(overlapped[iMaskedReaderPos].hEvent, INFINITE);

               int iLeft = FileSize - iPos;
               int iBytesToRead = iLeft > BlockSize ? BlockSize: iLeft;

               memcpy(&g_buffer[iPos], blocks[iMaskedReaderPos], iBytesToRead);

               iReaderPos++;
               iPos += iBytesToRead;

            }
            while(iPos < FileSize);

            CloseHandle(hFile);

            for(int i = 0; i < NumBlocks; i++)
            {
               VirtualFree(blocks[i], BlockSize, MEM_COMMIT);
               CloseHandle(overlapped[i].hEvent);
            }

            char* s vs char s[]
            char s1[] = "abcd";// 定義一個未指定長度的char型數組,并使用字符串"abcd"將之初始化
            char *s2  = "abcd";// 定義一個char型指針,并將其指向字符串"abcd",該字串位于靜態存儲區

            s1[0] = 'm';// 無編譯期、運行期錯誤
            s2[0] = 'm';// 無編譯器錯誤,但運行期試圖修改靜態內存,所以發生運行期錯誤
            char s*只是被賦予了一個指針,char s[]是在棧中重新開辟了空間,可以在程序中寫,而不引起程序崩潰。
            所以相比較而言,使用字符串數組要比字符指針要安全的多,要慎用char*s 和char s[].
            7 can not find MSVCR80.dll
            在安裝了vc2005之后,發現錯誤報告說MSVCR80.dll,以為又要重新安裝vc2005了,但是在網絡上面搜索到另外一個例子說,其實可以不用安裝vc2005,直接改變配置就好了,于是就有這個了:
            http://blogs.msdn.com/seshadripv/archive/2005/10/30/486985.aspx
            http://www.codeguru.com/forum/showthread.php?t=439964
            工程架構:
            新建一個空白的 solution.
            然后在新建的solution上面添加vcproject.
            并且也可以在子空白solution上面添加vcproject.

            1>        ]
            1>正在編譯資源...
            1>正在鏈接...
            1>LINK : warning LNK4075: 忽略“/INCREMENTAL”(由于“/OPT:ICF”規范)
            1>fatal error C1900: Il mismatch between 'P1' version '20060201' and 'P2' version '20050411'
            1>LINK : fatal error LNK1257: 代碼生成失敗
            1>生成日志保存在“file://e:\demo-work\LocalVersionTianJi\_out\DragoonApp\Release\BuildLog.htm”
            1>DragoonApp - 1 個錯誤,5382 個警告
            ========== 全部重新生成: 0 已成功, 1 已失敗, 0 已跳過 ==========

            http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1512436&SiteID=1
            http://forum.codecall.net/c-c/6244-fatal-error-c1900-il-mismatch-between-p1-version-20060201-p2-version-2005-a.html
            http://www.codeguru.com/forum/archive/index.php/t-144030.html

            timeGetTime: 頭文件 mmsystem.h,庫文件 winmm.lib
            獲得當前窗口的句柄。
            HWND hwnd=::GetForegroundWindow();
            hwnd就保存了當前系統的最頂層窗口的句柄
            GetSafehWnd 取你程序所在窗口類的句柄
            GetActiveWindow 取當前活動窗口句柄
            AfxGetMainWnd 取主窗口句柄
            GetForegroundWindow 取前臺窗口句柄
            FindWindow
            EnumWindow
            改變窗口屬性:
            SetWindowLong
            SetClassLong.

            strcpy strncpy memcpy.
            strcpy:按照msdn的話說是:No overflow checking is performed when strings are copied or appended,即沒有嚴格的長度檢查,所以即使是溢出也無法被檢查出來,以及The behavior of strcpy is undefined if the source and destination strings overlap.

            strncpy:雖然加入了size這個來限制,但是這個size小于或者等于字符長度的話,那么該信息是不被加上字符串結束符的.并且仍舊存在跟strcpy一樣的問題, The behavior of strncpy is undefined if the source and destination strings overlap

            memcpy:具體的用法跟strncpy類似,也加入了size的成分在里面,但是卻比strncpy好用得多.

            If the source and destination overlap, this function does not ensure that the original source characters in the overlapping region are copied before being overwritten.

            Use memmove to handle overlapping regions.

            顯然它能夠處理重疊的部分,安全可靠.
            并且:

            The first argument, dest, must be large enough to hold count characters of src; otherwise, a buffer overrun can occur.


            上次遇到的問題是我將一串漢字用strcpy來拷貝到緩沖里面,結果發現出現了亂碼.
            strncpy, strcpy還是建議少用,換用memcpy+memmove(如果存在重疊的情況)吧:)
            未完待續.

            posted on 2008-05-12 10:01 jolley 閱讀(2753) 評論(1)  編輯 收藏 引用

            Feedback

            # re: 大雜燴 2012-04-30 21:12 陳明澤
            請教:fatal error LNK1257: 代碼生成失敗如何解決呢?  回復  更多評論
              

            伊人久久精品线影院| 伊人久久大香线焦AV综合影院| 91麻豆国产精品91久久久| 一本一道久久精品综合| 精品一区二区久久| 国产精品久久久久久影院 | 亚洲狠狠婷婷综合久久蜜芽| 久久中文精品无码中文字幕| 武侠古典久久婷婷狼人伊人| 久久伊人亚洲AV无码网站| 久久精品女人天堂AV麻| 青草久久久国产线免观| 久久AV无码精品人妻糸列| 一本色综合网久久| 久久久久久夜精品精品免费啦| 成人久久精品一区二区三区| 嫩草影院久久99| 伊人久久无码精品中文字幕| 一本一道久久综合狠狠老| 99久久无码一区人妻a黑| 色综合久久中文综合网| 老司机午夜网站国内精品久久久久久久久| 久久久久亚洲av毛片大| 亚洲综合精品香蕉久久网| 国产综合久久久久久鬼色| 综合人妻久久一区二区精品| 久久亚洲精品无码aⅴ大香| 久久99精品久久只有精品 | 日韩人妻无码精品久久免费一| 久久影院综合精品| 国内精品久久久久久久久 | 久久99精品久久久久久久久久| 久久99国产亚洲高清观看首页| 久久久精品久久久久久| 精品一二三区久久aaa片| 青草影院天堂男人久久| 狠狠色丁香婷婷久久综合| 青青草原综合久久| 性做久久久久久久| 伊人久久大香线蕉精品不卡| 93精91精品国产综合久久香蕉|