|
-
Sep 19th, 2006, 05:01 AM
#1
Thread Starter
New Member
Writefile API on a connected modem device
Hi,
I'm trying to port over some old, working, VB6 code into VBDotNet (VS2003, but soon upgrading to VS2005) 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 which I now don't know enough about to replace. I think that's probably where the main error is, but I'm not certain.
I've also tried replacing that with a Byte Arraym, which still leads to an 87 error.
Hopefully someone can tell me where I am going wrong with this.
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
Last edited by KFrost; Sep 19th, 2006 at 05:05 AM.
Reason: Added VS version
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|