日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > c/c++ >内容正文

c/c++

第一课[编辑器设置-VC++6.0]

發(fā)布時(shí)間:2025/3/15 c/c++ 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第一课[编辑器设置-VC++6.0] 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

VC++6.0直接生成driver

內(nèi)容:
VC++ 6.0來(lái)編輯(不是編譯)Driver的源文件是很不錯(cuò)的選擇,尤其是搭配用Visual Assist,更方便了。編輯完了,就在VC++里面build,就更方便了。
我在M$的站點(diǎn)參考了些,DS生成的dsw、和build生成的log文件,都有參考。實(shí)際上,M$站點(diǎn)上就是根據(jù)buildlog文件來(lái)改VCSetting的。Me too
限于2K DDK,因?yàn)?/span>XP DDK2003 DDK不需要VC++6.0了。并且我用VC6來(lái)build的時(shí)候,會(huì)告訴你“Compiler version not supported by Windows DDK”,不過(guò)沒(méi)有進(jìn)一步去嘗試。(注:有個(gè)bt的方式,照樣添加XPsetting,當(dāng)然路徑要設(shè)置對(duì),然后用UltraEdit修改dsp文件,根據(jù)配置把對(duì)應(yīng)的clmidlrclink什么的改為XP DDK的,嘿嘿)
DDK
自己帶了link982K DDK似乎都是VC5的,如果像我這樣做,實(shí)際上是用VC6link了。
不考慮sourcedirmake文件。

DDK
build,其實(shí)算是一個(gè)調(diào)用nmake工具,而nmake去調(diào)相應(yīng)的文件如cl.exelink.exe等。
cl
的選項(xiàng)設(shè)置,主要注意DDKinclude路徑問(wèn)題,link的選項(xiàng),就是要讓linklink出一個(gè)sys而不是exe,呵呵

預(yù)備工作:
1
、安裝了DDK(呵呵,說(shuō)句廢話)。目錄名字最好不要帶空格。
2
、建立一個(gè)workspace,把自己的chrc等文件加進(jìn)去。
3
Configurations,添加CheckedFree,不要DebugRelease(其實(shí)這并沒(méi)有什么必要,CheckedDebug,看你怎么叫了)。
剩下的就是改各個(gè)設(shè)置,讓VC為你build出一個(gè)sys文件了。

我們一個(gè)一個(gè)的來(lái)。所有的改動(dòng),都在Project->Setting下面。主要集中在C/C++Link下。
1
General,就一個(gè),Not Using MFC
2
Debug,沒(méi)有什么可改的;
3
C/C++

1.1 General

3.1.1 Warning level
,用Level3,驅(qū)動(dòng)嘛,穩(wěn)定壓倒一切,而且DDK sample就是warning 3的,Warnings as errors選上;
3.1.2 Optimizations
,對(duì)checked,我是Disable(Debug),省的用SoftIce的時(shí)候會(huì)有變量說(shuō)Watch不了,對(duì)Free的,我是Customize,后面會(huì)講到;
3.1.3 Debug Info
Free當(dāng)然是沒(méi)有了,你要加上是你的事了,Checked,我用C7VC默認(rèn)的Program Database for /"Edit & Continue/",和link/driver選項(xiàng)沖突;
3.1.4 Preprocessor definitions
,有些我并沒(méi)有弄清楚,有些可能是DS用的,大概說(shuō)說(shuō)。下面是我某個(gè)dsw用的。
RDRDBG, SRVDBG, FPO=0, WIN32=100, STD_CALL, CONDITION_HANDLING=1, NT_UP=1, NT_INST=0, _NT1X_=100, WINNT=1, _WIN32_WINNT=0x0400, WIN32_LEAN_AND_MEAN=1, DEVL=1, _DLL=1, _X86_=1, $(CPU)=1, NTVERSION=/'WDM/', WINVER=0x500, NTDEBUG=ntsd
DBG=1

