Results 1 to 10 of 10

Thread: [RESOLVED] Error on program close when using manifest file

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Resolved [RESOLVED] Error on program close when using manifest file

    Hi, I'm using this custom Listview control.

    When I close the app there are two errors:

    1) Window handle isn't subclassed.
    2) Project1 has encountered a problem and needs to close....

    The first error can simply be commented out, but I can't get rid of the second error, because it doesn't seem to be a code error. This second error only occurs when using a manifest file to get XP style.

    Does anybody know how get rid of that second error and still use the manifest file?

    (compile the project)
    Last edited by Chris001; Sep 12th, 2010 at 12:29 PM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Error on program close when using manifest file

    have you still got some subclassing instanced when you are closing?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: Error on program close when using manifest file

    To be honest, my knowledge about subclassing isn't good enough to understand all of that code. I simply copied over all classes/modules and everything works fine until I close the app. No subclassing code is called on the form.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Error on program close when using manifest file

    Chris, that custom listview definitely uses subclassing to in the scrollbar class. I haven't looked at the code thoroughly and maybe the Subclasser.cls is referenced in other parts of that project.

    I don't know if this will help at all, but try moving your code in form_load to Sub Main() in a module.
    Do you get the same problem if your listview contains just a few items, causing no scrollbars to be created?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: Error on program close when using manifest file

    The project above simply has an empty custom Listview on the form and no Listview code at all. The only form code is this and nothing else.

    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function InitCommonControls Lib "comctl32.dll" () As Long
    4.  
    5. Private Sub Form_Initialize()
    6.     InitCommonControls 'XP Theme
    7. End Sub

    I moved the code above to Main() in a module and the error still occurs.
    I even removed Subclasser.cls, Scrollbars.cls and ISubclass.cls from the project (basically removing all subclassing), commented out the related code on other classes and still the error occurs.

  6. #6
    Addicted Member
    Join Date
    Jul 2007
    Posts
    228

    Re: Error on program close when using manifest file

    Hi Chris:

    See if this helps.

    In the forms General Declarations add:

    Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" ( _
    ByVal lpLibFileName As String) As Long
    Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    Private lb As Long

    Then in the Form Initialize:

    lb = LoadLibrary("shell32.dll")
    DoEvents
    InitCommonControlsXP

    In the Form Unload be sure to include free library:

    FreeLibrary lb

    Tom

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Error on program close when using manifest file

    Ok, dumb question. Do you get the error placing a typical listview control on your form, not the custom listview.

    Also, you are using an obsolete API function. Here's a Sub Main() I often use, commented. Already appended the ICC_LISTVIEW_CLASSES below.
    Code:
    Private Declare Function InitCommonControlsEx Lib "comctl32.dll" (iccex As InitCommonControlsExStruct) As Boolean
    Private Declare Sub InitCommonControls Lib "comctl32.dll"()
    Private Type InitCommonControlsExStruct
        lngSize As Long
        lngICC As Long
    End Type
    
    Public Sub Main()
        Dim iccex As InitCommonControlsExStruct
        ' constant descriptions: http://msdn.microsoft.com/en-us/library/bb775507%28VS.85%29.aspx
        Const ICC_ANIMATE_CLASS As Long = &H80&
        Const ICC_BAR_CLASSES As Long = &H4&
        Const ICC_COOL_CLASSES As Long = &H400&
        Const ICC_DATE_CLASSES As Long = &H100&
        Const ICC_HOTKEY_CLASS As Long = &H40&
        Const ICC_INTERNET_CLASSES As Long = &H800&
        Const ICC_LINK_CLASS As Long = &H8000&
        Const ICC_LISTVIEW_CLASSES As Long = &H1&
        Const ICC_NATIVEFNTCTL_CLASS As Long = &H2000&
        Const ICC_PAGESCROLLER_CLASS As Long = &H1000&
        Const ICC_PROGRESS_CLASS As Long = &H20&
        Const ICC_TAB_CLASSES As Long = &H8&
        Const ICC_TREEVIEW_CLASSES As Long = &H2&
        Const ICC_UPDOWN_CLASS As Long = &H10&
        Const ICC_USEREX_CLASSES As Long = &H200&
        Const ICC_STANDARD_CLASSES As Long = &H4000&
        Const ICC_WIN95_CLASSES As Long = &HFF&
        Const ICC_ALL_CLASSES As Long = &HFDFF& ' combination of all values above
    
        With iccex
           .lngSize = LenB(iccex)
           .lngICC = ICC_STANDARD_CLASSES Or ICC_LISTVIEW_CLASSES
           ' if using Common Controls; add appropriate ICC_ constants for type of control you are using
           ' example if using CommonControls v5.0 Progress bar:
           ' .lngICC = ICC_STANDARD_CLASSES Or ICC_PROGRESS_CLASS
        End With
        On Error Resume Next ' error? Requires IEv3 or above
        InitCommonControlsEx iccex
        If Err Then 
            Err.Clear
            InitCommonControls ' try Win9x version
            If Err Then Err.Clear
        End If
        On Error GoTo 0
        '... show your main form next (i.e., Form1.Show)
    
    
    '** Tip 1: Avoid using VB Frames when applying XP/Vista themes
    '          In place of VB Frames, use pictureboxes instead.
    '** Tip 2: Avoid using Graphical Style property of buttons, checkboxes and option buttons
    '          Doing so will prevent them from being themed.
    
    End Sub
    Oh & remember to change your startup from your main form to Sub Main!
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: Error on program close when using manifest file

    Thank you, Tom Moran. That fixes the problem. No more "application has encountered a problem and needs to close...." error.

    Can you please explain to me what "LoadLibrary("shell32.dll")" exactly does?



    Thank you, LaVolpe. From now on I'll use your code. I didn't know that InitCommonControls is obsolete, because it seems to work fine on XP/Vista/7.

  9. #9
    Addicted Member
    Join Date
    Jul 2007
    Posts
    228

    Re: [RESOLVED] Error on program close when using manifest file

    Hi Chris:

    Glad it worked for you.

    This link will give you a pretty detailed view of what you experienced and why it happened and how the LoadLibrary helps solve the problem.

    http://www.vbaccelerator.com/home/vb...wn/article.asp

    There's even a second solution for the same problem.

    Tom

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: [RESOLVED] Error on program close when using manifest file

    Thank you very much for your help, Tom.

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