Link to home
Start Free TrialLog in
Avatar of isnoend2001
isnoend2001Flag for United States of America

asked on

questions on InitCommonControlsEx

I have had an ongoing problem that rarely occurs on some systems.
The error is runtime 0 and my app does not even start. I have narrowed it down to
InitCommonControlsEx. i have been using code from vbaccelerator.
http://www.vbaccelerator.com/home/vb/code/libraries/xp_visual_styles/using_xp_visual_styles_in_vb/article.asp
InitCommonControlsVB is the first line in sub Main, so it is called before anything else. See code.
I have not been using the line :On Error GoTo 0 and do not understand the "On Error Resume next"
which i never use in any of my code. My app does include the manifest.
I do not understand the usage of On Error resume next, then the On error Goto 0. Can someone explain ? Do i need to include the Comctl32.dll in my setup? I have noticed that this dll is not even on my system, only a Comctl32.ocx
Public Type tagInitCommonControlsEx
   lngSize As Long
   lngICC As Long
End Type
Public Declare Function InitCommonControlsEx Lib "comctl32.dll" (iccex As tagInitCommonControlsEx) As Boolean
Const ICC_USEREX_CLASSES = &H200

Public Function InitCommonControlsVB() As Boolean
    On Error Resume Next
   Dim iccex As tagInitCommonControlsEx
   ' Ensure CC available:
   With iccex
       .lngSize = LenB(iccex)
       .lngICC = ICC_USEREX_CLASSES
   End With
   InitCommonControlsEx iccex
   InitCommonControlsVB = (err.Number = 0)
   On Error GoTo 0
    
    End Function

Open in new window

Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

<< Do i need to include the Comctl32.dll in my setup >>
Nope. This file is part of windows so you don't want to include it or copy over the original in System32 directory.
The manifest that I use is in the code section below. You will notice it has support for Vista and later that with User Account Control(UAC).
You can try this manifest and let me know how it works for you.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity
        version="1.0.0.0"
        processorArchitecture="X86"
        name="app.name"
        type="win32"
      />
    <description> </description>
    <dependency>
      <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="*"
            publicKeyToken="6595b64144ccf1df"
            language="*"
          />
      </dependentAssembly>
    </dependency>

    <!-- Identify the application security requirements. -->
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
      <security>
        <requestedPrivileges>
          <requestedExecutionLevel
            level="asInvoker"
            uiAccess="false"/>
        </requestedPrivileges>
      </security>
    </trustInfo>
  </assembly>

Open in new window

BTW: You don't need that error checking at all, just make sure the application runs on XP or later.
Avatar of isnoend2001

ASKER

thanks egl1044:
So you think it is the manifest causing the problem. When i combined my manifest with uac i had to remove the part " standalone="yes"?"
Have you installed this manifest on a lot of systems ?

<?xml version="1.0" encoding="UTF-8" ?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity
        version="1.0.0.0"
        processorArchitecture="*"
        name="MyApp"
        type="win32" />
    <description>Executable</description>
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                type="win32"
                name="Microsoft.Windows.Common-Controls"
                version="6.0.0.0"
                processorArchitecture="*"
                publicKeyToken="6595b64144ccf1df"
                language="*" />
        </dependentAssembly>
    </dependency>
    <!-- Identify the application security requirements. -->
    <ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-com:asm.v2">
      <ms_asmv2:security>
        <ms_asmv2:requestedPrivileges>
          <ms_asmv2:requestedExecutionLevel
            level="asInvoker"
            uiAccess="false"/>
          </ms_asmv2:requestedPrivileges>
         </ms_asmv2:security>
    </ms_asmv2:trustInfo>
</assembly>
I have been using that manifest since Vista was released. It's perfectly stable "as is" which means you shouldn't have to alter "standalone".  I don't know if it it's your manifest but it could be one of the reasons. Even the smallest XML error in the manifest can crash the application so this is why I recommended trying the manifest that I have always used.
You want to make sure that you ship comctl32.ocx and that it's located in your application directory folder with your manifest and application executable. This is the version 5.0 of the common controls. You want register the file on the system. This is the only version that works with XP style. The 5.0 only works because it's wrapped around the comctl32.dll the version 6.0 to my knowledge is completley independant.
Thanks egl1044
I tried your manifest and my app will not run
Okay. Well lets see your runtime code you have your application to use Sub Main at startup correct? Make sure no controls are inititated before you link to comctl32.dll. Can you post your exact module code?
BTW: I use the following with the manifest. ICC_(&H3FFF&)
'egl1044
Option Explicit

Private Const ICC_STANDARD_CLASSES = &H3FFF&

Private Type tagINITCOMMONCONTROLSEX
dwSize As Long
dwICC As Long
End Type

' Comctl32.dll (version 4.70 or later)
Private Declare Function InitCommonControlsEx Lib "Comctl32.dll" ( _
  ByRef lpInitCtrls As tagINITCOMMONCONTROLSEX) As Long


Public Sub Main()

  Dim icc As tagINITCOMMONCONTROLSEX
  icc.dwSize = Len(icc)
  icc.dwICC = ICC_STANDARD_CLASSES
  If InitCommonControlsEx(icc) Then
    Form1.Show' show UI
  End If
  
End Sub

Open in new window

My Sub Main is very lengthy with many subs, functions, splash screen etc .It never hits my error handler.
You mentioned i need to include comctl32.ocx in my setup. I haven't, but that could be the problem
it starts like this:
Sub Main()
10      InitCommonControlsVB
          Dim VeryFirstUse As Boolean          
          Dim AppExedate
           Dim HelpFileDate
           Dim MainDrive As String          
           Dim unregister As String
           Dim AppVersion As Integer
20       gFromSubMain = True          
           Dim Version As String, Response As Integer
           Dim mTmpLocalFile As String
           Dim WinVersion As String
         
30       On Error GoTo e
Okay. Yes you should ship the Comctl32.OCX but NOT Comctl32.DLL
Do you have any Public control reference in that same module with Sub Main()?
Let me just clear the last statement up, If your using the Common Controls 5.0 in your application you must ship and register Comctl32.OCX. If you don't then it's not required! I assumed you're using it correct?
I will just include the Comctl32.OCX in my setup. My setup will not overwrite any files that are already present. Not sure if i am using any Common Controls 5.0 my app is huge, how would i know?
ASKER CERTIFIED SOLUTION
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your help
isnoend2001,
Did you actually solve the issue or just accept ?  Did you have a reference in your project?
thanks egl1044
I did not have reference, but you answered my question about nitCommonControlsEx
I have an ocx that gets loaded in sub main. This ocx sends me any errors in my app wth the function-sub-form name and line numbers as well as the users pc info. This is sent to an online jmail on my website.
I moved the call to this to the top of sub main before the the call to  itCommonControlsEx. This error will  be sent if it still occurs, giving me more info. The error is really seldom and so far I only know of it happening is when someone tells me. I know it seldom happens because i also get an email with success on the first use. My app gets installed about 20 times a day. I f the problem continues I will be back and hopefully with more info. I probably should be using .icc.dwICC = ICC_STANDARD_CLASSES  like yours instead of lngICC = ICC_USEREX_CLASSES
Okay bud, Just wanted to check with you. It's hard to determine what might cause your problem without having the entire project to test but I would like that you get on the right track at best. You can always report back but I hope you find the root of the problem. I never had issues with the manifest, but I also never use third party controls. I don't want to suggest that is your problem here, only that I never "seen" a problem using the XP style manifest.