[CONNECT C++] mdlResource_loadByAlias()

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...

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?

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.

 

Parents
  • Hi ,

    After my quick review of the source code, maybe the best way to think of how mdlResource_loadByAlias is operating is by looking at the docs (of this function) as "developer implementation notes".  This function takes 4 required arguments and returns requested/found Data or NULL.  If an error is encountered mdlErrNo is used to return a result listed in the documentation table.  At this point let's stop a moment with that given (needed to implement), and add a simplified understanding of how the resource file system implements a rather good isolation system and flexibility needed/required granularity to resolve unique resources by:
    1. Resource File (full path and file name - filespec)
    2. Resource Type/Class (structured types)
    3. Resource ID (instances of stored data - Resource Type instances)
    4. Resource Alias (application specific "named" instances - in this case also using the ID provided)

    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.

    1. First arg RscFileHandle (validation)
      1. Null?
        1. Attempt internal lookup "by app", then "system" using alias if provided
      2. If really Null
        1. Return MDLERR_RSCFILENOTFOUND (typ, or MDLERR_INSFMEMORY not enough memory to load)

    2. Next arg RscType (validation)
      1. Unable to locate Resource Type/Class within found Resource File (MDLERR_RSCTYPEINVALID)
    3. Next arg Rscid (validation)
      1. Unable to find that specific Rsc ID instance of data requested
    4. Next arg Alias (validation)
      1. NOTE: Typically the owning MDL application name is used. I'm not sure what you provide, but for example see: e.g. Miscellaneous\steel\steel.cpp:2934
      2. Now time to do some secondary Alias param validation and return possibilities. In essence, identify A given RscId of a RscType for a RscFileH, for it's provided App/Alias name.  This looks through loaded App/Alias names first, then (being helpful) tries to provide from loaded System (by RscType and Rscid)
      3. Return MDLERR_RSCNOTFOUND; only after really trying - and not having an above return case/code to provide.

    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 

  • Let me know if you need something more

    Thanks for the detailed comments.

    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

Reply Children
No Data