GetOverlappedResult API call on a modem

K

Kristian Frost

Hi,
I'm trying to port over some old, working, VB6 code into VBDotNet and,
because the code is too bloated to continue with, I am converting it
manually, while updating various aspects of the code as needed.
At the moment, I'm trying to send some data over a modem.
I'm using the MS Telephony API 3.1 (TAPI) to make the call and have
successfully created a Call Control object, dialled, and responded to a
TAPI3Lib.CALL_STATE.CS_CONNECTED event from the call object, indicating
that it has connected successfully.
I have then used a TAPI function to get a handle for the call, which I
have then fed into this WriteFile command:

If(WriteFile(CallHandle, StringIAmTryingToSend,
StringIAmTryingToSend.Length, bytesWritten, ModemOVERLAPPED) = 0) Then

which completes successfuly, and gives me the expected 997 DDLError,
indicating that it hasn't finished yet.
I then go into a loop to check the GetOverlappedResult:

check = GetOverlappedResult(CallHandle, ModemOVERLAPPED, bytesWritten,
True)

The DLLError here is 87, which is an ERROR_INVALID_PARAMETER error, which
I can't understand. I've sent it a valid CallHandle, because if the
CallHandle isn't valid, I get a 6 returned (ERROR_INVALID_HANDLE).
Similarly, the ModemOVERLAPPED should be valid because it's been
successfully taken as input by the WriteFile, and then has been output by
WriteFile, also. bytesWritten is a simple integer, and True is a Boolean..
I can't see which parameter could be wrong.

Also, here are my declarations for the various API calls. They are the
same calls as were made in the (working) VB6 code, with the exception of
the "lpBuffer" in WriteFile, which used to be an "Any" object, but whichI
now don't know enough about to replace. I think that's probably where the
main error is, but I'm not certain. Maybe it does take a String object.
Probably not.

Private Declare Function WriteFile Lib "kernel32.dll" ( _
ByVal hFile As Integer, _
ByVal lpBuffer As String, _ 'Was "as Any"
in VB6 code
ByVal nNumberOfBytesToWrite As Integer, _
ByRef lpNumberOfBytesWritten As Integer, _
ByRef lpOverlapped As OVERLAPPED) _
As Integer

Private Declare Function GetOverlappedResult Lib "kernel32.dll" ( _
ByVal hFile As Integer, _
ByRef lpOverlapped As OVERLAPPED, _
ByRef lpNumberOfBytesTransferred As Integer, _
ByVal bWait As Boolean) _
As Integer

Private Structure OVERLAPPED
Public ternal As Integer
Public ternalHigh As Integer
Public offset As Integer
Public offsetHigh As Integer
Public hEvent As Integer
End Structure

Any ideas as to a solution would be welcome.
KF
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top