ComboBox class, CB_INSERTSTRING , VB.NET and marshalling...

  • Thread starter Thread starter CJ Taylor
  • Start date Start date
C

CJ Taylor

Whats your code look like for the SendMessage?

And what part are you marshalling? individual variables or an entire
structure?
 
Hello All,
let me pose a simple question about combobox and the CB_INSERTSTRING
message.
Suppose for instance that I already have a combobox handle, how can I
declare and use the SendMessage function just for insert a new item into the
combobox ?
Of course, the combo box DO NOT belong to my process, so I can't use the
standard properties of that class.
In fact, I need to "put" a new entry in the combo box of IExplorer.
EnumWindows get me the handle of the IExplorer main window, with
EnumChildWindows I can obtain the handle of the "www address" combo.
At this point, I would like to put into the combo an "www address" of
choice.
I tried ALL the parameters of the MarshalAs attribute related to the string,
(with the UnmanagedType enum) but never seems to works, sometime IE
crashes.. :-)

Please, don't tell to me to use SendKeys class.
..NET SendKeys class works well (do not alter, no more, the numlock and/or
capslock status of my keyboard, like the older sendkeys in VB) but I need to
use SendMessage because I want to unterstand hot to marshalling correctly
the parameters.
And last, but not least, I LIKE API's...

Thank You Gentleman for Your precious help.
Best regards


Ing. GianPiero Andreis
 
Ok,
a piece of code...
This is the function I use for looping over the child windows in IE.
Everything works well except the SendMessageA function

Public Function EnumChildWindowsSub(ByVal argl_hChildWnd As IntPtr, ByVal
argl_Param As Integer) As Boolean
Dim lsb_ClassName As New StringBuilder(256)
Call GetClassNameA(argl_hChildWnd, lsb_ClassName,
lsb_ClassName.Capacity)
If (lsb_ClassName.ToString = "ComboBox") Then
SendMessageA(argl_hChildWnd.ToInt32, CB_INSERTSTRING, 0,
"www.thatsite.com")
'This just for see with Spy that the combo handle is correct
Me.Text = "I find combo with handle " &
Hex(argl_hChildWnd.ToInt32).ToString
Return False
Else
Return True
End If
End Function

And this is the prototype for the function.
Private Declare Auto Function SendMessageA Lib "user32" (ByVal hwnd As Long,
ByVal wMsg As Long, ByVal wParam As Long, <MarshalAs(UnmanagedType.LPStr)>
ByVal lParam As String) As Long

There is no need to use System.IntPtr, I don't look for system portability
at this time.

Regarding to formatted classes, at this time I don't use it because I see
Win32 APi's are working as well without the use of that encapsulation.
Maybe this is the cause of the problem, but consider that I use API very
very often in .NET (because I wrote automation programs, macro player and
so on), and everything works well without formatted classes.
I tried also the use of StringBuilder class as fouth parameter in the
SendMessageA function, but IE crashes.
If You need other informations, I would be glad to write for You forward.
Please excuse my english, is very poor, I know.

Thank You in advance, Sir.

Ing. GianPiero Andreis
 
Back
Top