VS2010編譯的時候碰到winnt.h問題

今天心血來潮,到微“軟”那下了個VS2010玩玩。裝好了就隨便做個工程,結果編譯的時候出來幾個錯誤,全是在winnt.h裏邊。

  1. ------ Rebuild All started: Project: 123, Configuration: Debug Win32 ------  
  2.   stdafx.cpp  
  3. c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(290): error C2146: syntax error : missing ';' before identifier 'PVOID64' 
  4. c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(290): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
  5. c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(8992): error C2146: syntax error : missing ';' before identifier 'Buffer' 
  6. c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
  7. c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
  8. ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========== 

然後又是搜索大法,以這些信息搜索,找誰碰到這個問題。結果在微軟的網站上看到了一條信息。

 

  1. I built a new project to start the porting of an application written with CV6++, but the project stopped with the following errore just after few modifications to stdafx.h and the main include icarus2010.h.  
  2.  
  3.  
  4.  
  5. 1>------ Build started: Project: Icarus2010, Configuration: Debug Win32 ------  
  6. 1>Build started 04/11/2009 16.51.46.  
  7. 1>_PrepareForBuild:  
  8. 1> Touching "Debug\Icarus2010.unsuccessfulbuild".  
  9. 1>ClCompile:  
  10. 1> stdafx.cpp  
  11. 1>c:\programmi\microsoft sdks\windows\v7.0a\include\winnt.h(290): error C2146: syntax error : missing ';' before identifier 'PVOID64' 
  12. 1>c:\programmi\microsoft sdks\windows\v7.0a\include\winnt.h(290): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
  13. 1>c:\programmi\microsoft sdks\windows\v7.0a\include\winnt.h(8992): error C2146: syntax error : missing ';' before identifier 'Buffer' 
  14. 1>c:\programmi\microsoft sdks\windows\v7.0a\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
  15. 1>c:\programmi\microsoft sdks\windows\v7.0a\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
  16. 1>c:\programmi\microsoft sdks\windows\v7.0a\include\exdisp.h(842): error C2061: syntax error : identifier 'SHANDLE_PTR' 
  17. 1>  
  18. 1>Build FAILED.  
  19. 1>  
  20. 1>Time Elapsed 00:00:01.93  
  21. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========  
  22.  
  23. The modifications in the stdafx were  
  24.  
  25. #pragma warning(disable: 4786)  
  26. #pragma warning (disable:4996)  
  27. #pragma warning (disable:4244)  
  28. #pragma warning (disable:4189)  
  29. #pragma warning (disable:4100)  
  30.  
  31. and the modifications in the main inlcude were some include files from the VC6++ application. For a while the new project worked!   
  32.  詳細信息 (展開) Product Language  
  33. EnglishVersion  
  34. Visual Studio 2010 Beta 2Operating System  
  35. Windows XP  
  36. Operating System Language  
  37.  
  38. ItalianSteps to Reproduce  
  39. unknownActual Results  
  40. unknownExpected Results  
  41. soon      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey. [Details]   
  42.  
  43.    
  44. ///////////////////////////////////////////////////////////////////////  
  45.     
  46. 由 Microsoft 在 2009/11/5 1:29 發送   
  47. Thank you for your feedback, We are currently reviewing the issue you have submitted.   
  48. 由 Microsoft 在 2009/11/8 20:41 發送   
  49. Thanks for reporting this issue.   
  50.  
  51. In order to fix the issue, we must first reproduce the issue in our labs. We are unable to reproduce the issue with the steps you provided.  
  52.  
  53. Please provide us with a demo zipped project file so that we can conduct further research.  
  54.  
  55. It would be greatly appreciated if you could provide us with that information as quickly as possible. If we do not hear back from you within 7 days, we will close this issue.  
  56.  
  57. Thanks again for your efforts and we look forward to hearing from you.  
  58.  
  59. Visual Studio Product Team  
  60.  
  61. 由 Microsoft 在 2009/11/9 11:54 發送   
  62. Hi -   
  63.  
  64. Do you have the DirectX SDK installed on the machine? We have seen some cases where the DirectX SDK installer modifies the Visual Studio include path and puts the DirectX SDK entries first. This causes the build to use DirectX versions of some files that are a different version that the files in the Visual Studio SDK.  
  65.  
  66. Try changing the order of include directories in VS so the DirectX SDK entries are last. That may solve the problem.  
  67.  
  68. Mike Robinson  
  69. Program Manager  
  70. Windows SDK Team  

有個傢伙也碰到了這個問題。微軟的回答是,你可能裝了DIRECTX SDK,你到包含目錄設置把DX SDK的目錄往後移就可以了。

