|
||||||
| 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. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 |
| Sponsored Links |
|
|
|
|||||
|
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 |
|
|||||
|
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. |
|
|||
|
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 |
|
|||||
|
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! |
| Sponsored Links |
|
|
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
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. |
|
|||
|
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! |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |
| 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 |