Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I create a phone dialler with WinAPI calls

Tips -N- Tricks

How can I create a phone dialler with WinAPI calls

by  ChrisRChamberlain  Posted    (Edited  )
You can use the following, courtesy of George Tasker, who originally wrote it.

Special thanks to Jon Hawkins who first posted it in the VFP forum.
[color blue]
#DEFINE WAITSECONDS 4
#DEFINE ID_CANCEL 2
#DEFINE MB_OKCANCEL 1
#DEFINE MB_ICONSTOP 16
#DEFINE MB_ICONINFO 64
#DEFINE GEN_READ 0x80000000
#DEFINE GEN_WRITE 0x40000000
#DEFINE CF_TEXT CHR(13) + CHR(10)

DECLARE INTEGER WriteFile IN Win32API;
[tab]INTEGER hFile,;
[tab]STRING @lpbuffer,;
[tab]INTEGER nNumberOfBytesToWrite,;
[tab]INTEGER @lpNumberOfBytesWritten,;
[tab]STRING @lpOverlapped

DECLARE INTEGER CreateFile IN Win32API;
[tab]STRING @lpFileName,;
[tab]INTEGER dwDesiredAccess,;
[tab]INTEGER dwShareMode,;
[tab]STRING @lpSecurityAttributes,;
[tab]INTEGER dwCreationDisposition,;
[tab]INTEGER dwFlagsAndAttributes,;
[tab]INTEGER hTemplateFile

DECLARE INTEGER CloseHandle IN Win32API;
[tab]INTEGER hObject

DECLARE INTEGER FlushFileBuffers IN Win32API;
[tab]INTEGER hFile

PROCEDURE DialNumber

LPARAMETERS PhoneNumber, CommPort

LOCAL lcmsg, lnport, lnwritten, lcmnd, lnstop

lcmsg = "Please pickup the phone and choose OK to dial " + PhoneNumber

IF MESSAGEBOX(lcmsg, MB_ICONINFO + MB_OKCANCEL, "Dial Number") # ID_CANCEL
[tab]lnport = CreateFile(@CommPort, GEN_READ + GEN_WRITE, 0, 0, 3, 0, 0)

[tab]IF lnport > 0
[tab][tab]lnwritten = 0
[tab][tab]lccmnd = "ATDT" + PhoneNumber + CF_TEXT

[tab][tab]IF WriteFile(lnport, @lccmnd, LEN(lccmnd), @lnwritten, 0) # 0
[tab][tab][tab][color green]* Flush the buffer to assure the data was written[color blue]
[tab][tab][tab]= FlushFileBuffers(lnport)
[tab][tab][tab][color green]* Wait to make sure it's been dialed[color blue]
[tab][tab][tab]lnstop = SECONDS() + WAITSECONDS

[tab][tab][tab]DO WHILE SECONDS() < lnstop
[tab][tab][tab][tab]DoEvents
[tab][tab][tab]ENDDO

[tab][tab][tab][color green]* Hang up command[color blue]
[tab][tab][tab]lccmnd = 'ATH0' + CF_TEXT
[tab][tab][tab]= WriteFile(lnport, @lccmnd, LEN(lccmnd), @lnwritten, 0)
[tab][tab][tab]= FlushFileBuffers(lnport)
[tab][tab][tab][color green]* Close up[color blue]
[tab][tab][tab]= CloseHandle(lnport)

[tab][tab]ENDIF

[tab]ENDIF

ENDIF

RETURN

ENDPROC
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top