Re: RAS Client by Tibby
Tibby
Tue Jul 13 18:47:47 CDT 2004
On Tue, 13 Jul 2004 18:53:11 -0400, "William DePalo [MVP VC++]"
<willd.no.spam@mvps.org> wrote:
>"Tibby" <tibby@tiberiansun.us> wrote in message
>news:nf98f0t8hkdjupb2elop1ekghiu7o2ifod@4ax.com...
>> Now I just need to figure out how to use the callback
>> function of RasDial so I can moitor progress/error, and
>> export that.
>
>Some time ago someone in another group asked how to call RasDial(). The ugly
>little hack below demonstrates how to route the progress notifications to a
>window. The hack's window procedure simply writes the two parameters of the
>message to a console window.
>
>I'd suggest changing this string "New MSN" to the name of the "connectoid"
>that you want to dial, and then building it unchanged to make sure it works.
>
>> Thanks a million guys!
>
>You are welcome.
>
>Regards,
>Will
>
>#include <windows.h>
>#include <ras.h>
>#include <io.h>
>#include <stdio.h>
>#include <iostream>
>
>UINT uMsgRas;
>HWND hWndRas = NULL;
>
>// Window procedure
>
>LRESULT CALLBACK RasWndProc(HWND hWnd, UINT uMsg, WPARAM wp, LPARAM lp)
>{
> LRESULT lr;
>
> if ( uMsg == uMsgRas )
> {
> std::cout << "Ras event parameters are (" << wp << ", " << lp << ")" <<
>std::endl;
> lr = 0;
> }
>
> else if ( uMsg == WM_DESTROY )
> {
> PostQuitMessage(0);
> hWndRas = NULL;
> lr = 0;
> }
>
> else
> lr = DefWindowProc(hWnd, uMsg, wp, lp);
>
> return lr;
>}
>
>// Handles control/c etc on console
>
>BOOL WINAPI ConsoleEventHandler(DWORD dwEvent)
>{
> if ( hWndRas )
> PostMessage(hWndRas, WM_CLOSE, 0, 0);
>
> return TRUE;
>}
>
>// Main program creates a console, a window, and does the RasDial() thing
>
>int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR pszCmd, int
>nShow)
>{
> int fd;
> MSG msg;
> FILE *fp;
> BOOL bGotPwd;
> DWORD dwSize;
> WNDCLASS wc;
> HRASCONN hRasConn;
> RASENTRY re = { 0 };
> RASDIALPARAMS rdp = { 0 };
>
> // Hybrid: windowed application using console for simple output
>
> AllocConsole();
>
> fd = _open_osfhandle( (long) GetStdHandle(STD_OUTPUT_HANDLE), 0);
> fp = _fdopen(fd, "w");
>
> *stdout = *fp;
> setvbuf( stdout, NULL, _IONBF, 0 );
>
> SetConsoleCtrlHandler(ConsoleEventHandler, TRUE);
>
> // Register RAS notification message
>
> uMsgRas = RegisterWindowMessage(RASDIALEVENT);
>
> if (uMsgRas == 0)
> uMsgRas = WM_RASDIALEVENT;
>
> // Register a window class
>
> memset(&wc, 0, sizeof(wc));
> wc.hInstance = hInst;
> wc.lpfnWndProc = RasWndProc;
> wc.lpszClassName = "MyRasClass";
>
> RegisterClass(&wc);
>
> // Create the window
>
> hWndRas = CreateWindow("MyRasClass", "RasTest", WS_OVERLAPPEDWINDOW,
> CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
> HWND_MESSAGE, NULL, hInst, NULL);
>
> // Get the dial parameters of the connectoid
>
> rdp.dwSize = sizeof(rdp);
> strcpy(rdp.szEntryName, "New MSN");
> RasGetEntryDialParams(NULL, &rdp, &bGotPwd);
>
> // Get the phone number, too
>
> dwSize = re.dwSize = sizeof(re);
> RasGetEntryProperties(NULL, rdp.szEntryName, &re, &dwSize, NULL, 0);
> strcpy(rdp.szPhoneNumber, re.szLocalPhoneNumber);
>
> // Dial the connectoid
>
> hRasConn = NULL;
> RasDial(NULL, NULL, &rdp, -1, hWndRas, &hRasConn);
>
> // The ubiquitous message pump
>
> while ( GetMessage(&msg, NULL, 0, 0) )
> {
> TranslateMessage(&msg);
> DispatchMessage(&msg);
> }
>
> // Get rid of the console
>
> FreeConsole();
>
> return 0;
>}
>
>It creates this output when dialing up MSN here:
>
>Ras event parameters are (0, 0)
>Ras event parameters are (1, 0)
>Ras event parameters are (2, 0)
>Ras event parameters are (3, 0)
>Ras event parameters are (4, 0)
>Ras event parameters are (5, 0)
>Ras event parameters are (6, 0)
>Ras event parameters are (10, 0)
>Ras event parameters are (6, 0)
>Ras event parameters are (18, 0)
>Ras event parameters are (6, 0)
>Ras event parameters are (14, 0)
>Ras event parameters are (8192, 0)
>
Is it possible to do that from a DLL? Liek I said, I really suck at
C++, I'm a VB programmer by trade LOL
Thanks again,
Tibby