STD_CALL
不必說(shuō)了,driver的函數(shù)全部是__stdcall的,其實(shí)在其他地方有設(shè)置的。
WINVER=0x500
,是因?yàn)槟闶?/span>for 2K的。XP的是0x501,不過(guò)沒(méi)有用,反正不能用VC6了。
_X86_=1
,沒(méi)有的話,嘿嘿。AlphaCPU不是這個(gè)值了。
DBG
free的話,就不要定義,或?yàn)?/span>0
FPO
checked的為0free的為1。我想應(yīng)該是指Fram-Pointer Omission
NTDEBUG= checked ? ntsd : ntsdnodebug
WIN32_LEAN_AND_MEAN, Exclude rarely-used stuff from Windows headers
non-mfc的,用這個(gè)能減少build的時(shí)間。多些definitions也沒(méi)有關(guān)系,不影響其他的就好
NT_UP
,為0表示是MP,多處理器的,1表示你在單處理器用的。
NT_INST
set to turn on instrumentation


根據(jù)driver類(lèi)型,你可能還要加上別的preprocessor definitions,比如NDISIMD,就要NDIS50, NDIS_MINIPORT_DRIVER, NDIS50_MINIPORT
3.1.5 Project Options
你只需要最后添加幾個(gè)就好了,包括/QIfdiv- /QIf /QI0f,可以在MSDN上查到。值得一提是VC產(chǎn)生的workspacedebug setting,默認(rèn)有個(gè)GZ選項(xiàng),Catch Release-Build Errors in Debug Build,編譯的時(shí)候會(huì)說(shuō)error LNK2001: unresolved external symbol __chkesp,去掉就好了。
1.2 C++ Language
沒(méi)有什么說(shuō)的,不要RTTI exception handling看你用沒(méi)有用了。
1.3 Code Generation
Calling convention__stdcall,其余不管了(記得STD_CALL嗎);
1.4 Customize
沒(méi)有什么可說(shuō)的,我一般是function-level linking,因?yàn)榧恿?/span>GF選項(xiàng),Eliminate duplicate strings我也就不選了;
1.5 Listing Files
Listing file type可說(shuō)一下。你要想看匯編代碼的話,可以在這里改改;
1.6 Optimizations checked
自然是disable了,free的,我選是Full optimizationFrame_Popinter Omission,以及Only __inline,其實(shí)這看個(gè)人了;
1.7 Precompiled Headers
這個(gè)就不說(shuō)了,看MSDN吧,默認(rèn)也可以;
1.8 Preprocessor Preprocessor definitions
前面已經(jīng)說(shuō)了,重點(diǎn)在Additional include directories上,$(BASEDIR)incddkwdm, $(BASEDIR)incddk, $(BASEDIR)inc, $(BASEDIR)incwin98, ....inc,這是我某個(gè)dsw的,所以,BASEDIR的環(huán)境變量要設(shè)置好,我就順便用DS的工具來(lái)start VC,它恰好幫你設(shè)置了,當(dāng)然你也可以直接寫(xiě)上你的DDK的安裝路徑。找不到include 路徑,會(huì)引發(fā)一大堆錯(cuò)誤,比如WDM.H有錯(cuò)誤等。。。是很多人問(wèn)的問(wèn)題;

