5月 2006的归档

今天从图书馆走回来(这对于华工来说,不是件容易的事情)。看到大嘴的电脑前围了几个人,过去一看,原来是CPropertySheet的使用出了点问题,于是就跟大家讨论了一下。

关于初始化部分,最初选择放在类的构造函数中,但是这里有些成员变量是CONTROL型的,在构造CPropertySheet的派生类的时候,该控件还没有创建,所以运行会出错。所以改到initdialog里面。一切ok。

关于返回的问题。由于CPropertySheet默认不能由classwizzard添加onok的响应函数。所以可以选择手动添加,在这里我们想使用另外一种方式,就是在调用CPropertySheet的时候用if(M_myprperty.domodal()=IDOK){

//do sth

}

但是由于这时已返回,访问控件失败。最后在网上找到,属性表会调用每一页的onok(),所以问题解决,只需要在每一页重载onok()就可以了

Shot alternate link for this article: 属性表CPropertySheet的OnOK问题。Tags:

Comments 一个回复 »

关于对于VC/MFC/ATL的评论问题,其实我很早就想写一篇文章来阐述自己的观点,
不过又觉得这种容易引发论战的文章实际上是在空耗大家的时间, 不如做点实际
工作. 但是现在中国程序员群体的思想走向已经到了一种非常危险的一边倒的地步,
上几期电脑报上登出了几名14岁的小孩子, 刚刚学会写几个程序, 就把VC列为自己
的梦想. 我去年找工作的时候,连续被几个公司问会不会VC,得到我的答复之后,
他们怎么也不能相信一个学了四年C,两年多C++,还利用“空闲”时间学习了Java、
Perl的人,一个敢于在“专长”一栏里写上“掌握C++”的人,居然只是对VC“略
有了解”,我从他们的表情中看出一种不屑:“你还敢说自己懂C++?你还有时间
去学别的东西?连VC都不会,水平能高到哪去?”我并没有费力去向他们解释VC外
面的世界更精彩,因为之前我在提到STL这个词汇的时候,已经留心他们目光,那是
一种冷漠、茫然和无动于衷。一切都已经十分清楚,解释是徒劳的,他们根本不知道VC外面还有C++。

当然不劳大家担心,我最终还是找到了一份满意的工作。但是这种经历对我的触动
是很大的,因为我已经深深地感觉到,当我们中国的程序员好不容易能够有机会以
一双开放的眼睛面向整个世界的时候,我们的思想又被迅速地封闭了起来。一个叫
微软的巨人用一只巨大的圆规在我们的思想里画了一个大圈圈,并且对我们说:
“天就是这么高,地就是么大,你们享受吧!”伊甸园的生活是快味的,但是,
当我们所有人都被牢牢地限制在一个范围之内,听命于一个上帝的清规戒律时,我看不到我们自己的未来还有什么希望,我甚至看不到我们自己存在的意义。

不自由,勿宁死!

我们的能力当然是有限的,在相当长的一段时间里我们所能到达的疆界还是会远远地小于先驱者开拓的界域。但是我确信,就在现在,我们的能力至少可以突破微软给我们划定的天地。微软是好的,她很体贴,很出色。但是不论是微软也好,巨软也好,在我们程序员的心中,没有凯撒。我们可以把你当朋友,但是你别想做我们的主子!我们一定要走出去,虽然我们知道极限是存在的,很长时间里我们是不可能超过前人的,但是我们一定要出去。我们可以因为累死而在探索的道路上而止步,但决不能在人为设定的篱笆前畏缩不前。

C++是我最钟爱的语言,我愿意投入一辈子的时间在她的身上。VC也是一个好东西,在Windows下我最喜欢的C++编译器。MFC/ATL也都是好东西,如果将来需要,我也会认真地学习它们。但是,我心中的天地比这要宽广的多,标准C++所定义的语言性能集和标准库,是更加绚丽的风景线;STL所带来的通用编程时代的曙光,更令我心驰神往;设计模式的精美与一致,面向模式编程范式的初现端倪,面向对象软件工程的成熟与巨大希望,TAO/ACE的庞大与精致,我们中国人自己的C**语言的动人心魄,…,让我目不暇接的珍宝太多太多。虽然我所能接触到的东西只是一小部分,虽然在这个过程中我更加深刻地发现自己的水平是多么的不值一提,但是我已经可以大声宣称:外面的世界很精彩!

我知道我们都还是生活在现实世界中的,精神上的快乐不足以填饱辘辘饥肠。但是
我们现在是在说C++啊!想想你为什么不用更简单、更好挣钱的VB、Java、Delphi,
偏偏要把已经够难学的VC当成自己心中的理想呢?不就是因为VC能够代给你自由、
自信和自豪吗?如果你意识到VC同样是道更大的篱笆墙,你为什么不愿意冲出去,
获取更大的自由、自信和自豪呢?

