VC編譯ADO的開發環境和客戶環境的細微差別可能導致的失敗 (轉)
VC編譯ADO的開發環境和客戶環境的細微差別可能導致的失敗 (轉)[@more@]
·應閱讀本公告牌的目標受眾:針對®ADO 2.5及其後續版本加以應用的客戶。這其中便包括使用著Microsoft ® XP、 SERVER™ 2000和MDAC 2.7的VC員。
·薄弱環節可能造成的影響:VC編譯的應用執行失敗。
·現象:
在開發機器上編譯如下程式碼:
#pragma warning(push) // Needs to be done in order to suppress warning message
#pragma warning(disable:4146) // caused by in ADO (MS Knowledge Base article Q253317)
#import "C:Program FilesCommon Filessystemadomsado15.dll"
no_namespace rename("EOF","adoEOF")
#pragma warning(pop)
#pragma warning(disable:4146) // caused by in ADO (MS Knowledge Base article Q253317)
#import "C:Program FilesCommon Filessystemadomsado15.dll"
no_namespace rename("EOF","adoEOF")
#pragma warning(pop)
.....
_CommandPtr pCmd = NULL;
HRESULT hr = pCmd.CreateInstance("ADO.Command");
HRESULT hr = pCmd.CreateInstance("ADO.Command");
但是在客戶的一臺正常的上卻發生錯誤:
Command指標建立失敗,錯誤號:0x80004002,錯誤描述:沒有此介面。
·原因:
我們的開發機器上一般都裝有MDAC2.7,這可能是因為裝了,也可能是自帶的。
而客戶機器上只有MDAC2.5。
由於的ADO開發小組習慣上總把ADO的最新版本命名為預設介面,如ADO2.5時將_Command25命名為_Command。
這樣當你在MDAC2.7下編譯VC程式碼,繫結的_Command的InterfaceID可能就是_Command2.7的介面ID。而在客戶的MDAC2.5環境中
,可能不存在這個介面ID,它的_Command的介面ID還是2.5的,和你的機器上的_Command介面ID肯定不一樣。
所以以VC的方式建立_CommandPtr指標,是無法建立出來的。但是由於VB並不是繫結InterfaceID,所以VB中還可以正常建立ADO介面指標。
·解決方法:
第一種:只在MDAC2.5環境下編譯,併發布到MDAC2.5以上的客戶環境中,但是WindXP就沒有辦法了;
第二種:強迫客戶環境升級MDAC;
第三種:在MDAC2.7環境下編譯,但是我們只明確表示建立Command25指標,如下所示:
ADODB::Command25Ptr pCmdChange = NULL;
HRESULT hResult = pCmdChange.CreateInstance(__uuidof(ADODB::Command));
HRESULT hResult = pCmdChange.CreateInstance(__uuidof(ADODB::Command));
第四種:選擇使用OLEDB;
============================================
·參考1:
請一定參考這篇文件,他們抱怨得非常清楚:
.com/groups?q=b08400bd+command&hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&selm=uwaoAXD7BHA.1864%40tkmtngp04&rnum=1">%40tkmsftngp04&rnum=1
> The call to CreateInstance will fail when the code is
> compiled with a MDAC 2.7 version of msado.dll but run on
> a system with MDAC 2.5 installed. It returns a HRESULT of
> 0x80004002 (E_NOINTERFACE) - "The QueryInterface method
> did not recognize the requested interface. The interface
> is not supported.". i.e. the code tried to find the new
> _Command interface NOT the old _Command interface as
> defined in MDAC 2.5.
> The code works fine when compiled with MDAC 2.5 and run
> on a system with MDAC 2.5 or greater. (Will also work
> fine when compiled with MDAC 2.7 and run on MDAC 2.7).
>
> SOLUTIONS
> ------------------
>
> 1) Compile only on MDAC 2.5 and then can target MDAC 2.5
> or greater (Not really an option with (
> etc.))
>
> 2) Compile with MDAC 2.7 and force all clients to upgrade
> to MDAC 2.7 (Not an al solution as already have enough
> problems when forcing clients to install MDAC 2.5 -
> breaking existing apps - or simply not installing
> proy as part of the install process)
>
> 3) The solution we have come up with is to develop on
> systems with MDAC 2.7 installed but not to use
> the "_Command" interface. Instead we use the "Command25"
> interface (i.e. this is the renamed "_Command" interface
> from MDAC 2.5). This means all our developers are forced
> to develop on MDAC 2.7 but we can continue to target MDAC
> 2.5 or better). i.e. the above code becomes
>
> ADODB::Command25Ptr pCmdChange = NULL;
> HRESULT hResult = pCmdChange.CreateInstance
> (__uuidof(ADODB::Command));
> compiled with a MDAC 2.7 version of msado.dll but run on
> a system with MDAC 2.5 installed. It returns a HRESULT of
> 0x80004002 (E_NOINTERFACE) - "The QueryInterface method
> did not recognize the requested interface. The interface
> is not supported.". i.e. the code tried to find the new
> _Command interface NOT the old _Command interface as
> defined in MDAC 2.5.
> The code works fine when compiled with MDAC 2.5 and run
> on a system with MDAC 2.5 or greater. (Will also work
> fine when compiled with MDAC 2.7 and run on MDAC 2.7).
>
> SOLUTIONS
> ------------------
>
> 1) Compile only on MDAC 2.5 and then can target MDAC 2.5
> or greater (Not really an option with (
> etc.))
>
> 2) Compile with MDAC 2.7 and force all clients to upgrade
> to MDAC 2.7 (Not an al solution as already have enough
> problems when forcing clients to install MDAC 2.5 -
> breaking existing apps - or simply not installing
> proy as part of the install process)
>
> 3) The solution we have come up with is to develop on
> systems with MDAC 2.7 installed but not to use
> the "_Command" interface. Instead we use the "Command25"
> interface (i.e. this is the renamed "_Command" interface
> from MDAC 2.5). This means all our developers are forced
> to develop on MDAC 2.7 but we can continue to target MDAC
> 2.5 or better). i.e. the above code becomes
>
> ADODB::Command25Ptr pCmdChange = NULL;
> HRESULT hResult = pCmdChange.CreateInstance
> (__uuidof(ADODB::Command));
=============================
·參考2:
另一篇中文參考:
我的ATL/ADO的曲折經歷 horris(原作)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752019/viewspace-977284/,如需轉載,請註明出處,否則將追究法律責任。
請登入後發表評論
登入
全部評論
相關文章
- 【爬坑】.Net編譯環境導致的問題編譯
- RAC環境中修改系統時間可能導致SRVCTL命令失敗
- 第三篇 編譯環境與執行環境不一致會導致class檔案執行失敗編譯
- java編譯環境的構建(轉)Java編譯
- 編譯環境 Golang開發環境 vscode+git編譯Golang開發環境VSCodeGit
- Linux 開發環境 -- C/C++開發環境編譯安裝Linux開發環境C++編譯
- 簡單建立VC + DDK的驅動開發環境開發環境
- 15 款最好的 C/C++ 編譯器和整合開發環境C++編譯開發環境
- webpack4生產環境和開發環境的對比Web開發環境
- 全志A40i開發板編譯環境的搭建編譯
- maven更改編譯環境的java版本Maven編譯Java
- 配置開發環境、生成環境、測試環境開發環境
- 安裝不上vc++環境,導致部分遊戲和qq不能用的解決方案C++遊戲
- 高通編譯環境搭建編譯
- openform環境搭建-編譯ORM編譯
- VC++ 6.0下OpenGL開發環境配置C++開發環境
- 《爐石傳說》的退環境機制失敗在哪
- 【轉】Windows Phone 8 開發環境的搭建Windows開發環境
- Python的開發環境Python開發環境
- 搭建vue的開發環境Vue開發環境
- WinCE開發環境的搭建開發環境
- qgroundcontrol開發環境搭建原始碼編譯開發環境原始碼編譯
- Android 原始碼的下載和編譯環境的安裝及編譯Android原始碼編譯
- Mac版最詳細的Flutter開發環境搭建MacFlutter開發環境
- Java開發環境的安裝和配置Java開發環境
- emacs開發環境配置(4)——rust開發環境Mac開發環境Rust
- 開發中所使用的開發環境開發環境
- 彙編程式開發環境搭配開發環境
- Win32彙編的環境和基礎(轉)Win32
- Win32彙編的環境和基礎 (轉)Win32
- centos下編譯lnmp環境CentOS編譯LNMP
- 編譯安裝LAMP環境編譯LAMP
- 編譯LAMP環境之PHP編譯LAMPPHP
- Android編譯環境搭建Android編譯
- Ubuntu交叉編譯環境配置Ubuntu編譯
- VC6.0 + WDK 7600.16385.1 開發環境配置開發環境
- 利用 Docker 構建一個簡單的 java 開發編譯環境DockerJava編譯
- 編譯環境一致Wise2C的自動化流程編譯