4
好了,輪到Link
4.1 General
Ignore all default libraries,你可以選上generate map file map文件有時(shí)候很有用的;Checked的當(dāng)然要選上generate debug info Link incrementally不選;Objects/library modules,添加wdm.lib等,ntoskrnl.lib好像輸出了諸如sprintfstrcat等一些函數(shù)(注1),根據(jù)driver可能還要其他的,比如ndis.lib;別忘了Output file name改成yourname.sys,可不是yourname.exe
4.2 Debug
checked要改改,選上Debug info,我是選Both formats的;
4.3 Input
重點(diǎn)之一,Additional lib path$(BASEDIR)libchki386,這是我的一個(gè)dsw用的,checkedchecked lib的路徑,freefreelib的路徑
4.4 Output
Entry-point symbol,填DriverEntry,或_DriveEntry@8,一樣;
根據(jù)link的輸出來(lái)看,Base address應(yīng)該填0x10000StackReserve的應(yīng)該填0x40000Commit0x1000Version Info,自己填吧;
4.5 Project Options
,重點(diǎn),很多選項(xiàng)要直接在這里添加。要添加的包括:
/machine:IX86
CPU相關(guān)的
/debug:full
/debugtype:both 根據(jù)M$站點(diǎn)的說(shuō)法,為了使WinDbg能找到你的symbol,這兩是都要的,而且還要單獨(dú)用linker來(lái)link一次,VC不認(rèn)/debug:fullfree就沒(méi)有這個(gè)問(wèn)題了。根據(jù)M$的方法,可以這樣:寫(xiě)個(gè)lnk文件,在Post-build step,再link一次,添加link @yourlnk.lnk,這個(gè)lnk文件,可以從log文件提取,如果不用WinDbg,就無(wú)所謂了;
/driver
Use this linker option to build a Windows NT kernel mode driverMSDN說(shuō)的
/IGNORE:4001,4037,4039,4065,4070,4078,4087,4089,4096,4210
MSDN
/MERGE:_PAGE=PAGE /MERGE:_TEXT=.text /SECTION:INIT,d
DriverEntry就可以放到INIT section去。
/FULLBUILD
/RELEASE
,在文件頭添加checksum
/FORCE:MULTIPLE
/OPT:REF /OPT:ICF /align:0x20 /osversion:5.00 /subsystem:native

特別注意/subsystem:native/driver不要漏了。
一長(zhǎng)串的/ignore可以讓你即使選warning level 4也能通過(guò),warning level 4有點(diǎn)變態(tài)的


其實(shí)上面說(shuō)的大部分是廢話:),大部分選項(xiàng),你看看build輸出的log文件,就能知道了。這樣你也可以根據(jù)你的driver,自己添加一些必要的選項(xiàng)。

越寫(xiě)越覺(jué)得自己無(wú)知

有什么不對(duì)的地方,請(qǐng)指出。

另外還有用個(gè)bat文件在VCbuild的方法等,不多說(shuō)了。


12003DDK帶了個(gè)ntstrsafe.h,有一些很方便的string函數(shù)可以用,而且保證安全,在NT2K也可以用的,我把它貼上來(lái)。用ntoskrnl輸出的如strcpy等函數(shù)現(xiàn)在就沒(méi)有必要了。



-------------------------------------------------------
關(guān)于DbgPrint的一個(gè)問(wèn)題:

我測(cè)試驅(qū)動(dòng)的時(shí)候碰到藍(lán)屏,用sistack命令一看,居然是KdPrint引起的,很是ftDbgPrint調(diào)用_vsnprintf,它又調(diào)用wctomb,就藍(lán)了,沒(méi)有記錯(cuò)的話是0xAIRQL_NOT_LESS_OR_EQUAL。同樣的上下文,其他地方多次用KdPrint都沒(méi)有問(wèn)題。
我想原因可能在spinlock上。這個(gè)DbgPrintKeAcquireSpinLockRelease之間的。把這個(gè)KdPrint注釋掉,就好了。

因?yàn)?/span>SpinLock,就提升到dispatch level了,這個(gè)時(shí)候不能用%wc and %ws的(必須在passive level),而我好像用了,so...
自己沒(méi)有注意看DDK


------------------------------------------------------
關(guān)于優(yōu)化碰到的一個(gè)問(wèn)題:
這個(gè)問(wèn)題應(yīng)該是優(yōu)化引起的,因?yàn)楦牧司湍苡昧恕?/span>
事情是這樣地:一個(gè)NDIS5miniport驅(qū)動(dòng),在重新搭建的編譯環(huán)境下編譯的可以在2Krun的,結(jié)果在98下一加載就掛了(他們說(shuō)以前可以在98下用的),ft,找了半天發(fā)現(xiàn)是優(yōu)化選項(xiàng)的緣故:以前用的是最小代碼優(yōu)化,而新的用了最快代碼優(yōu)化,就不行了。這樣也會(huì)出問(wèn)題!?真。。。反正改為最小代碼優(yōu)化就能用了。


