• <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++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              37 Posts :: 1 Stories :: 12 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(9)

            我參與的團(tuán)隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            1) 使用windows 頭文件
            API 頭文件允許32位和64位應(yīng)用程序,包含了ANSI版本和UNICODE版本的聲明。
            如果安裝更新SDK的話,那么就可能有頭文件的多個版本在機(jī)器上面。
            一些函數(shù)的使用可能會通過使用條件編譯代碼依賴于某個特定版本的操作系統(tǒng),為了編譯成功,你得定義比較合適的macro.頭文件使用宏來指示哪個版本系統(tǒng)支持編程元素。
            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) 使用多態(tài)
            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 大小寫字符串比較大小(考慮區(qū)域性語言的問題)
            #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;
            };
            詳細(xì)內(nèi)容見:
            http://learningcppisfun.blogspot.com/2008/04/case-insensitive-string-comparison.html

            4 找不到msctf.h問題
            在用DX自帶的dxut做界面程序的時候,整個程序編制下來就出現(xiàn)了這個錯誤
            fatal error C1083: Cannot open include file: 'msctf.h': No such file or directory
            很詭異的,在dxsdk里面也找不到,想了很久,才發(fā)現(xiàn)自己沒有安裝platform sdk.因為win32程序之類的,最好都要安裝這些sdk之類的。具體的信息可以在這里得到
            http://www.gamedev.net/community/forums/topic.asp?topic_id=481358
            5 重載 , 覆蓋,隱藏
            重載與覆蓋有以下的區(qū)別:
            重載:同一類,相同函數(shù)名,不同函數(shù)參數(shù),不一定要有virtual 關(guān)鍵字
            覆蓋:子類和父類,相同函數(shù)名,  相同函數(shù)參數(shù),一定要有virtual 關(guān)鍵字
            隱藏:1)如果派生類的函數(shù)名與基類的函數(shù)名相同,但是參數(shù)不同,不論有無virtual關(guān)鍵字,基類的函數(shù)將被隱藏(與重載區(qū)別開來)
                        2)如果派生類的函數(shù)名與基類的函數(shù)名相同,并且參數(shù)相同,但是基類沒有virtual關(guān)鍵字,基類的函數(shù)將被隱藏(與覆蓋區(qū)別開來)
            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型數(shù)組,并使用字符串"abcd"將之初始化
            char *s2  = "abcd";// 定義一個char型指針,并將其指向字符串"abcd",該字串位于靜態(tài)存儲區(qū)

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

            1>        ]
            1>正在編譯資源...
            1>正在鏈接...
            1>LINK : warning LNK4075: 忽略“/INCREMENTAL”(由于“/OPT:ICF”規(guī)范)
            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
            獲得當(dāng)前窗口的句柄。
            HWND hwnd=::GetForegroundWindow();
            hwnd就保存了當(dāng)前系統(tǒng)的最頂層窗口的句柄
            GetSafehWnd 取你程序所在窗口類的句柄
            GetActiveWindow 取當(dāng)前活動窗口句柄
            AfxGetMainWnd 取主窗口句柄
            GetForegroundWindow 取前臺窗口句柄
            FindWindow
            EnumWindow
            改變窗口屬性:
            SetWindowLong
            SetClassLong.

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

            strncpy:雖然加入了size這個來限制,但是這個size小于或者等于字符長度的話,那么該信息是不被加上字符串結(jié)束符的.并且仍舊存在跟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來拷貝到緩沖里面,結(jié)果發(fā)現(xiàn)出現(xiàn)了亂碼.
            strncpy, strcpy還是建議少用,換用memcpy+memmove(如果存在重疊的情況)吧:)
            未完待續(xù).

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

            Feedback

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

            久久99精品久久久久久hb无码 | 久久r热这里有精品视频| 2020久久精品国产免费| 99久久精品国产一区二区三区 | 久久久久99精品成人片欧美 | 狠狠久久亚洲欧美专区| 四虎久久影院| 99re久久精品国产首页2020| 中文精品久久久久人妻| 国产免费久久精品99久久| 久久精品国产免费观看三人同眠| 狠狠色丁香久久婷婷综| 色偷偷偷久久伊人大杳蕉| 人人狠狠综合久久亚洲高清| 久久久精品一区二区三区| 亚洲AV日韩精品久久久久久| 久久精品极品盛宴观看| 久久久久国色AV免费观看| 26uuu久久五月天| 久久久国产精品福利免费 | 精品99久久aaa一级毛片| 97超级碰碰碰久久久久| 久久久久人妻精品一区二区三区| 久久人人爽人人爽人人片AV不| 无码精品久久一区二区三区 | 精品乱码久久久久久久| 亚洲精品蜜桃久久久久久| 久久人妻AV中文字幕| 久久久久久国产精品无码下载| 伊人丁香狠狠色综合久久| 久久国产乱子精品免费女| 久久国产精品成人免费| 久久精品国产精品国产精品污| 久久精品国产精品青草app| 久久中文字幕一区二区| 国产女人aaa级久久久级| 久久男人中文字幕资源站| 久久97久久97精品免视看| 性高湖久久久久久久久AAAAA| 久久中文字幕精品| 久久亚洲精品成人AV|