B.Stroustrup说:“我想大家学习C++,应该是为了解决哪些开创性的问题,而不是
一次次地重复解决哪些已经有了成熟的框架和现成的解决方案的问题。”C++是开拓
者的语言,是思想者的语言,是“高手”层次之上的语言。或许在实用性、简单性
方面,现在和将来都会有许多语言不断地超越它。但是,我认为在相当长的一段时间里,在构造和表达软件工程思想和创造性软件的开发领域,不会有什么语言能超过它。或者说,精通了C++语言及其思想的程序员,在思想深度和对新技术的领悟能力上上是远远超越其他语言使用者的,我们或许应该称这种人为程序员中的思想者。正因为如此,我认为被限制在VC的圈圈里,不是一个C++程序员能够容忍的。

我觉得,作为一名真正的C++程序员和自由的思想者,更应该有有一颗仁慈的心。不要整天纠缠与C++和JAVA谁好谁次的争论,不要一听说某软件使用VB做的就鄙夷起来,更不要拒绝学习其他的语言。C++难学、难用,距离应用层面比较远,这些问题我们应该坦率地承认,可能的话做出一些努力来改变这些情况。应该积极鼓励把其他语言与C++混合使用,让C++成为它们背后坚实的支撑。我不是公司的老板,但是我觉得,如果我的企业能拥有这种水平的程序员,我会为自己的企业而骄傲,也会给他最高的薪水。

附:
我个人认为MFC实现上的缺陷:
MFC是在89年代末,90年代初定型的,当时C++还十分不完善。在当时来讲,MFC是相当先进的。但是从那以后,C++发生了(可以说是)革命性的巨大变化,与新的C++相比,MFC的体系结构和实现机制显得比较落后,很多优秀的C++特性都没有被合理地应用,反而自己另起炉灶搞了一摊。而且VC这种语言也越来越不象C++了,完全为微软自己的应用而量身定制,甚至不惜违反标准。(不过在编译技术尤其是优化技术上的确还是无人能及)

MFC由几个缺点让我比较不满:
1. 大量使用稀奇古怪宏, 搞的代码不象个样子. 真佩服有些人那么耐心地去分析它们.
2. 消息映射的实现机制十分笨拙. 不用继承我可以理解, 但是为什么不用委托, 而要
   用表驱动? 还是那句话, 搞的代码不像个样子.
3. 对于底层SDK的封装太薄, 面向对象的感觉不足.(当然也有他的好处, 不过这毕竟是
   C++!)
4. 自己另起炉灶搞了RTTI, SEH, CString, CObjXXX(Container)这些东西, 实现的
   又不太好, 早几年还可以理解, 现在则完全落伍.
5. 很多场合本来是标准库可以一展身手的地方, MFC完全没用上.
6. 为了迎合MFC, 编译器的很多地方都违反标准.
7. Doc/View体系的局限性, 想突破很难.

话说回来, MFC还是一套出色的工具. 但是现在它事实上已经成为了对中国C++程序员的一个威胁, 它把太多的精力和资源吸引到支路上面, 而对于主干道上真正的好东西视而不见. 矫枉必须过正, 所以我不惜得罪一大批人, 写了上面的文章. 正如开篇所
说, 我一向认为无休止的争论是空谈误国, 该说的话已经说了, 大家可以批评讨论,
但我大概是不会再回到这个话题上来了.

Shot alternate link for this article: 转载:VC不是梦想,C++需要自由的心 myanTags:

Comments 沒有留言 »

学习mfc到一定程度,必然要查看一下它的源代码。可是组成mfc源代码的文
件太多又太长,如何快速方便地找到我们要看的东西?
初次学习vc的朋友或许不知道在你的vc++6.0安装目录的某个角落里有这么一
个文件:mfc.bsc。这可是学习掌握vc和mfc的好帮手。靠它可以找出vc和mfc中某
个类的声明和成员函数的定义,可以找到vc中每一个预定义名和宏的定义,找出
一个文件里都声明了什么类,类中有些什么成员,还可以找出mfc中各个类的各个
成员函数谁调用了谁。
打开你的vc++6.0,先随便打开一个project,然后选菜单File/Open,在“文
件类型”一栏里选Browse Info File(.bsc),然后进入“你的vc++6.0的安装目录
vc98mfcsrc”里,选中文件mfc.bsc,按“打开”。
然后在主菜单里选Tool/Source Browser,会弹出一个对话框,里面包含两个
窗口。第一个窗口是Identifier,你可以在这里输入函数名,类名,预定义名,
宏名,文件名。
如果你在第一个窗口里输入了函数名,类名,预定义名,宏名,那么你在第
二个窗口里可以选第一项:Definitions and References。然后按OK,就可以查
看函数,类,预定义名和宏的定义以及在何处被引用。
如果你在第一个窗口里输入了文件名,那么你在第二个窗口里可以选择第二
项:File Outline,按OK后可以查看该文件里声明了什么类,什么函数,等等。

