Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-02-2007, 09:55 PM
ryanszeto ryanszeto is offline
Newbie
 
Join Date: Jul 2007
Posts: 9
Rep Power: 0
ryanszeto is on a distinguished road
Default Using C++ to write a program for dialling up modem

Hi guys. First time here.

I am trying to write a program for dialling up a modem using C++ programming language but I don't know where to start. I am a new C++ programmer so I don't know very much about C++. Any suggestions?

Thanks for your help.

Ryan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 07-03-2007, 01:53 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,651
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

Which platform are you doing this for?
If it's for Win32 (Windows) you can find some function in the WinInet library. Some of the functions related to what you're trying to do are:
Code:
InternetAutodial
InternetAutodialHangup
InternetDial
InternetHangup
You might want to look into the Remote Access Service [RAS] functions as well, which you can find a list for here. You can get more information about the functions I listed at MSDN, which can be found here. When working with the WinInet library, you've to remember to link with libwininet.a.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-03-2007, 11:47 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,405
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

If you are new to C++, you may be in for a headache. C++ doesn't provide direct access to hardware, so you are going to be using system functionality along with C++. Visual C++ will probably make it somewhat easier.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-03-2007, 09:27 PM
ryanszeto ryanszeto is offline
Newbie
 
Join Date: Jul 2007
Posts: 9
Rep Power: 0
ryanszeto is on a distinguished road
Default My Reply

Here is my situation. I will be using the program in Windows platform. It is going to be a 56K external modem, connected by serial or USB cable. I thought I am going to use the RAS functions.

Questions:
1) Do I have to write the code to connect to the modem or to the serial port?

2) Since the RAS function requires RAS library, which is part of the Windows Platform SDK. Do I have to download it (>900MB) from Microsoft each time I install the program into different computers? Or is there a way I can just install this particular library file into windows?

3) The thing is I don't know where to start. Is there a sample code I can have a look?

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-04-2007, 01:44 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,651
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

1) Using the RAS-functions, or the other functions, you'll be connecting right to the modem.

2) The only thing you need is the dynamic linked library, rasapi32.dll. So yes, in some way, you need to "install" it on every computer you uses. But you can choose to f.ex. zipping rasapi32.dll, with the executable file. Then the executable file can get contact with it in the same folder.

3) I just tried to find something, but there's no concrete examples. In all the examples I saw, it was the RAS-functionality that were used. You might want to use a search engine, like Google - or a code search engine like Koders, to find some examples.

Good luck!
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 07-09-2007, 08:57 PM
ryanszeto ryanszeto is offline
Newbie
 
Join Date: Jul 2007
Posts: 9
Rep Power: 0
ryanszeto is on a distinguished road
Default Re: Dialling up a modem using C++

I am writing the code already, but I have an issue.

I am trying to import the library "rasapi32.dll" to get the RAS functions (RasDial, and some other functions) and use GetProAddress to get the functions. The library is successfully loaded, but it just can't find those functions.

I have browsed through some websites and it talks about "Linking with rasapi32.LIB". What does that mean? Do I have to write the code "importLibrary("rasapi32.LIB") instead? Or is there a code I have to add on to so that the functions can be found?

Here is my code:

typedef DWORD (*fptr1)(LPRASDIALEXTENSIONS, LPCTSTR, LPRASDIALPARAMS, DWORD, LPVOID, LPHRASCONN);
fptr1 RasDial;

HINSTANCE hinstLib = LoadLibrary("C:\\WINDOWS\\system32\\rasapi32.DLL") ;
RasDial = (fptr1)GetProcAddress(hinstLib, "RasDial");
if (RasDial == NULL) {
printf("ERROR: unable to find the function RasDial.\n");
FreeLibrary(hinstLib);
return ERR;
}

Thanks for your great help!

Ryan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-09-2007, 09:20 PM
ryanszeto ryanszeto is offline
Newbie
 
Join Date: Jul 2007
Posts: 9
Rep Power: 0
ryanszeto is on a distinguished road
Default Re: Dialling up a modem using C++

And one more question:

What is the difference between DLL file "rasapi32.dll" and importLibrary "rasapi32.LIB"?

What will they do? When am I going to use that? What functions will they perform?

THX.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-10-2007, 03:02 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,651
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

It's two different kinds of libraries, "rasapi32.dll" is a dynamic library, while "rasapi.lib" is a static library. If you're using a static library, the executable file will include the library init. So if our normal executable's size is 1MB, without any libraries and the static library's size is also 1MB, if we then link them together the executable's size will become 2MB, but then we don't need the static library anymore. If we're using a dynamic library, then we'll have two files all the time. But that means, if you f.ex. want people to download your application, that you need to include the DLL-file in some folder, to be secure that the users has it. On the other side, you're able to easily make ew functionality in the DLL-file, without compiling the executable file.

If you're using a dynamic library, you're doing the right thing in your code, but if you're using a static library, you need to link with it. An easy example could be showed like the following, using GCC.
Code:
gcc ./myfile.cpp -L /.../library_folder/ -lrasapi32 -o ./myexecutable
If the static library as default already is in the default folder (different locations, usually a "lib"), then you don't need the "-L" parameter.

