Click to See Complete Forum and Search --> : Help, want to get access to my modem using CreateFile.


SilentJackqh
June 9th, 2003, 06:25 AM
I want to get Access to my modem (COM3).
I use CreateFile Function.
HANDLE hFile=CreateFile("\\\\.\\COM3" ,READ_CONTROL,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_SYSTEM,NULL);

It's return INVALID_HANDLE_VALUE.
Anyone can help what should I change ?

rxbagain
June 9th, 2003, 06:43 AM
HANDLE hFile = CreateFile("COM3",
GENERIC_READ | GENERIC_WRITE,
0, // comm devices must be opened w/exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // comm devices must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);
Hope this will help you

SilentJackqh
June 9th, 2003, 04:14 PM
it's work.
how can I detect my connection still alive without distrub the connection itself ?
Is there any function to do this,
I am using VC++ v6.0 in Windows 98.

rxbagain
June 9th, 2003, 09:20 PM
Use ClearCommError. I don't know the exact value of lpErrors for modems but I'm quite sure it's the right function as what I was doing with serial printers.

Try also GetCommModemStatus.

Hope this will help you

SilentJackqh
June 9th, 2003, 11:20 PM
I mean what if other application already used the modem, and the Application I make is only to detect if the connection still alive or not.

SilentJackqh
June 10th, 2003, 04:22 PM
I manage to find a function for that :
bReturn=InternetCheckConnection(NULL,0,0);

but I still cann't do it rightly.
Wheter I connect to internet or not it's still return FALSE;

Caprice
June 11th, 2003, 03:21 AM
The CreateFile returns an error if an another application works with your modem.
If you want to check internet connection you can read about IsNetworkAlive function or GetConnectedState (something like this)

SilentJackqh
June 11th, 2003, 06:22 AM
thanx it's works.