≡ Menu

Step By Step instructions to write your first IVR Application – II

In my previous post about Step By Step instructions to write your first IVR Application , I wrote about installing the Dialogic D4 PCI card on PCI slot and then installing Dialogic System Release on a Windows XP machine. In this part, I intend to provide the C++ code to initialise the card, make it ready to accept a call and then when it rings, pick the call and play an WAV file!

1. Setup Visual Studio 6.0. Please do not forget to select install the Visual C++ 6.0.

2. It is assumed that you know how to use Visual Studio C++ 6.0. Start a new project IVRS. You will have to include Dialogic INC directories as well as Lib in its option. Else you will see “Compile Error”.

3. Every Channel in a D4 PCI card is denoted by a string dxxxBnCk where n denotes the board ID and k denotes the channel number 1 through 4. For a D4 PCI Card, the list of channels are
a. dxxxB1C1
b. dxxxB1C2
c. dxxxB1C3
d. dxxxB1C4
There are other ways to find these strings to denote channels. There are also Dialogic APIs to find these. You can also check these strings attached Sample Voice application that comes with Dialogic System Release.

4. Now here is the C++ code.

To open the first channel
int hChanell;
hChannel = dx_open(dxxxB1C1,0)

If ( hChannel != -1 )

// Initialise same way for other three channels, ie. dxxxB1C2, dxxxB1C3 and dxxxB1C4

Now threadFunc is a Windows Thread that performs the Call Flow.

DV_TPT def_rp_tpt[] = {

UINT threadFunc(LPVOID pParam)
char *ch = (char *)pParam;
int channel = atoi(ch);
unsigned char callid[81];
memset((void *)callid, 0, 81*sizeof(char));
char UniqueId[300];

char mobid[20];
char temp[100];
char channelname[20];
char callername[50];
time_t starttime,endtime;

char tm[100],tm1[100];
int retval=1;

FILE *file;
char szBuffer[200];

int NumRingAnswer;

// Ensure the phone is kept ON HOOK
if (dx_sethook(channel,DX_ONHOOK,EV_SYNC) == -1)
//WinPrintf(“dx_sethook failed”);

NumRingAnswer = 3; // Answer after 3 rings

if (dx_wtring(channel,NumRingAnswer,DX_OFFHOOK,-1) == -1)
print(“ERROR: dx_wtring failed. errno = %dn,Please make sure your drivers are properly installed”, errno);

// PostMessage(hWnd,WM_OFFHOOK,channel,0);

//Get the caller id
strcpy((char *)callid, “0000000000”);
strcpy((char *)mobid, “0000000000”);

//printf(“Caller ID information blocked n”);
else if (ATDV_LASTERR(channel) == EDX_CLIDOOA)
//printf(“Caller out of area n”);
else {
/* Or print the pre-formatted error message */
//printf(“Error: %s n”, ATDV_ERRMSGP(channel));

switch (ATDX_TERMMSK(channel))
case TM_LCOFF:
//delete cml;
return false;
case TM_DIGIT:
case TM_EOD:

strcpy(callername,(char *)callid);


sprintf(UniqueId,”%d”,::GetTickCount()); // Just to generate an unique ID



strcpy(szBuffer,”Welcome.wav”); // welcome.wav is the file played, it has to be 11025 KHz, PCM, 8Bit, Mono.

if(dx_playwav(channel,szBuffer,def_rp_tpt,EV_SYNC)<0) { printf(ATDV_ERRMSGP(channel)); } tch (ATDX_TERMMSK(channel)) { case TM_LCOFF: return false; case TM_DIGIT: case TM_EOD: break; } endtime=time(NULL); sprintf(tm,"%s",asctime(localtime(&starttime))); sprintf(tm1,"%s",asctime(localtime(&endtime))); // Just to record time of call if (dx_sethook(channel,DX_ONHOOK,EV_SYNC) == -1) { //WinPrintf("dx_sethook failed"); //return(0); } PostMessage(hWnd,WM_ONHOOK,channel,0); // if it discovers a file civrs.dat in its directory, then it closes itself. strcpy(szDirectory[channel],defLanguage); if ( (file=fopen("civrs.dat","r"))==NULL ) { } else { exit(0); } } return 1; } 6. The variable names etc. may produce some errors! This code may not work as it is if pasted! But this code is intended for use a reference and starting point I will update the code with fully working code soon.

Next post:

Previous post:

{ 10 comments… add one }
  • Jeeva February 5, 2010, 10:30 am

    I am trying to do an IVR. you guys adviced to use dialogic card.Since, it is very costlier to me I am trying to do IVR with the help of voice modem. can any one help me out plz!!!!!!!!!!!???


  • Uttam Pegu February 5, 2010, 10:38 am

    Hi Jeeva,
    You may try Donjin o Synway board. These boards are much cheaper ( 1/3rd of Dialogic cost). Donjin uses same library as Dialogic.

    For using Voice modem, you may try with TAPI which is inbuilt library in any Microsoft Tools like VB, VC++ etc.

    Hope this helps.

  • Shankar June 15, 2010, 8:59 am

    hi i am using an electronics circuit which will interface with computer, i.e. same ivrs.. will the code work for my circuit….??

  • Shankar June 15, 2010, 9:11 am

    i am using electronic circuit in such way that it is serial connected thru RS232 cable with pc and DTMF tone is detected in hyperterminal and from there the software section starts,,So my question whether this code will work for my circuit? Plz reply at my mail;shankaranan191@gmail.com

  • Shankar June 15, 2010, 9:15 am

    i am using IVRS for college automation where it will play wav file of students record from the database….. so plz reply quickly

  • Uttam Pegu June 16, 2010, 12:13 pm

    Dear Shankar,
    Since you are using your own electronic circuit, I think you will have write everything on your own in the PC software too.

    I think, you will have to send the audio file to your electronic circuit through the RS232 port and your electronic circuit will have to play the audio data to the caller.

  • Sunit Tyagi November 8, 2010, 6:33 pm

    Hi Dear,

    I am using Dialogic IVR(in Visual C++) but i m facing a problem. when i am calling to machine ext. its connection but when immidaiate i will disconnect the phone it is not stoping it is execute full function so if any body have any idea that i can check the customer phone(chennel) is connecting or disconnect.

    Thanks in Advance

  • Uttam Pegu November 8, 2010, 6:46 pm

    Hi Sunit,
    I assume you are using an Analog Dialogic board. Kindly check this post if this helps


  • nirav February 8, 2012, 3:38 pm

    dear sir

    please give us software which can be work and edited online also.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.