INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Tips -N- Tricks

How can I create a phone dialler with WinAPI calls by ChrisRChamberlain
Posted: 19 Aug 02

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.

#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;
    INTEGER hFile,;
    STRING @lpbuffer,;
    INTEGER nNumberOfBytesToWrite,;
    INTEGER @lpNumberOfBytesWritten,;
    STRING @lpOverlapped

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

DECLARE INTEGER CloseHandle IN Win32API;
    INTEGER hObject

DECLARE INTEGER FlushFileBuffers IN Win32API;
    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
    lnport = CreateFile(@CommPort, GEN_READ + GEN_WRITE, 0, 0, 3, 0, 0)

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

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

            DO WHILE SECONDS() < lnstop
                DoEvents
            ENDDO

            * Hang up command
            lccmnd = 'ATH0' + CF_TEXT
            = WriteFile(lnport, @lccmnd, LEN(lccmnd), @lnwritten, 0)
            = FlushFileBuffers(lnport)
            * Close up
            = CloseHandle(lnport)

        ENDIF

    ENDIF

ENDIF

RETURN

ENDPROC

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close