CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Posts
    4

    Unhappy Failure in AddStandardFormats of COlePasteSpecialDialog.

    I am working on code that was compiled under VC++ version 6 and moved to VC++ 2008. I am getting a crash from the COlePasteSpecialDialog.AddStandardFormats().

    Does anyone know the solution to this? The AddStandardFormats() loks like this:

    {
    // Note: only need to add Embedded Object because Embed Source is
    // automatically recognized by the paste special dialog implementation.
    ASSERT(_oleData.cfEmbeddedObject != NULL);
    AddFormat(_oleData.cfEmbeddedObject, TYMED_ISTORAGE, AFX_IDS_EMBED_FORMAT,
    TRUE, FALSE);

    // add link source if requested
    if (bEnableLink)
    {
    ASSERT(_oleData.cfLinkSource != NULL);
    AddFormat(_oleData.cfLinkSource, TYMED_ISTREAM, AFX_IDS_LINKSOURCE_FORMAT,
    TRUE, TRUE);
    }

    // add formats that can be used for 'static' items
    AddFormat(CF_METAFILEPICT, TYMED_MFPICT, AFX_IDS_METAFILE_FORMAT,
    FALSE, FALSE);
    AddFormat(CF_DIB, TYMED_HGLOBAL, AFX_IDS_DIB_FORMAT, FALSE, FALSE);
    AddFormat(CF_BITMAP, TYMED_GDI, AFX_IDS_BITMAP_FORMAT, FALSE, FALSE);
    }

    In one of the AddFormats calls ...

    ...
    LPTSTR lpszResult = _tcschr(szFormat, '\n');
    ENSURE(lpszResult != NULL); // must contain a newline
    *lpszResult = '\0';
    ++lpszResult; // one char past newline
    ...

    The lpszResult is NULL and thus the system crashes when the *lpszReslt = '\0' is executed. I do get an exception from the ENSURE()... but on the old compiler this AddStandardFormats() worked...anyone have an suggestion? Know how to resolve?

  2. #2
    Join Date
    Jun 2009
    Posts
    4

    Re: Failure in AddStandardFormats of COlePasteSpecialDialog.

    Further information:

    When the AddStandardFormats() calls

    AddFormat(CF_METAFILEPICT, TYMED_MFPICT, AFX_IDS_METAFILE_FORMAT,
    FALSE, FALSE);

    The CF_METAFILEPICT apparently does pass the AfxLoadString() call prior to where it fails.

    The code looks like:

    ...
    if (AfxLoadString(nFormatID, szFormat, _countof(szFormat)) == 0)
    AfxThrowResourceException();

    // the format and result strings are delimited by a newline
    LPTSTR lpszResult = _tcschr(szFormat, '\n');
    ENSURE(lpszResult != NULL); // must contain a newline
    *lpszResult = '\0';
    ...

    The is no newline in the string ...

    Does anyone know or see this problem?

  3. #3
    Join Date
    Jun 2009
    Posts
    4

    Smile Re: Failure in AddStandardFormats of COlePasteSpecialDialog.

    Found the problem. Record the answer here for anyone who maybe interested.

    The issue is that my application has it's own resource file and there was a added string id that was given the same value as AFX_IDS_METAFILE_FORMAT. This created the problem.


    Microsoft has restricted ranges that the resource file I have colides with. The fix if to give your ids values outside MS ranges.

    RESTRICTIONS!!!!! RANGES

    • By convention, the ID value of 0 is not used.

    • Windows implementation limitations restrict true resource IDs to be less than or equal to 0x7FFF [32767].

    • MFC's internal framework implementations reserve two ranges: 0x7000 [28672] through 0x7FFF [32767] and 0xE000 [57344] through 0xEFFF [61439].

    • Several Windows system commands use the range of 0xF000 [61440] through 0xFFFF [65535].

    • Control IDs of 1 through 7 are reserved for standard controls such as IDOK and IDCANCEL.

    • The range of 0x8000 [32768] through 0xFFFF [65535] for strings is reserved for menu prompts for commands.



    Thanks

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured