Click to See Complete Forum and Search --> : WriteFile(


Eric Smith
August 18th, 1999, 03:42 PM
Ok, here is the situation. I am using TAPI to open a phone line. It opens, dials and connects just fine. When it comes time to write data I am using the following code:


HANDLE commFile=(HANDLE)getModemHandle();

/* commFile is now a handle to the comm port */
/* hopefully we can send data using this */

char data[]="stuff to write, IE all my data goes here";
DWORD written;

if(!WriteFile(commFile,data,strlen(data),&written,NULL))
{
error=GetLastError();
}
/* the flippin data is written */
/* hang up */




commFile comes back from getModemHandle with a value. When it gets to WriteFile(), WriteFile returns with an error "Invalid handle". This doesn't make sense to me unless TAPI is lying and not giving me the modem handle.

Has anyone else had experience in this?

Thanks.

ChristianH
August 20th, 1999, 01:56 AM
We had a similar problem with WinSockets.
We found in the MSVC doc that WriteFile can only write into a socket you use the OVERLAPPED option because this is a asynchronous operation.
I hope that this is a useful hint...

Eric Smith
August 20th, 1999, 10:54 AM
Thank you. This would explain much.

chiady
July 28th, 2000, 10:41 AM
You said that you had a similar problem with WinSockets!
I started from same type of problem! Not using overlapped options I get err = 87 ERROR_INVALID_PARAMETER .
Using overlapped options I get err =6 ERROR_INVALID_HANDLE

Do you see any errors, or do you have any useful hints?

Thanks


DWORD err;
OVERLAPPED ovr;

SOCKET m_hSocket = socket(AF_INET, SOCK_STREAM, 0);

SOCKADDR_IN adr;
adr.sin_addr.s_addr = 0;
adr.sin_family = AF_INET;
adr.sin_port = htons( 1234 );

rc = bind(m_hSocket,(const struct sockaddr *)&adr, sizeof(adr) );
rc = listen(m_hSocket,MB_TOPMOST);

rc = sizeof(adr);
SOCKET so2 = accept(m_hSocket,(struct sockaddr *)&adr, &rc ); //doesn't block here, OK
//m_lpB,m_lLength are setted in others methods
if (WriteFile(so2 , m_lpB, m_lLength, &dwWritten, &ovr) == 0)
{
err = GetLastError();
::MessageBox(::GetTopWindow(::GetDesktopWindow()), "Error on Write data", "Server", MB_ICONERROR);
}

charlass
July 31st, 2000, 01:50 AM
Hi,

at least you have to initialize teh OVERLAPPED struct:


OVERLAPPED ovr = {0}; // zero mem somehow
EVENT ev = ::CreateEvent( NULL, FALSE, FALSE, "MyOverlappedEvent");
ovr.hEvent = ev;




And note that WriteFile() can deliver an error code if it is working "overlapped". Check then GetLastError() - it must be sth. like IO_PENDING.

Hope that helps.
bye!