Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Win32API & VB6 SP4

8 views
Skip to first unread message

David Golus

unread,
Sep 23, 2000, 3:00:00 AM9/23/00
to

Here's a good one,

What I'm trying to do is automatically execute Dial-up networking, select an
entry and dial.

The Code:

Dim hProcessID As Double
Dim hWndMain As Long
Dim hWndChild As Long
Dim lResult As Long
Dim lCount As Long
Dim lCnt As Long

Dim lpClassName As String
Dim lpWindowName As String

hProcessID = Shell("C:\winnt\system32\rasphone.exe", vbNormalFocus)
If hProcessID = 0 Then
MsgBox "Unable to execute 'Dial-Up Networking'", vbOKOnly, "Test Dialer"
Exit Sub
End If

lpWindowName = "Network and Dial-up Connections"
lpClassName = vbNullString
hWndMain = FindWindow(lpClassName, lpWindowName)
If hWndMain = 0 Then
MsgBox "Unable to Find 'Dial-Up Networking'", vbOKOnly, "Test Dialer"
Exit Sub
End If

lpClassName = "ComboBox"
lpWindowName = vbNullString
hWndChild = FindWindowEx(hWndMain, 0, lpClassName, lpWindowName)
If hWndChild = 0 Then
MsgBox "Unable to Find 'ComboBox'", vbOKOnly, "Test Dialer"
Exit Sub
End If

lpWindowName = "gr-lakes"
lResult = SendMessage(hWndChild, CB_SELECTSTRING, -1, lpWindowName)

The rest of the code has been omitted for clarity.

When I test the value of lResult I always get CB_ERR (or -1). I Use Spy++
and can see the messages working just fine.
hWndMain and hWndChild have valid value and are the same as what Spy++
reports.
All the Win32 API functions and Constants have been delcared properly (Can't
go wrong with cut and paste with the API Text viewer).
The problem is that the gr-lakes entry does NOT get selected. The character
in the combobox and my lpWindowName string
are the exact same. No Typo's or anything.

Any clues?

Thanks,

David.

Alexander Kienzle

unread,
Sep 24, 2000, 3:00:00 AM9/24/00
to

You can go wrong with API Text viewer !!!!!!!!

When I paste the declaration of SendMessage from API Text viewer,
the fourth parameter is defined '[ByRef] As Any'.
Passing a string without an explicit 'ByVal' will pass the address of
your VB string and not a null-terminated C string (DLL's normally
require a C string).
Change your statement to:

SendMessage(hWndChild, CB_SELECTSTRING, -1, ByVal lpWindowName)

or change the declaration of SendMessage accordingly ', ByVal str As
String)'

Hope this helps

Alex


David Golus schrieb in Nachricht <#wt2JqcJAHA.247@cppssbbsa05>...

David Golus

unread,
Sep 24, 2000, 3:00:00 AM9/24/00
to

Alex,

Thanks, I made the change and it works like a charm!

I thing what I'll do though is instead of doing it this way as a quick hack
(My way of doing it ;-) I'll just re-write it using the RAS API. That
should improve things.

Thanks for your help!

David.


"Alexander Kienzle" <kie...@bigfoot.com> wrote in message
news:#ZUDU#mJAH...@cppssbbsa02.microsoft.com...

0 new messages