如果你在第一个窗口里输入了一个类名,那么在第二个窗口里你可以选择第
三项和第四项:Base Classes and Members和Derived Classes and Members。按
OK后分别可以查看该类的基类及其成员和该类的派生类及其成员。
如果你在第一个窗口里输入了一个函数名,那么你在第二个窗口里可以选择
最后两项:Call Graph和Caller Graph,按OK后分别可以查看该函数调用了谁和
被谁调用。

还有一个小技巧:当最后的结果显示出来后,你在结果中的函数名,类名,
预定义名,宏名上双击鼠标左键,那么包含这些名字的定义或实现的文件就被打
开了。

Shot alternate link for this article: 转载 查看mfc源码的一个很好的方法

Comments 沒有留言 »

 

The following table describes the error codes contained in Winerror.h included with Microsoft Visual C++ version 5.0:


Automation Automation
Error Error
in Decimal in Hex Error Description

-2147418113 (8000FFFF) Catastrophic failure.
-2147942413 (8007000D) The Data is invalid.

-2147467263 (80004001) Not implemented.
-2147024882 (8007000E) Ran out of memory.
-2147024809 (80070057) One or more arguments are invalid.
-2147467262 (80004002) No such interface supported.
-2147467261 (80004003) Invalid pointer.
-2147024890 (80070006) Invalid handle.
-2147467260 (80004004) Operation aborted.
-2147467259 (80004005) Unspecified error.
-2147024891 (80070005) General access denied error.
-2147483647 (80000001) Not implemented.
-2147483646 (80000002) Ran out of memory.
-2147483645 (80000003) One or more arguments are invalid.
-2147483644 (80000004) No such interface supported.
-2147483643 (80000005) Invalid pointer.
-2147483642 (80000006) Invalid handle.
-2147483641 (80000007) Operation aborted.
-2147483640 (80000008) Unspecified error.
-2147483639 (80000009) General access denied error.
-2147483638 (8000000A) The data necessary to complete this operation
not yet available.
-2147467258 (80004006) Thread local storage failure.
-2147467257 (80004007) Get shared memory allocator failure.
-2147467256 (80004008) Get memory allocator failure.
-2147467255 (84009) Unable to initialize class cache.
-2147467254 (8400A) Unable to initialize RPC services.
-2147467253 (8000400B) Cannot set thread local storage channel control.
-2147467252 (8000400C) Could not allocate thread local storage channel
control.
-2147467251 (8000400D) The user supplied memory allocator is
unacceptable.
-2147467250 (8000400E) The OLE service mutex already exists.
-2147467249 (8000400F) The OLE service file mapping already exists.
-2147467248 (80004010) Unable to map view of file for OLE service.
-2147467247 (80004011) Failure attempting to launch OLE service.
-2147467246 (80004012) There was an attempt to call CoInitialize a
second time while single threaded.
-2147467245 (80004013) A Remote activation was necessary but was not
allowed.
-2147467244 (80004014) A Remote activation was necessary but the server
name provided was invalid.
-2147467243 (80004015) The class is configured to run as a security id
different from the caller.
-2147467242 (80004016) Use of Ole1 services requiring DDE windows is
disabled.
-2147467241 (80004017) A RunAs specification must be A RunAs
specification must be
<domain name>\<user name> or simply
<user name>.
-2147467240 (80004018) The server process could not be started. The
pathname may be incorrect.
-2147467239 (80004019) The server process could not be started as the
configured identity. The pathname may be
incorrect or unavailable.
-2147467238 (8000401A) The server process could not be started because
the configured identity is incorrect. Check the
username and password.
-2147467237 (8000401B) The client is not allowed to launch this server.
-2147467236 (8000401C) The service providing this server could not be
started.
-2147467235 (8000401D) This computer was unable to communicate with the
computer providing the server.
-2147467234 (8000401E) The server did not respond after being launched.
-2147467233 (8000401F) The registration information for this server is
inconsistent or incomplete.
-2147467232 (80004020) The registration information for this interface
is inconsistent or incomplete.
-2147467231 (80004021) The operation attempted is not supported.
-2147221504 (80040000) Invalid OLEVERB structure.
-2147221503 (80040001) Invalid advise flags.
-2147221502 (80040002) Can't enumerate any more, because the associated
data is missing.
-2147221501 (80040003) This implementation doesn't take advises.
-2147221500 (80040004) There is no connection for this connection ID.
-2147221499 (80040005) Need to run the object to perform this operation.
-2147221498 (80040006) There is no cache to operate on.
-2147221497 (80040007) Uninitialized object.
-2147221496 (80040008) Linked object's source class has changed.
-2147221495 (80040009) Not able to get the moniker of the object.
-2147221494 (8004000A) Not able to bind to the source.
-2147221493 (8004000B) Object is static; operation not allowed.
-2147221492 (8004000C) User cancelled out of save dialog.
-2147221491 (8004000D) Invalid rectangle.
-2147221490 (8004000E) compobj.dll is too old for the ole2.dll
initialized.
-2147221489 (8004000F) Invalid window handle.
-2147221488 (80040010) Object is not in any of the inplace active states.
-2147221487 (80040011) Not able to convert object.
-2147221486 (80040012) Not able to perform the operation because object
is not given storage yet.
-2147221404 (80040064) Invalid FORMATETC structure.
-2147221403 (80040065) Invalid DVTARGETDEVICE structure.
-2147221402 (80040066) Invalid STDGMEDIUM structure.
-2147221401 (80040067) Invalid STATDATA structure.
-2147221400 (80040068) Invalid lindex.
-2147221399 (80040069) Invalid tymed.
-2147221398 (8004006A) Invalid clipboard format.
-2147221397 (8004006B) Invalid aspect(s).
-2147221396 (8004006C) tdSize parameter of the DVTARGETDEVICE structure
is invalid.
-2147221395 (8004006D) Object doesn't support IViewObject interface.
-2147221248 (80040100) Trying to revoke a drop target that has not been
registered.
-2147221247 (80040101) This window has already been registered as a drop
target.
-2147221246 (80040102) Invalid window handle.
-2147221232 (80040110) Class does not support aggregation (or class
object is remote).
-2147221231 (80040111) ClassFactory cannot supply requested class.
-2147221184 (80040140) Error drawing view.
-2147221168 (80040150) Could not read key from registry.
-2147221167 (80040151) Could not write key to registry.
-2147221166 (80040152) Could not find the key in the registry.
-2147221165 (80040153) Invalid value for registry.
-2147221164 (80040154) Class not registered.
-2147221163 (80040155) Interface not registered.
-2147221136 (80040170) Cache not updated.
-2147221120 (80040180) No verbs for OLE object.
-2147221119 (80040181) Invalid verb for OLE object.
-2147221088 (800401A0) Undo is not available.
-2147221087 (800401A1) Space for tools is not available.
-2147221056 (800401C0) OLESTREAM Get method failed.
-2147221055 (800401C1) OLESTREAM Put method failed.
-2147221054 (800401C2) Contents of the OLESTREAM not in correct format.
-2147221053 (800401C3) There was an error in a Windows GDI call while
converting the bitmap to a DIB.
-2147221052 (800401C4) Contents of the IStorage not in correct format.
-2147221051 (800401C5) Contents of IStorage is missing one of the
standard streams.
-2147221050 (800401C6) There was an error in a Windows GDI call while
converting the DIB to a bitmap.
-2147221040 (800401D0) OpenClipboard Failed.
-2147221039 (800401D1) EmptyClipboard Failed.
-2147221038 (800401D2) SetClipboard Failed.
-2147221037 (800401D3) Data on clipboard is invalid.
-2147221036 (800401D4) CloseClipboard Failed.
-2147221024 (800401E0) Moniker needs to be connected manually.
-2147221023 (800401E1) Operation exceeded deadline.
-2147221022 (800401E2) Moniker needs to be generic.
-2147221021 (800401E3) Operation unavailable.
-2147221020 (800401E4) Invalid syntax.
-2147221019 (800401E5) No object for moniker.
-2147221018 (800401E6) Bad extension for file.
-2147221017 (800401E7) Intermediate operation failed.
-2147221016 (800401E8) Moniker is not bindable.
-2147221015 (800401E9) Moniker is not bound.
-2147221014 (800401EA) Moniker cannot open file.
-2147221013 (800401EB) User input required for operation to succeed.
-2147221012 (800401EC) Moniker class has no inverse.
-2147221011 (800401ED) Moniker does not refer to storage.
-2147221010 (800401EE) No common prefix.
-2147221009 (800401EF) Moniker could not be enumerated.
-2147221008 (800401F0) CoInitialize has not been called.
-2147221007 (800401F1) CoInitialize has already been called.
-2147221006 (800401F2) Class of object cannot be determined.
-2147221005 (800401F3) Invalid class string.
-2147221004 (800401F4) Invalid interface string.
-2147221003 (800401F5) Application not found.
-2147221002 (800401F6) Application cannot be run more than once.
-2147221001 (800401F7) Some error in application program.
-2147221000 (800401F8) DLL for class not found.
-2147220999 (800401F9) Error in the DLL.
-2147220998 (800401FA) Wrong OS or OS version for application.
-2147220997 (800401FB) Object is not registered.
-2147220996 (800401FC) Object is already registered.
-2147220995 (800401FD) Object is not connected to server.
-2147220994 (800401FE) Application was launched but it didn't register a
class factory.
-2147220993 (800401FF) Object has been released.
-2146959359 (80080001) Attempt to create a class object failed.
-2146959358 (80080002) OLE service could not bind object.
-2146959357 (80080003) RPC communication failed with OLE service.
-2146959356 (80080004) Bad path to object.
-2146959355 (80080005) Server execution failed.
-2146959354 (80080006) OLE service could not communicate with the object
server.
-2146959353 (80080007) Moniker path could not be normalized.
-2146959352 (80080008) Object server is stopping when OLE service
contacts it.
-2146959351 (80080009) An invalid root block pointer was specified.
-2146959344 (80080010) An allocation chain contained an invalid link
pointer.
-2146959343 (80080011) The requested allocation size was too large.
-2147352575 (80020001) Unknown interface.
-2147352573 (80020003) Member not found.
-2147352572 (80020004) Parameter not found.
-2147352571 (80020005) Type mismatch.
-2147352570 (80020006) Unknown name.
-2147352569 (80020007) No named arguments.
-2147352568 (80020008) Bad variable type.
-2147352567 (80020009) Exception occurred.
-2147352566 (8002000A) Out of present range.
-2147352565 (8002000B) Invalid index.
-2147352564 (8002000C) Unknown language.
-2147352563 (8002000D) Memory is locked.
-2147352562 (8002000E) Invalid number of parameters.
-2147352561 (8002000F) Parameter not optional.
-2147352560 (80020010) Invalid callee.
-2147352559 (80020011) Does not support a collection.
-2147319786 (80028016) Buffer too small.
-2147319784 (80028018) Old format or invalid type library.
-2147319783 (80028019) Old format or invalid type library.
-2147319780 (8002801C) Error accessing the OLE registry.
-2147319779 (8002801D) Library not registered.
-2147319769 (80028027) Bound to unknown type.
-2147319768 (80028028) Qualified name disallowed.
-2147319767 (80028029) Invalid forward reference, or reference to
uncompiled type.
-2147319766 (8002802A) Type mismatch.
-2147319765 (8002802B) Element not found.
-2147319764 (8002802C) Ambiguous name.
-2147319763 (8002802D) Name already exists in the library.
-2147319762 (8002802E) Unknown LCID.
-2147319761 (8002802F) Function not defined in specified DLL.
-2147317571 (800288BD) Wrong module kind for the operation.
-2147317563 (800288C5) Size may not exceed 64K.
-2147317562 (800288C6) Duplicate ID in inheritance hierarchy.
-2147317553 (800288CF) Incorrect inheritance depth in standard OLE
hmember.
-2147316576 (80028CA0) Type mismatch.
-2147316575 (80028CA1) Invalid number of arguments.
-2147316574 (80028CA2) I/O Error.
-2147316573 (80028CA3) Error creating unique tmp file.
-2147312566 (80029C4A) Error loading type library/DLL.
-2147312509 (80029C83) Inconsistent property functions.
-2147312508 (80029C84) Circular dependency between types/modules.
-2147287039 (80030001) Unable to perform requested operation.
-2147287038 (80030002) %1 could not be found.
-2147287037 (80030003) The path %1 could not be found.
-2147287036 (80030004) There are insufficient resources to open another
file.
-2147287035 (80030005) Access Denied.
-2147287034 (80030006) Attempted an operation on an invalid object.
-2147287032 (80030008) There is insufficient memory available to
complete operation.
-2147287031 (80030009) Invalid pointer error.
-2147287022 (80030012) There are no more entries to return.
-2147287021 (80030013) Disk is write-protected.
-2147287015 (80030019) An error occurred during a seek operation.
-2147287011 (8003001D) A disk error occurred during a write operation.
-2147287010 (8003001E) A disk error occurred during a read operation.
-2147287008 (80030020) A share violation has occurred.
-2147287007 (80030021) A lock violation has occurred.
-2147286960 (80030050) %1 already exists.
-2147286953 (80030057) Invalid parameter error.
-2147286928 (80030070) There is insufficient disk space to complete
operation.
-2147286800 (800300F0) Illegal write of non-simple property to simple
property set.
-2147286790 (800300FA) An API call exited abnormally.
-2147286789 (800300FB) The file %1 is not a valid compound file.
-2147286788 (800300FC) The name %1 is not valid.
-2147286787 (800300FD) An unexpected error occurred.
-2147286786 (800300FE) That function is not implemented.
-2147286785 (800300FF) Invalid flag error.
-2147286784 (80030100) Attempted to use an object that is busy.
-2147286783 (80030101) The storage has been changed since the last
commit.
-2147286782 (80030102) Attempted to use an object that has ceased to
exist.
-2147286781 (80030103) Can't save.
-2147286780 (80030104) The compound file %1 was produced with an
incompatible version of storage.
-2147286779 (80030105) The compound file %1 was produced with a newer
version of storage.
-2147286778 (80030106) Share.exe or equivalent is required for
operation.
-2147286777 (80030107) Illegal operation called on non-file based
storage.
-2147286776 (80030108) Illegal operation called on object with extant
marshallings.
-2147286775 (80030109) The docfile has been corrupted.
-2147286768 (80030110) OLE32.DLL has been loaded at the wrong address.
-2147286527 (80030201) The file download was aborted abnormally. The
file is incomplete.
-2147286526 (80030202) The file download has been terminated.
-2147418111 (80010001) Call was rejected by callee.
-2147418110 (80010002) Call was canceled by the message filter.
-2147418109 (80010003) The caller is dispatching an intertask
SendMessage call and cannot call out via
PostMessage.
-2147418108 (80010004) The caller is dispatching an asynchronous call
and cannot make an outgoing call on behalf of
this call.
-2147418107 (80010005) It is illegal to call out while inside message
filter.
-2147418106 (80010006) The connection terminated or is in a bogus state
and cannot be used any more. Other connections
are still valid.
-2147418105 (80010007) The callee (server [not server application]) is
not available and disappeared; all connections
are invalid. The call may have executed.
-2147418104 (80010008) The caller (client) disappeared while the callee
(server) was processing a call.
-2147418103 (80010009) The data packet with the marshalled parameter
data is incorrect.
-2147418102 (8001000A) The call was not transmitted properly; the
message queue was full and was not emptied after
yielding.
-2147418101 (8001000B) The client (caller) cannot marshal the parameter
data - low memory, etc.
-2147418100 (8001000C) The client (caller) cannot unmarshal the return
data - low memory, etc.
-2147418099 (8001000D) The server (callee) cannot marshal the return
data - low memory, etc.
-2147418098 (8001000E) The server (callee) cannot unmarshal the
parameter data - low memory, etc.
-2147418097 (8001000F) Received data is invalid; could be server or
client data.
-2147418096 (80010010) A particular parameter is invalid and cannot be
(un)marshalled.
-2147418095 (80010011) There is no second outgoing call on same channel
in DDE conversation.
-2147418094 (80010012) The callee (server [not server application]) is
not available and disappeared; all connections
are invalid. The call did not execute.
-2147417856 (80010100) System call failed.
-2147417855 (80010101) Could not allocate some required resource
(memory, events, ...)
-2147417854 (80010102) Attempted to make calls on more than one thread
in single threaded mode.
-2147417853 (80010103) The requested interface is not registered on the
server object.
-2147417852 (80010104) RPC could not call the server or could not return
the results of calling the server.
-2147417851 (80010105) The server threw an exception.
-2147417850 (80010106) Cannot change thread mode after it is set.
-2147417849 (80010107) The method called does not exist on the server.
-2147417848 (80010108) The object invoked has disconnected from its
clients.
-2147417847 (80010109) The object invoked chose not to process the call
now. Try again later.
-2147417846 (8001010A) The message filter indicated that the application
is busy.
-2147417845 (8001010B) The message filter rejected the call.
-2147417844 (8001010C) A call control interfaces was called with invalid
data.
-2147417843 (8001010D) An outgoing call cannot be made since the
application is dispatching an input-synchronous
call.
-2147417842 (8001010E) The application called an interface that was
marshalled for a different thread.
-2147417841 (8001010F) CoInitialize has not been called on the current
thread.
-2147417840 (80010110) The version of OLE on the client and server
machines does not match.
-2147417839 (80010111) OLE received a packet with an invalid header.
-2147417838 (80010112) OLE received a packet with an invalid extension.
-2147417837 (80010113) The requested object or interface does not exist.
-2147417836 (80010114) The requested object does not exist.
-2147417835 (80010115) OLE has sent a request and is waiting for a
reply.
-2147417834 (80010116) OLE is waiting before retrying a request.
-2147417833 (80010117) Call context cannot be accessed after call
completed.
-2147417832 (80010118) Impersonate on unsecured calls is not supported.
-2147417831 (80010119) Security must be initialized before any
interfaces are marshalled or unmarshalled. It
cannot be changed once initialized.
-2147417830 (8001011A) No security packages are installed on this
machine or the user is not logged on or there are
no compatible security packages between the
client and server.
-2147417829 (8001011B) Access is denied.
-2147417828 (8001011C) Remote calls are not allowed for this process.
-2147417827 (8001011D) The marshalled interface data packet (OBJREF) has
an invalid or unknown format.
-2147352577 (8001FFFF) An internal error occurred.
-2146893823 (80090001) Bad UID.
-2146893822 (80090002) Bad Hash.
-2146893821 (80090003) Bad Key.
-2146893820 (80090004) Bad Length.
-2146893819 (80090005) Bad Data.
-2146893818 (80090006) Invalid Signature.
-2146893817 (80090007) Bad Version of provider.
-2146893816 (80090008) Invalid algorithm specified.
-2146893815 (80090009) Invalid flags specified.
-2146893814 (8009000A) Invalid type specified.
-2146893813 (8009000B) Key not valid for use in specified state.
-2146893812 (8009000C) Hash not valid for use in specified state.
-2146893811 (8009000D) Key does not exist.
-2146893810 (8009000E) Insufficient memory available for the operation.
-2146893809 (8009000F) Object already exists.
-2146893808 (80090010) Access denied.
-2146893807 (80090011) Object was not found.