第一次用不熟這東西,只好以“winint.h”爲關鍵字找,結果從網上找到一個在VS2005設置DX SDK的。

 

  1. 解決方法:在winnt.h中加上以下語句  
  2.  
  3. #define POINTER_64 __ptr64  
  4.  
  5. typedef void *PVOID;  
  6. typedef void * POINTER_64 PVOID64;  
  7.  
  8. 個人認爲最好不去改winnt.h.  
  9. 有時需要要調整include文件夾的順序來解決問題,platform SDK中的winnt.h  
  10. DDK中的,vc6.0 自帶的winnt.h有多個。 dxsdk 中的這些所用到的winnt.h版本不同。  
  11.  
  12. 通過調整IDE 工具-> 選項-> 項目vc++目錄;包含文件include 的順序來解決這類問題  
  13. 使dxsdk需要的winnt.h所在文件夾在最上面。  
  14.  

 

  1. DirectShow 在VS2005中環境配置  
  2. 先介紹系統環境:  
  3. XP Professional sp2  
  4. visual studio 2005 version 8.0.50727.42  
  5. DirectX 9.0(9.0b) SDK Update - (Summer 2003)   
  6.  
  7.  
  8. 首先,就是編譯baseclasses,什麼是baseclasses?打開你的dx的sdk安裝目錄,例如:  
  9. D:\DX90SDK\Samples\C++\DirectShow\  
  10. 這裏就有一個叫baseclasses的工程,爲安全起見,請先備份此工程。   
  11.  
  12. 1,雙擊baseclasses.sln打開,提示我們需要轉換工程,按提示轉換就是了,編譯  
  13. 提示錯誤:  
  14. 1>D:\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnt.h(222) : error C2146: syntax error : missing ';' before identifier 'PVOID64' 
  15. 1>D:\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnt.h(222) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
  16. 1>D:\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnt.h(5940) : error C2146: syntax error : missing ';' before identifier 'Buffer' 
  17. 1>D:\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnt.h(5940) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
  18. 1>D:\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnt.h(5940) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
  19. 1>d:\DX90SDK\Samples\C++\DirectShow\BaseClasses\ctlutil.h(278) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int第一類問題的解決:錯誤發生在:operator=(LONG);函數定義中,這是因爲在VC6中,如果沒有顯示的指定返回值類型,編譯器將其視爲默認整 形;但是vs2005不支持默認整形,解決這個問題不能修改每個沒有顯示指示返回值類型的函數地方,可以用wd4430來解決;具體的在工程選項中的c+ +/Command Line中添加/wd4430即可。   
  20.  
  21.  
  22. 2,在Tools->Options->Projects and solutions->vc++ directories->show directories for裏選擇include files  
  23. 然後增加  
  24. D:\DX90SDK\Include  
  25. D:\DX90SDK\Samples\C++\DirectShow\BaseClasses  
  26. D:\DX90SDK\Samples\C++\Common  
  27. 可能會問題依舊,調整一下include files的順序吧,把他們都放在最後,例如我的環境:  
  28. $(VCInstallDir)include  
  29. $(VCInstallDir)atlmfc\include  
  30. $(VCInstallDir)PlatformSDK\include  
  31. $(FrameworkSDKDir)include  
  32. D:\DX90SDK\Include  
  33. D:\DX90SDK\Samples\C++\DirectShow\BaseClasses  
  34. D:\DX90SDK\Samples\C++\Common  
  35. 然 後在project->BaseClasses properties->configuration->C/C++ -> General->Additional Include Directories裏面的內容(.,..\..\..\..\include)刪掉,重新編譯,PVOID64的錯誤消失,原因如下:  
  36. POINTER_64 是一個宏,在64位編譯下起作用,它包含在SDK目錄下的BASETSD.H中(Microsoft Visual Studio 8\VC\PlatformSDK\Include\basetsd.h(23):#define POINTER_64 __ptr64),但DXSDK自己也帶了一個basetsd.h,裏面沒有定義POINTER_64,從而導致出錯,只需要改變include files的優先級即可。當然,也可以改寫winnt.h中的代碼,在下面這兩行:typedef   void   *PVOID;     
  37. typedef   void   *POINTER_64   PVOID64;  
  38. 之前增加一行:  
  39. #define   POINTER_64   __ptr64   
  40.  
  41. 3,到目前爲止,還剩下:  
  42. BaseClasses\ctlutil.h(278) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
  43. 這個錯誤,解決方法如下:  
  44. 打開project->BaseClasses properties->configuration->C/C++ ->Command Line,增加/wd4430選項。  
  45. 4, 接着編譯,提示error C2065: 'Count' : undeclared identifier等等錯誤,這個是微軟的歷史遺留問題了,C++標準語法的問題,因爲在之前在for循環內定義的變量可以在for之外的地方使用,即 在第一個forfor(int i,...),以後的for再使用i不必再聲明,解決方法也很簡單,打開project->BaseClasses properties->configuration->C/C++->Language->Force Comformance in For Loop Scrope設置爲No即可。當然,也可以手動改代碼,增加一個聲明就是了。   
  46.  
  47. 經過上面幾個步驟,應該是可以順利編譯了,對於其它版本的工程,照樣設置就可以了,總共編譯出下面4個文件備用:  
  48. BaseClasses\Debug\strmbasd.lib  
  49. BaseClasses\Debug_Unicode\strmbasd.lib  
  50. BaseClasses\Release\STRMBASE.lib  
  51. BaseClasses\Release_UnicodeSTRMBASE.lib   
  52.  
  53. 在lib裏面加入   
  54.  
  55. commctrl.lib   
  56. coredll.lib   
  57. strmiids.lib   
  58. strmbase.lib   
  59. uuid.lib   
  60. ole32.lib   
  61. commdlg.lib   
  62.  
  63. 你或許需要在Tools->Options->Projects and solutions->vc++ directories->show directories for->library files裏把它們加進去。  
  64. 趕快編譯DX90SDK\Samples\C++\DirectShow\Players\PlayDMO工程試試看吧。   
  65.  
  66.  
  67. 以上資料整理自下面3個blog,一併列出:  
  68. DirectShow在VS2005中PVOID64問題和配置問題   
  69. http://www.cnblogs.com/RunOnTheWay/archive/2008/01/17/1043705.html  
  70. DirectShow 在VS2005中環境配置  
  71. http://blog.cnii.com.cn/?uid-75821-action-viewspace-itemid-24418  
  72. Some DirectShow Samples Break in Visual Studio 2005  
  73. http://blogs.msdn.com/mikewasson/archive/2005/05/23/some-directshow-samples-break-in-visual-studio-2005.aspx  

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章