uri22
asked on
Assigning modem to port at win2k using createfile( ) - SOS
Hello
Im wrote a peace of code that sends/receives data using a modem.
I use to open the port was assign to the modem (COM1...)
At win2k the state is different and requires using the createFile().
Using that function requires the portName (not COM1...)
I tried to open by the name the modem ws defined but got a constant error.
Can someone send me an example of this function where the portName parameter is a modem name
Thanks
Im wrote a peace of code that sends/receives data using a modem.
I use to open the port was assign to the modem (COM1...)
At win2k the state is different and requires using the createFile().
Using that function requires the portName (not COM1...)
I tried to open by the name the modem ws defined but got a constant error.
Can someone send me an example of this function where the portName parameter is a modem name
Thanks
hi uri22,
Do you have any additional questions? Do any comments need clarification?
-- Dan
Do you have any additional questions? Do any comments need clarification?
-- Dan
uri22,
Some of these questions have been open for some time. Please resolve them appropriately as soon as possible.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11472178
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20004239
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20009924
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20011525
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20053971
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20078995
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20138023
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20149761
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20004907
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20079637
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20178804
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20231068
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20174847
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20015649
Thanks,
Netminder
Community Support Moderator
Experts Exchange
Some of these questions have been open for some time. Please resolve them appropriately as soon as possible.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11472178
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20004239
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20009924
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20011525
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20053971
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20078995
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20138023
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20149761
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20004907
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20079637
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20178804
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20231068
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20174847
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20015649
Thanks,
Netminder
Community Support Moderator
Experts Exchange
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Force/accepted by
Netminder
Community Support Moderator
Experts Exchange
Netminder
Community Support Moderator
Experts Exchange
#include <windows.h>
void main()
{
HANDLE hCom = CreateFile(
"COM2", // LPCTSTR lpFileName, // file name
GENERIC_READ | GENERIC_WRITE, // DWORD dwDesiredAccess, // access mode
0, // DWORD dwShareMode, // share mode
0, // LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
OPEN_EXISTING, // DWORD dwCreationDisposition, // how to create
0, // DWORD dwFlagsAndAttributes,// file attributes
0 // HANDLE hTemplateFile // handle to template file
);
char szModemInit[]= "AT&F\r";
DWORD nActual= 0;
BOOL fRet;
fRet= WriteFile( hCom, szModemInit,strlen(szModem
char buf[1000];
fRet= ReadFile( hCom, buf, 999, &nActual, 0 );
char szModemDial[]= "ATDT9,555-1234\r";
fRet= WriteFile( hCom, szModemDial,strlen(szModem
}
-=-=-==-=--=
Notice that the name of the file is "COM1" or "COM2" etc (look in the Control Panel to learn the correct COMn port" and you need to use
GENERIC_READ | GENERIC_WRITE,
and
OPEN_EXISTING
as shown. Note that it is possible that on your system, there is some software that already owns the COM port (eg, the system is waiting to answer an incomming Fax or data connection). In that case, you need to disable that software ...OR... enter the ugly ugly world of TAPI because TAPI lets you share access to the modem. TAPI also provides a way to init the modem without knowing the brand of modem, etc. But it is ugly beyond description.
-- Dan