I'm using the MDL resource API to load and store user preferences. When I attempt to load resources the first time (before they have been saved) the load understandably fails. What puzzles me is the resulting mdlErrno. Here's my code...
mdlErrno
T* pUserPrefs = (T*)mdlResource_loadByAlias ( manager.FileHandle (), //userPrefsH typeId_, rscId_, alias); if (nullptr == pUserPrefs) { wchar_t msg [MessageLength]; switch (mdlErrno) { case MDLERR_RSCTYPEINVALID: // Possible if first time used swprintf_s (msg, MessageLength, L"%s UserPreferences::Load: invalid resource type", alias_.c_str ()); break; case MDLERR_RSCNOTFOUND: // Possible if first time used swprintf_s (msg, MessageLength, L"%s UserPreferences::Load: resource not found", alias_.c_str()); break; case MDLERR_RSCFILENOTFOUND: swprintf_s (msg, MessageLength, L"%s UserPreferences::Load: user preference file not found", alias_.c_str()); break; default: { swprintf_s (msg, MessageLength, L"%s UserPreferences::Load: unknown error %d", alias_.c_str(), mdlErrno); break; } } mdlOutput_messageCenter(OutputMessagePriority::Warning, msg, msg, OutputMessageAlert::Balloon); }
The message I receive for a non-existent mdlErrno is MDLERR_RSCTYPEINVALID. Why don't I receive MDLERR_RSCNOTFOUND?
MDLERR_RSCTYPEINVALID
MDLERR_RSCNOTFOUND
I should add that this behaviour is not new to CONNECT — it was the same with V8i. I just never got around to asking this question.
Hi Jon Summers,
So, using this simplified presentation of features/hierarchy from a programmers perspective "top down" and "return on/with first descriptive error", the the documented params and return (mdlErrno table) codes (more-or-less in order listed) makes some sense.
First, we need to validate all incoming parameter args given the above considerations noting Each param potentially might need to return/report MDLERR_INSUFMEMORY along the way.
Again, this is a simplified version and the implementation does have some additional provisions, but hopefully the isolation (layering) and order of return codes as documented can help understand with precision what File, Type, Id, and/or Alias cannot be found.
Let me know if you need something more, or have a simplified Test Case I can quickly test, validate, and file a defect if needed.
HTH,Bob
Answer Verified By: Jon Summers
Robert Hook said:Let me know if you need something more
Thanks for the detailed comments.
Robert Hook said:this is a simplified version
My resource handling is fine. I just wanted to understand the error code (mdlErrno) the first time we attempt to open a user preference resource.
Regards, Jon Summers LA Solutions