dcsimg
Results 1 to 10 of 10

Thread: [RESOLVED] VB6 Unexpected Error on Windows 7

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    3

    Resolved [RESOLVED] VB6 Unexpected Error on Windows 7

    A forms-based VB6 application that runs on XP and Windows Server 2003 fails on Windows 7 with "Unexpected Error", even before the first form is launched.

    (I will be answering myself as I've just solved it. I just wanted to pass on the knowledge)

  2. #2

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    3

    Re: VB6 Unexpected Error on Windows 7

    The forms in this application were given high-resolution icons (256x256). Although VB6 can't make full use of these, it all seems to work well under XP and Windows Server 2003. The expectation was that it would yield better quality icons on Windows 7.

    However, a copy deployed on Windows 7 using the Package & Deployment Wizard would not launch. It immediately failed with "Unexpected Error", and with no clues as to the cause.

    The original application was re-compiled with smaller 72x72 icons, and re-deployed. This worked fine on Windows 7.

  3. #3
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    Re: VB6 Unexpected Error on Windows 7

    Did fixing the icon solve the problem with the "Unexpected Error"?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: VB6 Unexpected Error on Windows 7

    @ ACProctor

    Can you attach a sample of the icon(s)? 256x256 icons can be made to work flawlessly in XP and Win 7 just by rearranging the order of the internal images.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    3

    Re: VB6 Unexpected Error on Windows 7

    These icons were on the VB6 forms rather than in a resource file. I thought I'd mention that in case it was relevant to the suggesting of ordering. As far as I am aware, the IDE cannot be made to choose an application icon from a resource file when there are forms in the project.

    Yes, changing the form icons from 256x256 to 72x72 worked fine.

  6. #6
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: [RESOLVED] VB6 Unexpected Error on Windows 7

    Try these 256x256 icons that were edited in order to be compatible with VB6. The included project demonstrates how to utilize them by calling some API functions.


    Name:  Screenshot1.png
Views: 11650
Size:  79.7 KB Name:  Screenshot2.png
Views: 11388
Size:  82.4 KB
    Attached Files Attached Files
    Last edited by Bonnie West; Nov 25th, 2013 at 08:05 AM.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  7. #7
    Member
    Join Date
    Aug 2006
    Posts
    57

    Question Re: [RESOLVED] VB6 Unexpected Error on Windows 7

    Quote Originally Posted by Bonnie West View Post
    Try these 256x256 icons that were edited in order to be compatible with VB6. The included project demonstrates how to utilize them by calling some API functions.
    Name:  Screenshot1.png
Views: 11650
Size:  79.7 KB Name:  Screenshot2.png
Views: 11388
Size:  82.4 KB
    thanks for the sample.
    but i have a problem:
    how to add your code in MDIForm?

    Code:
    Option Explicit
    
    Private hIcon As Long
    
    
    Private Sub MDIForm_Load()
    Dim R As RECT, sngHeight As Single, sngWidth As Single
    
    
        R.Top = 20&:    R.Bottom = 20& + ICON_JUMBO
        R.Left = 20&:   R.Right = 20& + ICON_JUMBO
    
    
        If AdjustWindowRectEx(R, GetWindowLongW(hWnd, GWL_STYLE), 0&, GetWindowLongW(hWnd, GWL_EXSTYLE)) Then
            sngWidth = (R.Right - R.Left) * Screen.TwipsPerPixelX
            sngHeight = (R.Bottom - R.Top) * Screen.TwipsPerPixelY
            Move Screen.Width * HALF - sngWidth, (Screen.Height - sngHeight) * HALF, sngWidth, sngHeight
        End If
    
    
        If App.LogMode Then
            hIcon = LoadImageW(App.hInstance, WINDOWS_ICON, IMAGE_ICON, ICON_JUMBO, ICON_JUMBO)
            SendMessageW hWnd, WM_SETICON, ICON_BIG, LoadImageW(App.hInstance, WINDOWS_ICON, IMAGE_ICON, , , LR_DEFAULTSIZE)
            SendMessageW hWnd, WM_SETICON, ICON_SMALL, LoadImageW(App.hInstance, WINDOWS_ICON, IMAGE_ICON, 16&, 16&)
        End If
    End Sub
    
    
    Private Sub MDIForm_Resize()
        If WindowState <> vbMinimized Then
            Cls
            If hIcon Then
                DrawIconEx hDC, (ScaleWidth - ICON_JUMBO) * HALF, _
                                (ScaleHeight - ICON_JUMBO) * HALF, hIcon, ICON_JUMBO, ICON_JUMBO
            Else
                PaintPicture Icon, (ScaleWidth - ScaleX(Icon.Width, vbHimetric, vbPixels)) * HALF, _
                                   (ScaleHeight - ScaleY(Icon.Height, vbHimetric, vbPixels)) * HALF
            End If
        End If
    End Sub
    
    
    Private Sub MDIForm_Unload(Cancel As Integer)
        SendMessageW hWnd, WM_SETICON, ICON_BIG, 0&
        SendMessageW hWnd, WM_SETICON, ICON_SMALL, 0&
    End Sub
    if i write your code on MDIForm i get error Sub Or Function not defined on:
    • Cls
    • PaintPicture
    • ScaleX
    • ScaleY


    how to solve this?

    thanks b4

  8. #8
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: [RESOLVED] VB6 Unexpected Error on Windows 7

    Quote Originally Posted by afdoal View Post
    if i write your code on MDIForm i get error Sub Or Function not defined on:
    • Cls
    • PaintPicture
    • ScaleX
    • ScaleY
    That's because an MDIForm doesn't have any of those methods.

    Quote Originally Posted by afdoal View Post
    how to add your code in MDIForm?
    Code:
    Option Explicit     'Don't forget to set the "windows_perfection_logo_v2_d-bliss.ico" icon as the MDIForm's Icon! (Set it via the Properties Window)
    
    Private Const pbID As String = "picIcon"
    
    Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long
    Private Declare Function FindWindowExW Lib "user32.dll" (Optional ByVal hWndParent As Long, Optional ByVal hWndChildAfter As Long, Optional ByVal lpszClass As Long, Optional ByVal lpszWindow As Long) As Long
    Private Declare Function InvalidateRect Lib "user32.dll" (ByVal hWnd As Long, Optional ByVal lpRect As Long, Optional ByVal bErase As Long = -True) As Long
    
    Private m_hIcon   As Long
    Private m_hWndMC  As Long
    Private m_picIcon As VB.PictureBox
    
    Private Sub MDIForm_Load()
        m_hWndMC = FindWindowExW(hWnd, , StrPtr("MDIClient"))
    
        If App.LogMode Then
            Set Icon = Nothing
            m_hIcon = LoadImageW(App.hInstance, WINDOWS_ICON, IMAGE_ICON, ICON_JUMBO, ICON_JUMBO)
            SendMessageW hWnd, WM_SETICON, ICON_BIG, LoadImageW(App.hInstance, WINDOWS_ICON, IMAGE_ICON, , , LR_DEFAULTSIZE)
            SendMessageW hWnd, WM_SETICON, ICON_SMALL, LoadImageW(App.hInstance, WINDOWS_ICON, IMAGE_ICON, 16&, 16&)
        End If
    
        Set m_picIcon = Controls.Add("VB.PictureBox", pbID)
        With m_picIcon
            .AutoRedraw = True
            .BackColor = BackColor
            .BorderStyle = 0
            .ClipControls = False
            .ScaleMode = vbPixels
        End With
    End Sub
    
    Private Sub MDIForm_Resize()
        If WindowState <> vbMinimized Then
            With m_picIcon
                .Cls
                .Move 0!, 0!, ScaleWidth, ScaleHeight
    
                If m_hIcon Then
                    DrawIconEx .hDC, (.ScaleWidth - ICON_JUMBO) * HALF, _
                                     (.ScaleHeight - ICON_JUMBO) * HALF, m_hIcon, ICON_JUMBO, ICON_JUMBO
                ElseIf Not Icon Is Nothing Then
                   .PaintPicture Icon, (.ScaleWidth - .ScaleX(Icon.Width, vbHimetric, vbPixels)) * HALF, _
                                       (.ScaleHeight - .ScaleY(Icon.Height, vbHimetric, vbPixels)) * HALF
                End If
    
                Set Picture = .Image
                InvalidateRect m_hWndMC
            End With
        End If
    End Sub
    
    Private Sub MDIForm_Unload(Cancel As Integer)
        Set m_picIcon = Nothing
        Controls.Remove pbID
    
        If m_hIcon Then
            DestroyIcon m_hIcon
            DestroyIcon SendMessageW(hWnd, WM_SETICON, ICON_BIG, 0&)
            DestroyIcon SendMessageW(hWnd, WM_SETICON, ICON_SMALL, 0&)
        End If
    End Sub
    BTW, I've just realized that the code in the attachment above was leaking the icon handles. I've included the fixes (Set Icon = Nothing and DestroyIcon ...) in this MDIForm code.
    Last edited by Bonnie West; Nov 26th, 2013 at 07:26 AM.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  9. #9
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] VB6 Unexpected Error on Windows 7

    This thread has been reported a couple of times. It's been asked to be moved to the VB6 forum. Even though the original post didn't have any code (which is probably why people don't think it belongs in the CodeBank) it's a valuable tip, just as good as any code snippet. Bonnie also posted some code which might very well belong here so I've decided to leave this thread here in the CodeBank instead of moving it to VB6 where it soon will just disappear among the huge amount of new threads in that forum.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: [RESOLVED] VB6 Unexpected Error on Windows 7

    Tip: To avoid having to worry about leaking the big/small icons, maybe consider using the LR_SHARED constant during LoadImage call?

    Edited: LR_SHARED, however, may not be appropriate for every situation
    Last edited by LaVolpe; Jan 28th, 2015 at 03:06 PM.
    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}

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width