-2146893806 (80090012) Data already encrypted.
-2146893805 (80090013) Invalid provider specified.
-2146893804 (80090014) Invalid provider type specified.
-2146893803 (80090015) Provider's public key is invalid.
-2146893802 (80090016) Keyset does not exist.
-2146893801 (80090017) Provider type not defined.
-2146893800 (80090018) Provider type as registered is invalid.
-2146893799 (80090019) The keyset is not defined.
-2146893798 (8009001A) Keyset as registered is invalid.
-2146893797 (8009001B) Provider type does not match registered value.
-2146893796 (8009001C) The digital signature file is corrupt.
-2146893795 (8009001D) Provider DLL failed to initialize correctly.
-2146893794 (8009001E) Provider DLL could not be found.
-2146893793 (8009001F) The Keyset parameter is invalid.
-2146893792 (80090020) An internal error occurred.
-2146893791 (80090021) A base error occurred.
-2146762751 (800B0001) The specified trust provider is not known on this
system.
-2146762750 (800B0002) The trust verification action specified is not
supported by the specified trust provider.
-2146762749 (800B0003) The form specified for the subject is not one
supported or known by the specified trust
provider.
-2146762748 (800B0004) The subject is not trusted for the specified
action.
-2146762747 (800B0005) Error due to problem in ASN.1 encoding process.
-2146762746 (800B0006) Error due to problem in ASN.1 decoding process.
-2146762745 (800B0007) Reading / writing Extensions where Attributes are
appropriate, and visa versa.
-2146762744 (800B0008) Unspecified cryptographic failure.
-2146762743 (800B0009) The size of the data could not be determined.
-2146762742 (800B000A) The size of the indefinite-sized data could not
be determined.
-2146762741 (800B000B) This object does not read and write self-sizing
data.
-2146762496 (800B0100) No signature was present in the subject.
-2146762495 (800B0101) A required certificate is not within its validity
period.
-2146762494 (800B0102) The validity periods of the certification chain
do not nest correctly.
-2146762493 (800B0103) A certificate that can only be used as an
end-entity is being used as a CA or visa versa.
-2146762492 (800B0104) A path length constraint in the certification
chain has been violated.
-2146762491 (800B0105) An extension of unknown type that is labeled
'critical' is present in a certificate.
-2146762490 (800B0106) A certificate is being used for a purpose other
than that for which it is permitted.
-2146762489 (800B0107) A parent of a given certificate in fact did not
issue that child certificate.
-2146762488 (800B0108) A certificate is missing or has an empty value
for an important field, such as a subject or
issuer name.
-2146762487 (800B0109) A certification chain processed correctly, but
terminated in a root certificate which isn't
trusted by the trust provider.
-2146762486 (800B010A) A chain of certs didn't chain as they should in a
certain application of chaining.
Shot alternate link for this article: Error List from WINERROR.H

