I desperatly need to make some client software for my ISP. I
have tried using RAS from VB.NET and C# with no luck, and so I have to
turn to C++. As some have seen, I'm not the greatest with C++ yet, so
I was wondering if anyone had a good example of makeing a C++ wrapper
for RAS that I can export the function to call from VB/VB.NET or C#.

Thank You,
Tibby

Re: RAS Client by Tibby

Tibby
Tue Jul 13 12:05:08 CDT 2004

On Mon, 12 Jul 2004 23:13:37 -0400, Tibby <tibby@tiberiansun.us>
wrote:

> I desperatly need to make some client software for my ISP. I
>have tried using RAS from VB.NET and C# with no luck, and so I have to
>turn to C++. As some have seen, I'm not the greatest with C++ yet, so
>I was wondering if anyone had a good example of makeing a C++ wrapper
>for RAS that I can export the function to call from VB/VB.NET or C#.
>
>Thank You,
>Tibby

UPDATE:

I've built a DLL that exports functions, and I think I've got it, but
having a problem, here's my errors:

RASDialer error LNK2019: unresolved external symbol _RasDialA@24
referenced in function _Dial@12

RASDialer error LNK2019: unresolved external symbol _RasHangUpA@4
referenced in function _HangUp@4


And here's my complete code:

#include "stdafx.h"
#include "RAS.H"
#include "RASERROR.H"

RASDIALPARAMS rdParams;
HRASCONN hRasCon = NULL;

extern "C" __declspec(dllexport) HRASCONN WINAPI Dial(LPTSTR tel,

LPTSTR user,

LPTSTR pass)
{
rdParams.dwSize = sizeof(RASDIALPARAMS);

rdParams.szEntryName[0]='\0';
rdParams.szCallbackNumber[0] = '\0';
rdParams.szPhoneNumber[0]='\0';
rdParams.szUserName[0]='\0';
rdParams.szPassword[0]='\0';

strcpy( rdParams.szPhoneNumber , tel);
strcpy( rdParams.szUserName, user);
strcpy( rdParams.szPassword, pass);

rdParams.szDomain[0] = '\0';

DWORD RetVal = RasDial( NULL, NULL, &rdParams, 0L, NULL,
&hRasCon);

return hRasCon;
}

extern "C" __declspec(dllexport) DWORD WINAPI HangUp(HRASCONN
hRasConn)
{
DWORD RetVal = RasHangUp(hRasConn);
return RetVal;
}

Unfortunatly, I have to use MSVC 7 because my Dev-CPP is having all
kinds of issues with it, and I really don't understand what is going
on.

Thanks,
Tibby

Re: RAS Client by Igor

Igor
Tue Jul 13 12:31:59 CDT 2004

"Tibby" <tibby@tiberiansun.us> wrote in message
news:4e58f016r3cvvru9btp3knpq9c6hera5uq@4ax.com
> I've built a DLL that exports functions, and I think I've got it, but
> having a problem, here's my errors:
>
> RASDialer error LNK2019: unresolved external symbol _RasDialA@24
> referenced in function _Dial@12

Add Rasapi32.lib to the list of libraries in Project Options | Linker.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Re: RAS Client by William

William
Tue Jul 13 12:34:55 CDT 2004

"Tibby" <tibby@tiberiansun.us> wrote in message
news:4e58f016r3cvvru9btp3knpq9c6hera5uq@4ax.com...
> I've built a DLL that exports functions, and I think I've got it, but
> having a problem, here's my errors:
>
> RASDialer error LNK2019: unresolved external symbol _RasDialA@24
> referenced in function _Dial@12
>
> RASDialer error LNK2019: unresolved external symbol _RasHangUpA@4
> referenced in function _HangUp@4

Did you link against the RAS import library RASAPI32.LIB?

Regards,
Will



Re: RAS Client by Tibby

Tibby
Tue Jul 13 13:13:20 CDT 2004

On Tue, 13 Jul 2004 13:05:08 -0400, Tibby <tibby@tiberiansun.us>
wrote:

>On Mon, 12 Jul 2004 23:13:37 -0400, Tibby <tibby@tiberiansun.us>
>wrote:
>
>> I desperatly need to make some client software for my ISP. I
>>have tried using RAS from VB.NET and C# with no luck, and so I have to
>>turn to C++. As some have seen, I'm not the greatest with C++ yet, so
>>I was wondering if anyone had a good example of makeing a C++ wrapper
>>for RAS that I can export the function to call from VB/VB.NET or C#.
>>
>>Thank You,
>>Tibby
>
>UPDATE:
>
>I've built a DLL that exports functions, and I think I've got it, but
>having a problem, here's my errors:
>
>RASDialer error LNK2019: unresolved external symbol _RasDialA@24
>referenced in function _Dial@12
>
>RASDialer error LNK2019: unresolved external symbol _RasHangUpA@4
>referenced in function _HangUp@4
>
>
>And here's my complete code:
>
>#include "stdafx.h"
>#include "RAS.H"
>#include "RASERROR.H"
>
>RASDIALPARAMS rdParams;
>HRASCONN hRasCon = NULL;
>
>extern "C" __declspec(dllexport) HRASCONN WINAPI Dial(LPTSTR tel,
>
>LPTSTR user,
>
>LPTSTR pass)
>{
> rdParams.dwSize = sizeof(RASDIALPARAMS);
>
> rdParams.szEntryName[0]='\0';
> rdParams.szCallbackNumber[0] = '\0';
> rdParams.szPhoneNumber[0]='\0';
> rdParams.szUserName[0]='\0';
> rdParams.szPassword[0]='\0';
>
> strcpy( rdParams.szPhoneNumber , tel);
> strcpy( rdParams.szUserName, user);
> strcpy( rdParams.szPassword, pass);
>
> rdParams.szDomain[0] = '\0';
>
> DWORD RetVal = RasDial( NULL, NULL, &rdParams, 0L, NULL,
>&hRasCon);
>
> return hRasCon;
>}
>
>extern "C" __declspec(dllexport) DWORD WINAPI HangUp(HRASCONN
>hRasConn)
>{
> DWORD RetVal = RasHangUp(hRasConn);
> return RetVal;
>}
>
>Unfortunatly, I have to use MSVC 7 because my Dev-CPP is having all
>kinds of issues with it, and I really don't understand what is going
>on.
>
>Thanks,
>Tibby

That worked like a wet dream! I'm returning a non-zero handle now.
Now I just need to figure out how to use the callback function of
RasDial so I can moitor progress/error, and export that.

Thanks a million guys!

Tibby

Re: RAS Client by William

William
Tue Jul 13 17:53:11 CDT 2004

"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)



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

Re: RAS Client by Tibby

Tibby
Tue Jul 13 23:57:28 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)
>

I'm further boggled by the fact that it does dial, and initiate
connection, then disconnects. I verified with picking up another
phone and shceking my RAS logs.... Confusing LOL

Tibby