winformsmfczlibocx

WinForms apps can not successfully import images exported from MFC apps


INTRODUCTION AND RELEVANT INFORMATION:

We have MFC OCX control written in C++ that exports images into compressed MFC CArchive (compressing the archive with ZLib).
OCX control can also import those exported images (decompressing them with ZLib into CArchive, rendering CArchive afterward on it's client area).
It is used in several crucial applications, some written in MFC and some in WinForms.

PROBLEM:

WinForms apps can not successfully import images exported from MFC apps.
Importing images exported from WinForms into MFC works fine.
Exporting from MFC and importing back into MFC works fine.
Exporting from WinForms and importing back into WinForms works fine.

MVCE:

I have made small demo OCX control and small MFC and WinForms consumers that illustrate the problem.
GitHub link is here.

MY EFFORTS:

Debugging shows that ReadImagesFromCArchive(...) call in the DemoOCX app fails, to be more specific CImageList::Read(...).
Sadly, I found no way to debug into CImageList::Read(...).
I have tried to figure out how Read works under the hood and stumbled upon this.
After enabling Visual Styles in DemoOCX and consumer apps, everything worked.

Enabling Visual Styles in the real apps did not fix the problem though.
WinForms apps have lots of 3rd party components, mostly OCX. Some of them still have old look and feel.

QUESTION:

  1. Is there a way to rewrite the code in the DemoOCX so enabling Visual Styles is not required?

    If there is, can you please instruct me how to do it?

  2. If you can offer alternative to the above approach, I will accept it.

    I am open, and grateful, for everything since I do not know how to start tackling this problem.


Solution

  • Note: This is more of an extended comment than an answer, but your linked project yielded several build errors when I tried it, and I gave up trying to fix all the issues to confirm if the following is the issue.

    I have tried to figure out how Read works under the hood and stumbled upon this.

    You have misinterpreted the intent of:

    ImageList_WriteEx function (commctrl.h)-Remarks

    To use ImageList_WriteEx, the application must specify Comctl32.dll version 6 in the manifest. For more information on manifests, see Enabling Visual Styles.

    It is not implying that you need to enable visual styles, but rather that your project needs a manifest file that specifies using Comctl32.dll version 6 and that "Enabling Visual Styles" documentation tells how to create the manifest.

    In the OCXTesterCS project, add a manifest file (Project Menu->Add New Item->Select "Application Manifest File (Windows Only)"; accept the default name of "app.manifest").

    At the end of this file you will find this block:

      <!--
      <dependency>
        <dependentAssembly>
          <assemblyIdentity
              type="win32"
              name="Microsoft.Windows.Common-Controls"
              version="6.0.0.0"
              processorArchitecture="*"
              publicKeyToken="6595b64144ccf1df"
              language="*"
            />
        </dependentAssembly>
      </dependency>
      -->
    

    Delete the wrapping comment tags (<!-- and -->) to enable and save the file.