Comments 沒有留言 »

因为要在vc中连接数据库,所以在CMyApp::InitInstance()中调用了AfxOleInit(),但是不想,程序在Debug模式刚开始启动的时候报错,调试得出错的断言为

 _AFX_THREAD_STATE* pState = AfxGetThreadState();
 ASSERT(!pState->m_bNeedTerm); // calling it twice?

也就是说,该函数可能被执行了两次,但是搜索整个工程并没有发现啊,于是吧AfxOleInit()前移到InitInstance的最前面,发现没有报错,不断调整,定位到ProcessShellCommand(cmdInfo)这个函数。在此之后pState->m_bNeedTerm被修改。查找这个函数的源代码,

BOOL CWinApp::ProcessShellCommand(CCommandLineInfo& rCmdInfo)
{
 BOOL bResult = TRUE;
 switch (rCmdInfo.m_nShellCommand)
 {
 case CCommandLineInfo::FileNew:
  if (!AfxGetApp()->OnCmdMsg(ID_FILE_NEW, 0, NULL, NULL))
   OnFileNew();
  if (m_pMainWnd == NULL)
   bResult = FALSE;
  break;

  // If we’ve been asked to open a file, call OpenDocumentFile()

 case CCommandLineInfo::FileOpen:
  if (!OpenDocumentFile(rCmdInfo.m_strFileName))
   bResult = FALSE;
  break;

  // If the user wanted to print, hide our main window and
  // fire a message to ourselves to start the printing

………
}

在这里,会执行红色部分,由于我用了CHtmlView文档类,所以在新建时,会调用AfxOleInit(),才导致后面重复调用….呵呵

后来查查微软的文档,其中有:

Why Is MFC Being So ASSERTive?

Dear Dr. GUI,

I saw your article on using COM objects with smart pointers, and I have attempted to use them without success!

I have an MFC SDI application that is based on CHTMLView. I want to use smart pointers to wrap interfaces in the mshtml.tlb type library. Based on your article, I decided to use smart pointers because it looked easy:

#import <mshtml.tlb>

CMyAppView::LoadData()
{
AfxOleInit(); // Initialize the COM library

MSHTML::IHTMLDocument2Ptr pIDoc;
MSHTML::IHTMLElementCollectionPtr pICollection;

pIDoc = GetHtmlDocument();
pICollection = pIDoc->Getall();

//use the collection
int nLength = pICollection->length;
}

But when I run my app, it asserts on the AfxOleInit() call like this:

Debug Assertion Failed!

File: oleinit.cpp

Line: 54

Is there something I have missed in my code?

Regards,

Mark Reed

Dr. GUI replies:

Dr. GUI is flattered that you have taken his advice from previous columns. The good doctor still highly recommends using smart pointers! Unfortunately, the problem you are having with AfxOleInit() is preventing you from even experimenting with their use. So, the doctor has done a triage with his residents and has a diagnosis and a surgical repair that will help with future MFC debug assertions.

The good doctor is convinced that calling AfxOleInit() is necessary when using smart pointers in an MFC application. AfxOleInit() initializes the COM library and should only be called once, preferably at the beginning of your application.

Although it may look like a crash, this debug assertion is much better! Assertions proactively encourage good code health, because they warn you of coding errors that could lead to an actual crash or unexpected behavior. Even better, the condition that causes the assertion can lead directly to the cause of the problem in your code. It follows logically that the first step in your case is to look at the MFC source code (located in ".\VC98\MFC\SRC"). Run your application in the Visual C++ debugger by pressing the F5 key. When you get the debug assertion error, click the Retry button to debug. This opens OleInit.cpp and takes you to the source of the assertion inside the AfxOleInit() function, which looks like this:

ASSERT(!pState->m_bNeedTerm);    // calling it twice?

See the comment? The source code is giving you a hint that this method may be asserting because you are calling AfxOleInit() more than once. But the good doctor went through every line of his code and he is only calling it in our method call. Press the ALT+7 keys to bring up the callstack window. It shows that this assertion does generate from your CMyAppView::LoadData function. How can we know if someone else calls AfxOleInit() before we do?

The trick is to surgically implant a breakpoint in the MFC source code at the very first line of AfxOleInit() (press F9 on that line) and start the application in the debugger again. When the breakpoint is hit, look at the top few lines of the callstack:

AfxOleInit()
COleControlSite::CreateControl(Â…)
Â…
CHtmlView::Create(Â…)

Now, it’s more obvious! Because your view class derives from CHtmlView rather than CView, the CHtmlView::Create() method needs to create a Web Browser control. But, of course, first it calls AfxOleInit() for you.

Phew! That was a lot of work to find out that we don’t need to call AfxOleInit() at all in an MFC application that uses CHtmlView. But hopefully this demonstrates the tremendous benefit in using both the MFC source code and the callstack window. Dr. GUI recommends applying the same techniques to any future debug assertion failures.

This is what the good doctor calls a neat surgery. Your healing time will be negligible.

该段内容大致与我遇到的问题相同。

但是,当我在其中一个对话框类内定义_ConnectionPtr类型成员变量的时候,因为MFC构造各种对话框类型在处理程序命令行参数之前,此时会报错,因为COM未初始化,在我的程序中比较简单,不使用成员变量也可以解决问题,因为局部变量在运行时创建…此时COM已经初始化。对于必须使用成员函数的情况,把AfxOleInit()调用放在ProcessShellCommand()前即可,而并非简单的“That was a lot of work to find out that we don’t need to call AfxOleInit() at all in an MFC application that uses CHtmlView.” 这也算是对microsoft的DR GUI的一点补充吧。一直有个疑问:不知道这个DR是博士,还是“医生”。

Shot alternate link for this article: AfxoleInit()的一个错误(oleinit.cpp第54行)的简要分析

Comments 一个回复 »