------------------------------------------------------
關(guān)于浮點(diǎn)運(yùn)算:
KeSaveFloatingPointStateKeRestoreFloatingPointState

不過(guò)我一直沒(méi)有機(jī)會(huì)用

直到前幾天,我用上了。我發(fā)現(xiàn)直接用這兩函數(shù),會(huì)報(bào)錯(cuò),說(shuō)不能link 外部的__fltused
同事加了個(gè)全局的ulong __fltused 1;錯(cuò)誤沒(méi)有了,可是結(jié)果并不正確。sprintf(/"%3f/",x)不對(duì),x是個(gè)float
后來(lái)發(fā)現(xiàn),加上msvcrt.lib就好了,也不用定義全局的變量。


Walt Oney
有更全面的解釋,哪天貼上來(lái)

-------------------------------------------------------
Walt Oney關(guān)于浮點(diǎn)運(yùn)算的一個(gè)帖子貼上來(lái)吧

From: Walter Oney
Subject: Re: Using Floating variable in a WDM driver
Date: 1999/09/22
Message-ID: <37E8B83D.AFA107ED@oneysoft.com>#1/1
Content-Transfer-Encoding: 7bit
References: <7sa8kg$elc$1@news.entreprises.cegetel.fr>
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@rcn.com
X-Trace: GjGUm2k/h6dchDSW3dAtWL+k38GPA70bhhY4oqkqhG8=
Organization: Walter Oney Software
Mime-Version: 1.0
Reply-To: waltoney@oneysoft.com
NNTP-Posting-Date: 22 Sep 1999 11:08:34 GMT
Newsgroups: comp.os.ms-windows.programmer.drivers,comp.os.ms-windows.programmer.nt.kernel-mode


David BOUYEURE wrote:
> I want to use afloating variable in my driver (98 WDM).
> I have this error at compile time :
> /"unresolved external symbol __fltused/"
> I guess I have to link with a special lib, but I haven/'t found wich one.

The problem is worse than just finding the right library, unfortunately. The C compiler/'s floating point support assumes that it will be operating in a an application environment where you can initialize the coprocessor, install some exception handlers, and then blast away. It also assumes that the operating system will take care of saving and restoring each thread/'s coprocessor context as required by all the
thread context switches that occur from then on.

These assumptions aren/'t usually true in a driver. Furthermore, the runtime library support for coprocessor exceptions can/'t work because there/'s a whole bunch of missing infrastructure.

