-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathras.cpp
129 lines (103 loc) · 2.63 KB
/
ras.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "stdafx.h"
#include <ras.h>
#include <raserror.h>
#include <Wininet.h>
#include "DoHide.h"
#include "globals.h"
#include "menu.h"
#include "ras.h"
const char szRasDLL[] = "rasapi32.dll";
const char szRasEnumEntries[] = "RasEnumEntriesA";
const char szWinNTCmdLine[] = "-d \"%s\"";
const char szWinNTDialer[] = "RasPhone.exe";
const char szWin95CmdLine[] = "rnaui.dll,RnaDial %s";
const char szWin95Dialer[] = "RunDll.exe";
CRas ras;
/*
*
*
*/
void CRas::LoadRasLibrary ()
{
hRAS = LoadLibrary( szRasDLL );
_RasEnumEntries = ( hRAS ) ? _RasEnumEntries = (fnRasEnumEntries)GetProcAddress( hRAS, szRasEnumEntries ) : 0;
}
/*
*
*
*/
void CRas::FreeRasLibrary ()
{
if ( hRAS )
FreeLibrary( hRAS );
}
/*
*
*
*/
void CRas::EnumEntries(HMENU hMenu, int iMenuItem)
{
RASENTRYNAME* lpRasEntryName = (RASENTRYNAME*)GlobalAlloc(GPTR, sizeof(RASENTRYNAME));
lpRasEntryName->dwSize = sizeof(RASENTRYNAME);
DWORD nRet;
DWORD cb;
DWORD cEntries;
LoadRasLibrary();
if ( _RasEnumEntries )
{
cb = sizeof(RASENTRYNAME);
if ( (nRet = (*_RasEnumEntries)(NULL, NULL, lpRasEntryName, &cb, &cEntries))==ERROR_BUFFER_TOO_SMALL )
{
GlobalFree( lpRasEntryName );
lpRasEntryName = (RASENTRYNAME*)GlobalAlloc(GPTR, cb);
lpRasEntryName->dwSize = sizeof(RASENTRYNAME);
}
// Calling RasEnumEntries to enumerate the phone-book entries
nRet = (*_RasEnumEntries)(NULL, NULL, lpRasEntryName, &cb, &cEntries);
if (nRet == ERROR_SUCCESS)
{
RASENTRYNAME* lpTempRasEntryName = lpRasEntryName;
for ( DWORD i=0; i<cEntries; i++,lpTempRasEntryName++ )
{
int len = lstrlen(lpTempRasEntryName->szEntryName);
char* ptr = new char[len+1];
lstrcpy( ptr, lpTempRasEntryName->szEntryName );
MENUITEMINFO mInfo;
mInfo.cbSize = sizeof(MENUITEMINFO);
mInfo.fMask = MIIM_ID|MIIM_TYPE|MIIM_DATA;
mInfo.fType = MFT_OWNERDRAW;
mInfo.hSubMenu = 0;
mInfo.dwItemData = CustomMenu.AddItem( (int)ptr, MIT_DIALUP_NAME );
mInfo.wID = WM_EXECUTE_CUSTOM_MENU + mInfo.dwItemData;
InsertMenuItem(hMenu, 2+iMenuItem, TRUE, &mInfo);
iMenuItem++;
}
}
}
FreeRasLibrary();
GlobalFree( lpRasEntryName );
}
/*
*
*
*/
bool CRas::Dial( char* szRasEntryName )
{
char s[64];
SHELLEXECUTEINFO sei;
ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO));
if ( isWinNT )
{
wsprintf( s, szWinNTCmdLine, szRasEntryName );
sei.lpFile = szWinNTDialer;
}
else
{
wsprintf( s, szWin95CmdLine, szRasEntryName );
sei.lpFile = szWin95Dialer;
}
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.nShow = SW_SHOWNORMAL;
sei.lpParameters = s;
return ShellExecuteEx(&sei)==TRUE;
}