COM+中HResult错误代码含义???

cfm999 2002-12-30 04:56:18
(1)什么错误表示服务器失败?
(2)数据库(SQL Server, ADO)错误代码与HResult关系?
(3)那些范围可以自定义使用?
...全文
763 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
cfm999 2003-01-09
  • 打赏
  • 举报
回复
先结帐了吧,以后在开贴请教,谢谢!
cfm999 2003-01-02
  • 打赏
  • 举报
回复
to Raptor(猛禽) and del_c_sharp(摩托~◎~◎~◎):

在有理由解脱自己的时候,你们还在网上,为我等提供帮助,
非常感谢!!! 而我睡了一个懒觉,不好意思。

今天继续工作,我试试看:
主要是确定服务器失败,以便做容错处理。
del_c_sharp 2003-01-01
  • 打赏
  • 举报
回复
find an anwser:

server
-----------------
uses ComServ;

const
CODE_BASE = $200; //recommended codes are from 0x0200 - 0xFFFF

procedure TFoo.Bar;
begin
//can be assigned once (globally) from somewhere
ComServer.HelpFileName := 'HelpFile.hlp'; //help file
//raise error: message='Error Message', number=5 + CODE_BASE, help context=1
raise EOleSysError.Create (
'Error Message', //error message
ErrorNumberToHResult (5 + CODE_BASE), //HRESULT
1 //help context
);
end;

function ErrorNumberToHResult (ErrorNumber : integer) : HResult;
const
SEVERITY_ERROR = 1;
FACILITY_ITF = 4;
begin
Result := (SEVERITY_ERROR shl 31) or (FACILITY_ITF shl 16) or word (ErrorNumber);
end;
-----------------
client
-----------------
const
CODE_BASE = $200; //recommended codes are from 0x0200 - 0xFFFF

procedure CallFooBar;
var
Foo : IFoo;
begin
Foo := CoFoo.Create;
try
Foo.Bar;
except
on E : EOleException do
ShowMessage ('Error message: ' + E.Message + #13 +
'Error number: ' + IntToStr (HResultToErrorNumber (E.ErrorCode) - CODE_BASE) + #13 +
'Source: ' + E.Source + #13 +
'HelpFile: ' + E.HelpFile + #13 +
'HelpContext: ' + IntToStr (E.HelpContext)
);
end;
end;

function HResultToErrorNumber (hr : HResult) : integer;
begin
Result := (hr and $FFFF);
end;
猛禽 2002-12-31
  • 打赏
  • 举报
回复
最好的办法是把异常包装为HResult返回(DELPHI的SAFECALL自动实现这一功能)
del_c_sharp 2002-12-31
  • 打赏
  • 举报
回复
想法不错~不过可以直接自定义一个out参数吧,比这样要稳定而且好控制吧
cfm999 2002-12-31
  • 打赏
  • 举报
回复
to: del_c_sharp(摩托~◎~◎~◎),多谢!

请问HResult整体是如何划分的?

我的目的:
(1)我想确定服务器失败,总不能按李维所例,
凡OleSysError都视为服务器失败吧。
(2)数据库操作异常时错误代码是否转换成对应的HResult,
以便在Client判断。
(3)用系统未使用的错误代码,自定义含义,以便在Client
做出相应处理。
del_c_sharp 2002-12-30
  • 打赏
  • 举报
回复
以前没有仔细考虑过:
The following HRESULT values are defined in the System unit:

Constant Hex. Value Meaning

S_OK 00000000 No error. In some APIs, S_OK indicates a successful operation with a return value of true.
S_FALSE 00000001 No error, but operation did not produce a useful result. In some APIs, S_FALSE indicates a successful operation with a return value of false.
E_INTERFACE 80004002 Interface not supported.
E_UNEXPECTED 8000FFFF Catastrophic failure
E_NOTIMPL 80004001 Operation not implemented

Note that in the above constant names, the S_ and E_ prefixes correspond to the value of the Severity bit.

The following HRESULT values are defined in the Types unit (Linux) or Windows unit (Windows):

Constant Hex. Value Meaning

E_FAIL 80004005 Unspecified error.

STG_E_INVALIDFUNCTION 80030001 Unable to perform storage management function.
STG_E_FILENOTFOUND 80030002 File not found.
STG_E_PATHNOTFOUND 80030003 Path not found.
STG_E_TOOMANYOPENFILES 80030004 Insufficient resources to open another file.
STG_E_ACCESSDENIED 80030005 Access denied.
STG_E_INSUFFICIENTMEMORY 80030008 Insufficient memory to complete storage operation.
STG_E_NOMOREFILES 80030012 No more files to return.
STG_E_DISKISWRITEPROTECTED 80030013 Disk is write-protected.

STG_E_SEEKERROR 80030019 Error during seek.
STG_E_LOCKVIOLATION 80030021 Lock violation.
STG_E_FILEALREADYEXISTS 80030050 File already exists.
STG_E_INVALIDPARAMETER 80030057 Invalid parameter.
STG_E_MEDIUMFULL 80030070 Disk full.
STG_E_INVALIDNAME 800300FC Invalid name.
Note that an additional prefix is added to HRESULT constant names to indicate a non-zero Facility Code. In the above examples, the STG_ prefix and the Facility Code 3 both indicate storage errors.

和数据库的errorcode应该没有直接的联系

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