Hi, I'm trying to use the GetComboBoxInfo API to customize the position of combo box list, but i get amn MDA stack error using it ...
PInvokeStackImbalance was detected
Message: A call to PInvoke function 'MultiColCombo!WindowsControlLibrary1.MultiColumnCombo::GetComboBoxInfo' has unbalanced the stack. .....
arrrg ...
I've converted the code to VB6 format and obviously i don't get the MDA PInvokeStackImbalance error but it must be having the same problem because I don't anything returned in the COMBOBOXINFO structure
Am I doing something wrong .... is this an issue with my system .... etc.
any help would be appreciated ! thanks
code is as follows ....
Imports System.Windows
Imports System.Runtime.InteropServices
Public Class MultiColumnCombo
Inherits System.Windows.Forms.ComboBox
Public Structure WINDOWPLACEMENT
Public length As Integer
Public flags As Integer
Public showCmd As Integer
Public ptMinPosition As Point
Public ptMaxPosition As Point
Public rcNormalPosition As Rectangle
End Structure
Public Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure
Public Structure COMBOBOXINFO
Public cbSize As UInteger
Public rcItem As RECT
Public rcButton As RECT
Public stateButton As UInteger
Public hwndCombo As Integer
Public hwndEdit As Integer
Public hwndList As Integer
End Structure
Private Declare Function GetComboBoxInfo Lib "User32" (ByVal hwndCombo As Integer, ByVal CBInfo As COMBOBOXINFO) As Integer
Sub New()
MyBase.New()
End Sub
Private Function GetComboListHandle() As Long
Dim CBI As COMBOBOXINFO
Dim hMe As Long
Dim lCheck As Long
hMe = MyBase.Handle
CBI.cbSize = Marshal.SizeOf(CBI)
lCheck = GetComboBoxInfo(hMe, CBI)
GetComboListHandle = CBI.hwndList
End Function
Private Sub MultiColumnCombo_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DropDown
Dim hListBox As Integer
Dim wpListBox As WINDOWPLACEMENT
Dim newTop As Integer
hListBox = GetComboListHandle()
GetWindowPlacement(hListBox, wpListBox)
newTop = wpListBox.rcNormalPosition.Top + 150
MoveWindow(hListBox, wpListBox.rcNormalPosition.Right, newTop, wpListBox.rcNormalPosition.Width, wpListBox.rcNormalPosition.Height, True)
End Sub
End Class

GetComboBoxInfo - PInvokeStackImbalance
SMerrill8
Change the declaration to
Private Declare Function GetComboBoxInfo Lib "User32" (ByVal hwndCombo As IntPtr, ByRef CBInfo As COMBOBOXINFO) As Boolean
The most important change is to make the second parameter ByRef.
Kreator
Thanks Mattias !!! works like a charm now !