PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VB 2005 PInvokeStackImbalance Was Detected-VBForums
Results 1 to 16 of 16

Thread: VB 2005 PInvokeStackImbalance Was Detected

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Sittingbourne
    Posts
    26

    Question VB 2005 PInvokeStackImbalance Was Detected

    im trying to grab the Text from Yahoo Messengers Window in Microsoft Visual Basic 2005 Express Edition. I get this error when trying to grab the Chat Windows Text. Edit... think that was my code to set win Text but still i dunno why that error happens.

    Below is the code i was using.

    VB Code:
    1. Dim imclass As Long
    2.         Dim yhtmlcontainer As Long
    3.         Dim internetexplorerserver As Long
    4.  
    5.         imclass = FindWindow("imclass", vbNullString)
    6.         yhtmlcontainer = FindWindowEx(imclass, 0&, "yhtmlcontainer", vbNullString)
    7.         internetexplorerserver = FindWindowEx(yhtmlcontainer, 0&, "internet explorer_server", vbNullString)
    8.         Call SendMessageByString(internetexplorerserver, WM_SETTEXT, 0&, TextBox1.Text)
    9.  
    10.         If internetexplorerserver = 0 Then
    11.             MsgBox("No Window Was Found! or your code is bad.")
    12.             Exit Sub
    13.         End If
    14.  
    15.  
    16.     End Sub
    17. End Class

    The 2 lines im getting errors with is

    VB Code:
    1. yhtmlcontainer = FindWindowEx(imclass, 0&, "yhtmlcontainer", vbNullString)
    2.         internetexplorerserver = FindWindowEx(yhtmlcontainer, 0&, "internet explorer_server", vbNullString)


    I dont know why it did that but im hoping someone will be able to explain what im doing wrong
    Last edited by vbwizard2006; Nov 23rd, 2006 at 09:31 AM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,117

    Re: VB 2005 PInvokeStackImbalance Was Detected

    I'm guessing that you have taken your API declarations from VB6 code. Most Windows API functions require 32-bit numbers. In VB6 the Long type was 32 bits wide, so API declarations in VB6 usually used the Long type. If you want to adapt those declarations to VB.NET then you need to use the Integer type instead of Long. In VB.NET the Integer type is 32 bits wide while the Long is 64 bits wide. It's almost certainly the fact that you're passing 64-bit numbers where the function expects 32-bit numbers that is causing the problem. Note that the "&" suffix on your zero values is also forcing them to the Long type, so you need to remove those too.

    It's a fair bet that that was VB6 code because what you posted could almost pass as VB6. You shouldn't be using vbNullString in VB.NET at all. If you want an empty string then use String.Empty or if you want a null reference then use Nothing. Also, 'Call' serves no useful purpose in VB.NET. Many would also counsel that you use MessageBox.Show rather than MsgBox too.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Sittingbourne
    Posts
    26

    Re: VB 2005 PInvokeStackImbalance Was Detected

    thanks jmcilhinney you have been a great help. I am new to Visual Basics 2005. I need a EBook really to get to know this new code

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,117

    Re: VB 2005 PInvokeStackImbalance Was Detected

    See my signature for links to multiple tutorials and two eBooks from MS, plus other good stuff.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Sittingbourne
    Posts
    26

    Re: VB 2005 PInvokeStackImbalance Was Detected

    Thanks mate

  6. #6
    Member
    Join Date
    Nov 2008
    Posts
    32

    Re: VB 2005 PInvokeStackImbalance Was Detected

    Hi both, (jmcilhinney and vbwizard2006)

    Sorry to gate crash this old post but I am having the same problem and can't fix it (see code below), any ideas?

    Kindest regards,

    Matt.


    Code:
    'This is my usage:
    
    Dim rtf As New RichTextBox
    
    Call SetTransparent(rtf.Handle.ToInt32)
    
    
    
    'This is my module code
    Module transparentRTB
        Private Const GWL_EXSTYLE = (-20)
        Private Const WS_EX_TRANSPARENT = &H20&
    
        Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
        Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    
        Public Sub SetTransparent(ByVal mHWnd As Long)
    
    
            Dim x As Integer = GetWindowLong(mHWnd, GWL_EXSTYLE)   '<==== I get error here
    
            x = x Or WS_EX_TRANSPARENT
            SetWindowLong(mHWnd, GWL_EXSTYLE, x)
    
    
        End Sub
    End Module

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,117

    Re: VB 2005 PInvokeStackImbalance Was Detected

    Quote Originally Posted by lawsonium
    Hi both, (jmcilhinney and vbwizard2006)

    Sorry to gate crash this old post but I am having the same problem and can't fix it (see code below), any ideas?

    Kindest regards,

    Matt.


    Code:
    'This is my usage:
    
    Dim rtf As New RichTextBox
    
    Call SetTransparent(rtf.Handle.ToInt32)
    
    
    
    'This is my module code
    Module transparentRTB
        Private Const GWL_EXSTYLE = (-20)
        Private Const WS_EX_TRANSPARENT = &H20&
    
        Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
        Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    
        Public Sub SetTransparent(ByVal mHWnd As Long)
    
    
            Dim x As Integer = GetWindowLong(mHWnd, GWL_EXSTYLE)   '<==== I get error here
    
            x = x Or WS_EX_TRANSPARENT
            SetWindowLong(mHWnd, GWL_EXSTYLE, x)
    
    
        End Sub
    End Module
    The same problem would suggest the same solution. Read post #2.

  8. #8
    Member
    Join Date
    Nov 2008
    Posts
    32

    Re: VB 2005 PInvokeStackImbalance Was Detected

    Oh, sorry, have re-read your post and understand now about changing the longs to ints in the declaration.

    I now have this:

    Code:
        Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer
        Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Integer
    It has stopped the error but the result isn't quite what I thought it would be. My RichTextBox is now transparent through the 'DataGridView' it is contanied in and the form the DataGrid is sat on and on to my desktop????????
    Not what I was expecting at all.

    Matt.

  9. #9
    Member
    Join Date
    Nov 2008
    Posts
    32

    Re: VB 2005 PInvokeStackImbalance Was Detected

    Any ideas?

    Matt.

  10. #10
    Member
    Join Date
    Nov 2008
    Posts
    32

    Re: VB 2005 PInvokeStackImbalance Was Detected

    Ok, this is annoying :-(

    My code is a mixture of examples from the web and my own alterations.

    I set up a column in my list box like this:

    vb Code:
    1. Dim searchString As New DataGridViewRichTextColumn
    2.         searchString.DataPropertyName = "searchString"
    3.         searchString.HeaderText = "String"
    4.         searchString.ReadOnly = True
    5.         searchString.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader
    6.         searchString.DefaultCellStyle.Font = New System.Drawing.Font(Font.FontFamily, 11, FontStyle.Regular)
    7.         Me.dgvSearchResults.Columns.Add(searchString)

    DataGridViewRichTextColumn:
    vb Code:
    1. Public Class DataGridViewRichTextColumn
    2.     Inherits DataGridViewColumn
    3.  
    4.     Public Sub New()
    5.         MyBase.New(New DataGridViewRichTextCell)
    6.     End Sub
    7.  
    8.     Public Overrides Property CellTemplate() As DataGridViewCell
    9.         Get
    10.             Return MyBase.CellTemplate
    11.         End Get
    12.         Set(ByVal value As DataGridViewCell)
    13.  
    14.             ' Ensure that the cell used for the template is a CalendarCell.
    15.             If Not (value Is Nothing) AndAlso _
    16.              Not value.GetType().IsAssignableFrom(GetType(DataGridViewRichTextCell)) _
    17.              Then
    18.                 Throw New InvalidCastException("Must be a DataGridViewRichTextCell")
    19.             End If
    20.             MyBase.CellTemplate = value
    21.  
    22.         End Set
    23.     End Property
    24.  
    25. End Class


    DataGridViewRichTextCell:
    vb Code:
    1. Public Class DataGridViewRichTextCell
    2.     Inherits DataGridViewTextBoxCell
    3.  
    4.     Protected Overrides Sub Paint(ByVal graphics As Graphics, _
    5.      ByVal clipBounds As Rectangle, ByVal cellBounds As Rectangle, _
    6.      ByVal rowIndex As Integer, ByVal cellState As DataGridViewElementStates, _
    7.      ByVal value As Object, ByVal formattedValue As Object, _
    8.      ByVal errorText As String, ByVal cellStyle As DataGridViewCellStyle, _
    9.      ByVal advancedBorderStyle As DataGridViewAdvancedBorderStyle, _
    10.      ByVal paintParts As DataGridViewPaintParts)
    11.  
    12.         Dim backColor As Color = Color.Transparent
    13.  
    14.         Dim brush As New SolidBrush(backColor)
    15.         graphics.FillRectangle(brush, cellBounds)
    16.         brush.Dispose()
    17.  
    18.         ' Convert the text to Rtf, and then transfer to the Graphics object.
    19.         RtfTransfer.PaintRtf(formattedValue, graphics, cellBounds, cellStyle.Font, backColor)
    20.  
    21.         ' Paint the cell border after everything is done, or it will get
    22.         ' overridden.
    23.         MyBase.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle)
    24.  
    25.     End Sub
    26.  
    27.     Public Overrides ReadOnly Property DefaultNewRowValue() As Object
    28.         Get
    29.             ' Use the current date and time as the default value.
    30.             Return String.Empty
    31.         End Get
    32.     End Property
    33.  
    34. End Class


    RtfTransfer does a few things but the important part is:
    vb Code:
    1. Public Shared Sub PaintRtf(ByVal value As String, ByVal gr As Graphics, ByVal bounds As Rectangle, ByVal font As Font, ByVal backColor As Color)
    2.  
    3.         Dim rtf As New RichTextBox
    4.  
    5.         rtf.Font = font
    6.         rtf.WordWrap = False
    7.  
    8.         Call SetTransparent(rtf.Handle.ToInt32)
    9.  
    10.     End Sub


    transparentRTB:
    vb Code:
    1. Module transparentRTB
    2.     Private Const GWL_EXSTYLE = (-20)
    3.     Private Const WS_EX_TRANSPARENT = &H20&
    4.  
    5.     Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer
    6.     Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
    7.  
    8.     Public Sub SetTransparent(ByVal mHWnd As Integer)
    9.  
    10.         Dim lS As Long
    11.         If mHWnd <> 0 Then
    12.             lS = GetWindowLong(mHWnd, GWL_EXSTYLE)
    13.             lS = lS Or WS_EX_TRANSPARENT
    14.             SetWindowLong(mHWnd, GWL_EXSTYLE, lS)
    15.         End If
    16.     End Sub
    17. End Module


    Put simply, what I want is the RichTextBox to become highlighted when you click on a row in the DataGridView. I thought making it transparent would solve this but unfortunately it doesn't.

    Can I interact with the RichTextBox with a click event on the DataGridView? If so, how?

    Any ideas welcome.

    Thanks,

    Matt.
    Last edited by lawsonium; Jan 9th, 2009 at 06:29 AM.

  11. #11
    Member
    Join Date
    Nov 2008
    Posts
    32

    Re: VB 2005 PInvokeStackImbalance Was Detected

    *Bump*

  12. #12
    Member
    Join Date
    Jun 2011
    Posts
    53

    Re: VB 2005 PInvokeStackImbalance Was Detected

    Hi! I have the same problem!

    A call to PInvoke function 'Mouse!Mouse.Form1::mouse_event' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
    It's gen an error at this code:
    Code:
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    why?

  13. #13

    Re: VB 2005 PInvokeStackImbalance Was Detected

    Heavy, show us your declaration for mouse_event.

  14. #14
    Member
    Join Date
    Jun 2011
    Posts
    53

    Re: VB 2005 PInvokeStackImbalance Was Detected

    Quote Originally Posted by formlesstree4 View Post
    Heavy, show us your declaration for mouse_event.
    Is how you my holy code

    Code:
    Public Class Form1
    
        Public Declare Auto Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
        Private Const MOUSEEVENTF_LEFTDOWN As Integer = &H2
        Private Const MOUSEEVENTF_LEFTUP As Integer = &H4
        Private Const MOUSEEVENTF_RIGHTDOWN As Integer = &H8
        Private Const MOUSEEVENTF_RIGHTUP As Integer = &H10
    
        Sub start()
            Windows.Forms.Cursor.Position = New Point(550, 40)
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
            Threading.Thread.Sleep(2000)
            System.Windows.Forms.SendKeys.Send("hej")
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            start()
        End Sub
    End Class

  15. #15

    Re: VB 2005 PInvokeStackImbalance Was Detected

    See here.

  16. #16
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,117

    Re: VB 2005 PInvokeStackImbalance Was Detected

    Quote Originally Posted by Heavy.Is.Happy View Post
    Is how you my holy code

    Code:
    Public Class Form1
    
        Public Declare Auto Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
        Private Const MOUSEEVENTF_LEFTDOWN As Integer = &H2
        Private Const MOUSEEVENTF_LEFTUP As Integer = &H4
        Private Const MOUSEEVENTF_RIGHTDOWN As Integer = &H8
        Private Const MOUSEEVENTF_RIGHTUP As Integer = &H10
    
        Sub start()
            Windows.Forms.Cursor.Position = New Point(550, 40)
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
            Threading.Thread.Sleep(2000)
            System.Windows.Forms.SendKeys.Send("hej")
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            start()
        End Sub
    End Class
    It's probably a good idea to read the answers as well as the question. The solution to your issue has already been provided: use Integer in VB.NET where Long was used in VB6.

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