What you basically need to do is write your code in such a way that you initialize the coprocessor each time you want to use it (don/'t forget KeSaveFloatingPointState and KeRestoreFloatingPointState). Set things up so that the coprocessor will never generate an exception, too. Then you
can simply define the symbol __fltused somewhere to satisfy the linker.(All that symbol usually does is drag in the runtime support. You don/'t want that support becuase, as I said, it won/'t work in kernel mode.) You/'ll undoubtedly need some assembly language code for the initialization steps.

If you have a system thread that will be doing all your floating point math, you can initialize the coprocesor once at the start of the thread.
The system will save and restore your state as necessary from then on.

Don/'t forget that you can only do floating point at IRQL <
DISPATCH_LEVEL.

--
Walter Oney
[url] http://www.oneysoft.com[/url]


--------------------------------------------------------
關(guān)于一些C的字符處理函數(shù)

其實(shí)ntoskrnl.exe輸出了不少的諸如atoisprintf等函數(shù)(2K的,XP的沒(méi)有驗(yàn)證),用dumpbinexports參數(shù)可以看到。
那么至少,這些函數(shù)在passive level是可以用的。import lib應(yīng)該就是ntoskrnl.lib了。

2k ntoskrnl.exe
輸出的一些函數(shù)copy到下面吧 能用的函數(shù)還是不少的

1155 482 0005DC88 _itoa
1156 483 0005DD11 _itow
1159 486 0005DD3F_snprintf
1160 487 0005DD90 _snwprintf
1161 488 0005DE00 _stricmp
1162 489 0005DE8C_strlwr
1163 48A0005DEB0 _strnicmp
1164 48B 0005DF60 _strnset
1165 48C0005DF90 _strrev
1166 48D 0005DFC0 _strset
1167 48E 0005DFE0 _strupr
1168 48F0005E003 _vsnprintf
1169 490 0005E053 _wcsicmp
1170 491 0005E09E _wcslwr
1171 492 0005E0C8 _wcsnicmp
1172 493 0005E11D _wcsnset
1173 494 0005E143 _wcsrev
1174 495 0005E173 _wcsupr
1175 496 0005E228 atoi
1176 497 0005E19D atol
1177 498 0005E2B1 isdigit
1178 499 0005E289 islower
1179 49A0005E32E isprint
1180 49B 0005E306 isspace
1181 49C0005E261 isupper
1182 49D 0005E2D9 isxdigit
1183 49E 0005E35Cmbstowcs
1184 49F0005E3CF mbtowc
1185 4A0 0005E410 memchr
1186 4A1 0005E4C0 memcpy
1187 4A2 0005E800 memmove
1188 4A3 0005EB40 memset
1189 4A4 0005EB98 qsort
1190 4A5 0005ED64 rand
1191 4A6 0005ED82 sprintf
1192 4A7 0005ED5Asrand
1193 4A8 0005EDF0 strcat
1194 4A9 0005EEE0 strchr
1195 4AA 0005EFA0 strcmp
1196 4AB 0005EDE0 strcpy
1197 4AC0005F030 strlen
1198 4AD 0005F0B0 strncat
1199 4AE 0005F1E0 strncmp
1200 4AF 0005F220 strncpy
1201 4B0 0005F320 strrchr
1202 4B1 0005F350 strspn
1203 4B2 0005F390 strstr
1204 4B3 0005F410 swprintf
1205 4B4 0005F47Ftolower
1206 4B5 0005F4B3 toupper
1207 4B6 0005F504 towlower
1208 4B7 0005F51Ftowupper
1209 4B8 0005F529 vsprintf
1210 4B9 0005F57Awcscat
1211 4BA 0005F5C9 wcschr
1212 4BB 0005F5F2 wcscmp
1213 4BC 0005F5A4 wcscpy
1214 4BD 0005F62B wcscspn
1215 4BE 0005F66Cwcslen
1216 4BF 0005F689 wcsncat
1217 4C0 0005F6C9 wcsncmp
1218 4C1 0005F701 wcsncpy
1219 4C2 0005F73E wcsrchr
1220 4C3 0005F77E wcsspn
1221 4C4 0005F7C0 wcsstr
1222 4C5 0005F806 wcstombs
1223 4C6 0005F879 wctomb




-------------------------------------------------------
ntstrsafe.h
文件和ntstrsafe.lib文件


------------------------------------------------------
利用DS的插件,可以在VC6VC.NET下,調(diào)用DDKcllink,來(lái)編譯驅(qū)動(dòng)。
但是,如果沒(méi)有裝DS呢?
對(duì)vc6,你可以這樣啟動(dòng)你的dsw
set BASEDIR=...
start msdev my.dsw

或者,比較好的是先進(jìn)入DDKbuild環(huán)境,然后
start msdev my.dsw /useenv

.NET
可以類(lèi)似處理,就不說(shuō)了

[
編輯 - 6/30/04 by arthurtu]

[
編輯 - 9/7/04 by arthurtu]

[
編輯 - 5/17/05 by arthurtu]

總結(jié)

以上是生活随笔為你收集整理的第一课[编辑器设置-VC++6.0]的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。