Solved

Crash due to comctl32.dll

Posted on 1997-11-09
9
793 Views
Last Modified: 2013-12-03
I'm writing a shell-extension dll, using property sheets.
Compiled under VC++ 5.0, it works fine.
If I try it on a machine where VC50 was never installed, it crashes while trying to create a property sheet.
I investigated and found that VC50 updates comctl32.dll to a newer version. The old version seems to cause the crash.
Is there anything I should change in my code?
Otherwise I guess the only solution would be to use InstallShield to update this dll.
0
Comment
Question by:yairh
9 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1408271
Just replace the dll.
0
 

Author Comment

by:yairh
ID: 1408272
The answer is unacceptable.
I know I have this option, but I'm looking for a more creative solution.
0
 
LVL 7

Expert Comment

by:galkin
ID: 1408273
New version of comctl32.dll(4.70 or 4.71) installed with IE3.0 or hire adds some new common controls and changes functionality of the existing ones( for example it adds flat style to the toolbar control, tracking style to the tooltip control etc.). If your application doesn't use any of these new features it must work fine, if it uses one of the new common controls you must be given kernel error "Undefined link...". If you use extended style of the old control I expect they should be ignored but still may cause some problem.
I also think your problem may be caused not comctl32.dll but oleaut32.dll and olepro32.dll. These DLLs are also updated and for example olepro32.dll is InProcServer32 for standard property pages and oleaut32.dll is responsible for OLE automation.So I suggest you updating these DLLs.
 
0
 

Author Comment

by:yairh
ID: 1408274
The problem is only with comctl32.dll.
Other DLLs have nothing to do with it.
Again, I don't want to update any DLL, since it complicates the software distribution.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 5

Expert Comment

by:y96andha
ID: 1408275
I think this KB article applies to your problem. Try making your resources read-write and see if it solves your problem.



PRB: CPropertySheet::DoModal() or Create() Causes an Exception

Last reviewed: September 15, 1997
Article ID: Q158552 The information in this article applies to:

•The Microsoft Foundation Classes (MFC) included with: - Microsoft Visual C++, 32-bit Edition, versions 4.0, 4.1, 4.2, 5.0







SYMPTOMS

Calling CPropertySheet::DoModal() or CPropertySheet::Create() in Windows 95 may cause an exception. The Output window displays a message that says the following:



   First-chance exception in <program.exe> (Comctl32.dll): 0xC0000005:
   Access Violation.




Newer versions (version 4.70) of the Comctl32.dll do not have this problem.





CAUSE

The CommCtl32.dll tries to modify the resources for the pages. Since the resources are normally in read-only sections this throws an Exception that can be caught in the application. However, if the application does not catch this exception then the OS will handle this exception correctly.





RESOLUTION

The first-chance exception can be ignored because it is safely handled by the operating system.

One way to prevent the exception from being thrown is to make the resources read/write. You can do this by adding a linker setting of "/SECTION:.rsrc,rw."

A second way to prevent the exception being thrown is to change the font of the pages so they are not "MS Sans Serif". MFC checks the dialog template font for the page. If it is not "MS Sans Serif" then it makes a copy of the resource in read/write memory, modifies the font and passes this to the C mCtl32.dll. So when the dll writes to the template for the page it is writing to read/write memory and hence exception is not thrown.

Another way to prevent the exception from affecting your application is not to have the call for creating the property sheet in a try/catch(...) block. Instead catch particular exceptions in the catch block.

If the property sheet is part of an OLE Automation Server that can be invoked through a method of the server then you have to make the resources read/write, using either of the first two methods described above, since OLE catches the exception.

NOTE: Making the resources Read/Write can cause the resources to be written to a page file.





STATUS

This behavior is by design.





MORE INFORMATION





Sample Code



   /* Compile options needed: default
   */

   /***** this code will cause unpredictable results *****/
   try
   {
       sheet.DoModal();
   }
   catch(...)
   {
   }

   /***** this code is OK *****/
   try
   {
       if (0 == sheet.DoModal())
           throw "DoModal() failed!";
   }
   catch(char * str)
   {
       TRACE ("Exception thrown: %s\n", str);
   }






REFERENCES

For more information, please see the following article in the Microsoft Knowledge Base:



   ARTICLE ID: Q126630
   TITLE     : Resource Sections are Read-only



Keywords          : MfcUI kbprg
Technology        : kbMfc
Version           : WINDOWS NT:4.0 4.1 4.2 5.0;
Platform          : NT WINDOWS
Issue type        : kbprb
0
 

Author Comment

by:yairh
ID: 1408276
Nice a thorough answer, but my problem is different.
I tried your solution, but it doesn't cure the problem.

I'm not using MFC.
The system crashed with a divide-error in user.exe.
0
 
LVL 8

Expert Comment

by:gelbert
ID: 1408277
Dump export table of comctl32.dll of old version ( it must be less then 4.70) and check if functions which you are using are supported by this version of DLL. You can use dumpbin.exe from VC++ 5.0
0
 
LVL 11

Accepted Solution

by:
alexo earned 70 total points
ID: 1408278
Yair,

As previously noted, you need to check the version of the comctl32.dll that the user has installed.

There is a function DllGetVersion() that allows you to do it but it is only available in versions 4.70 and up.  So, you have to "letachmen".

Here is a piece of code that works for me (C++):

// Use LoadLibrary() instead if you don't link statically to comctl32.dll
HMODULE hComctl = GetModuleHandle("comctl32");
if (hComctl == NULL)
    return FALSE;

DLLGETVERSIONPROC pGetVersion = (DLLGETVERSIONPROC) GetProcAddress(hComctl, "DllGetVersion");
if (pGetVersion == NULL)
    return FALSE;

DLLVERSIONINFO dllvi = { sizeof(DLLVERSIONINFO) };
HRESULT hrc = (pGetVersion)(&dllvi);
if (hrc < 0)
    return FALSE;

if (dllvi.dwMajorVersion < 4 || dllvi.dwMajorVersion == 4 && dllvi.dwMinorVersion < 70)
    return FALSE;

Now, there are currently 4 versions of comctl32.dll.

The original version 4.0 is obviously not good for you.

If your program requires 4.70, it will run on Win95-OSR2, NT4+SP3 or any system with IE3.01 and up installed.  It is also available from MS at premium.microsoft.com/download/support/mslfiles/COM32UPD.EXE

Version 4.71 requires IE4.0 installed and 4.72 requires IE4.01.
Those DLLs are *not* redistributable.

So, you can (legally) redistribute COM32UPD.EXE (325K) with your app or test for existance of comctl32.dll 4.70 and up and suggest that the user gets it from one of the sources I mentioned above.

0
 

Author Comment

by:yairh
ID: 1408279
Can you (ALEXO) send me an e-mail?
yairh@m-sys.com
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now