I just looked up the RasDial-function, and it looks like it needs both the dynamic library (rasapi32.dll) -- and the static library (rasapi32.lib). And of course, you've to remember to include the header file in your souce. It's ras.h, that's used for the RAS functionality.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-27-2007, 03:31 AM
ryanszeto ryanszeto is offline
Newbie
 
Join Date: Jul 2007
Posts: 9
Rep Power: 0
ryanszeto is on a distinguished road
Default RasDial Function enquiries

Firstly, thanks for your help, guys!

I got the modem fired up for dialling up. I can make a call to my mobile phone already.

I got an enquiry about the RasDial function. What I want to do is after the RasDial function is executed, the code will jump to the next line and continue running, with the modem stayed connected (to the other device). What happen right now is that after dialling up the modem, it connects but then just hangs there (I thought it is still stuck within the RasDial function), doing nothing.

I have done some research in the MSDN library about the RasDial function but I am totally confused about it. What is the parameter LPVOID lpvNotifier about? What is the use of RasDialFunc()? How can I use that? What does a callback function do and when does that happen?

Here is my code:
RASDIALPARAMS rdParams;
rdParams.dwSize = sizeof(RASDIALPARAMS);
rdParams.szEntryName[0] = '\0';
lstrcpy(rdParams.szPhoneNumber, szPhoneNumberToDial);
rdParams.szCallbackNumber[0] = '\0';
lstrcpy( rdParams.szUserName, szUserName );
lstrcpy( rdParams.szPassword, szPassword );
rdParams.szDomain[0] = '\0';

HRASCONN hRasConn = NULL;
DWORD dwRet = RasDial(NULL, NULL, &rdParams, 0L, NULL, &hRasConn);

Thanks again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 07-31-2007, 01:28 AM
ryanszeto ryanszeto is offline
Newbie
 
Join Date: Jul 2007
Posts: 9
Rep Power: 0
ryanszeto is on a distinguished road
Default New Circumstances

Right now, when the RasDial function is run synchronously, the program is unusable unless it is disconnected.

In contrast, when the RasDial function is run asynchronously, it immediately jumps to the callback function and doesn't dial up anymore. It returns success straight after the callback function is finished.

I am a bit confused about the use of the callback function parameter in the RasDial function. Here is the RasDial function:

DWORD RasDial(
LPRASDIALEXTENSIONS lpRasDialExtensions,
LPCTSTR lpszPhonebook,
LPRASDIALPARAMS lpRasDialParams,
DWORD dwNotifierType,
LPVOID lpvNotifier,
LPHRASCONN lphRasConn
);

Is it like I have to set dwNotifierType to 0 and put a self-defined function into the lpvNotifier parameter, and then the RasDial function will do the dial-up while executing the callback function? Is there anything I have missed? Or is there something I have done wrong?

By the way, I still don't understand the concept of RasDialFunc. What does the placeholder mean? What does that do? (Sorry, maybe this is a silly question. I am just a programming beginner).

Here is my code:

typedef LPVOID (*RASDIALFUNC)(UINT, RASCONNSTATE, DWORD);

LPVOID RasDialFunction(UINT unMsg, RASCONNSTATE rascs, DWORD dwError)
{
/* No coding at the moment */
}

bool DialUp(void)
{
char szPhoneNumberToDial[RAS_MaxEntryName+1];
char szUserName[UNLEN+1];
char szPassword[PWLEN+1];

printf("Please enter the telephone number: ");
gets(szPhoneNumberToDial);

// Fill RASDIALPARAMS structure
RASDIALPARAMS rdParams;
rdParams.dwSize = sizeof(RASDIALPARAMS);
rdParams.szEntryName[0] = '\0';
lstrcpy(rdParams.szPhoneNumber, szPhoneNumberToDial);
rdParams.szCallbackNumber[0] = '\0';
lstrcpy(rdParams.szUserName, szUserName);
lstrcpy(rdParams.szPassword, szPassword);
rdParams.szDomain[0] = '\0';

// Call RasDial Function
HRASCONN hRasConn = NULL;
RASDIALFUNC rdFunc;
rdFunc = RasDialFunction;

DWORD dwRet = RasDial(NULL, NULL, &rdParams, 0L, rdFunc(WM_RASDIALEVENT, RASCS_OpenPort, 0), &hRasConn);

/* Further more codes...... */
}

I have been stucked for a few weeks already. So please HELP!
Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Best program for SQL database manipulation Rhadamanthys Database & Database Programming 3 07-02-2007 03:32 PM
How do I Program another Program? ! bosco General Programming 1 06-15-2007 12:15 PM
Need help w/ word count program (ASAP) siren C and C++ 1 04-23-2007 09:14 AM
How to modify a program written in .NET 2.0? jackyjack C# Programming 7 03-27-2007 01:26 PM


All times are GMT -5. The time now is 09:17 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads