简体   繁体   English

如何找出GetObject失败的原因?

[英]How to find out the reason why GetObject failed?

According to MSDN, GetObject returns 0 on failure. 根据MSDN, GetObject失败时返回0。 It does not say how to get additional information about the failure. 它没有说如何获得有关故障的其他信息。

I've tried GetLastError , but it looks like it does not reflect the previous failure and returns 0 (ie ERROR_SUCCESS ) instead. 我已经尝试过GetLastError ,但是看起来它不能反映先前的失败,而是返回0(即ERROR_SUCCESS )。

How do I get the failure reason when GetObject fails? GetObject失败时如何获取失败原因?

According to the documentation GetObject will not set the last error code. 根据文档, GetObject不会设置最后的错误代码。 This is not necessary either, since you can easily deduce, which parameter is wrong: 这也不是必须的,因为您可以轻松推断出哪个参数是错误的:

If a call to GetObject fails passing NULL for lpvObject , you know the handle is wrong (either a handle to an object that no longer exists, or is of an unsupported type). 如果对GetObject的调用未能为lpvObject传递NULL ,则您将知道该句柄是错误的(要么是不再存在的对象的句柄,要么是类型不受支持的句柄)。

If the previous call succeeded, and a following call with the same GDI object handle fails, you know that you are passing an inappropriate buffer (either too small, or not properly aligned on a 4-byte boundary). 如果前一个调用成功,而后一个具有相同GDI对象句柄的调用失败,则说明您正在传递不合适的缓冲区(太小或在4字节边界上未正确对齐)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM