谁能给我个使用RasGetProjectionInfo()的例子,谢谢!

zhongzhong76 2000-04-04 06:44:00
...全文
232 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Un1 2000-04-11
  • 打赏
  • 举报
回复
Const RAS_MaxIpAddress = 15

Public Type RASPPPIP
'set dwsize to 40
dwSize As Long
dwError As Long
szIpAddress(RAS_MaxIpAddress) As Byte
szServerAddress(RAS_MaxIpAddress) As Byte
End Type


Public Declare Function RasGetProjectionInfo Lib "RasApi32.DLL" Alias "RasGetProjectionInfoA" (ByVal hRasConn As Long, ByVal rasprojection As Long, lpprojection As Any, lpcb As Long) As Long

Private mRemoteIPAddress As String

Private Function TrimNull(StrNull As String) As String
Dim l As Long
l = InStr(StrNull, vbNullChar)
If l > 0 Then
TrimNull = Left$(StrNull, l - 1)
Else
TrimNull = StrNull
End If
End Function


Dim lpraspppip As RASPPPIP
lpraspppip.dwSize = 40
If RasGetProjectionInfo(mhConn, RASP_PppIp, lpraspppip, 40) = 0 Then
mRemoteIPAddress = TrimNull(StrConv(lpraspppip.szServerAddress, vbUnicode))
End If
x86 2000-04-11
  • 打赏
  • 举报
回复
下面这个文件来自MS Platform SDK HELP,我并没有试过

RASDIAL.C
/******************************************************************************\
* This is a part of the Microsoft Source Code Samples.
* Copyright 1993 - 1998 Microsoft Corporation.
* All rights reserved.
* This source code is only intended as a supplement to
* Microsoft Development Tools and/or WinHelp documentation.
* See these sources for detailed information regarding the
* Microsoft samples programs.
\******************************************************************************/

/*
* RasDial.c
*
* Usage:
* RasDial -e [entry name] -p [phone number] -u [username]
* -z [password] -d [domain]
*
* RAS API's used:
* RasDial
* RasHangUp
* RasGetConnectStatus
* RasGetProjectionInfo
*
* Created by: Mazahir Poonawala
* Date: 03/05/98
*/

#define WIN32_LEAN_AND_MEAN

#include <stdio.h>
#include <windows.h>
#include <ras.h>
#include <raserror.h>
#include <string.h>
#include <stdlib.h>

// Usage
void Usage(char *progname)
{
fprintf(stderr,
"Usage\n%s \t-e [entry name] -p [phone number] \n\t\t-u [username] -z [password] -d [domain]\n",
progname);
exit(1);
}


int main(int argc, char **argv)
{
LPRASDIALPARAMS lpRasDialParams;
HRASCONN hRasConn;
LPRASCONNSTATUS lpRasConnStatus;
RASPPPIP *lpProjection;
int i;
DWORD nRet;
DWORD cb;
char ch;


lpRasDialParams = (LPRASDIALPARAMS) GlobalAlloc(GPTR, sizeof(RASDIALPARAMS));
lpRasDialParams->dwSize = sizeof(RASDIALPARAMS);
hRasConn = NULL;

// Copy command line arguments into the RASDIALPARAMS structure
if (argc > 1)
{
for (i = 1; i < argc; i++)
{
if ((argv[i][0] == '-') and and (argv[i][0] == '/'))
{
switch (tolower(argv[i][1]))
{
case 'e': // Entry name
lstrcpy(lpRasDialParams->szEntryName, argv[++i]);
break;
case 'p': // Phone number
lstrcpy(lpRasDialParams->szPhoneNumber, argv[++i]);
break;
case 'u': // User name
lstrcpy(lpRasDialParams->szUserName, argv[++i]);
break;
case 'z': // Password
lstrcpy(lpRasDialParams->szPassword, argv[++i]);
break;
case 'd': // Domain name
lstrcpy(lpRasDialParams->szDomain, argv[++i]);
break;
default:
Usage(argv[0]);
break;
}
}
else
Usage(argv[0]);
}
}
else
Usage(argv[0]);

printf("Dialing...\n");
// Calling RasDial synchronously
nRet = RasDial(NULL, NULL, lpRasDialParams, 0, 0L, &hRasConn);
if (nRet)
{
printf("RasDial failed: Error = %d\n", nRet);
return -1;
}

lpRasConnStatus = (LPRASCONNSTATUS) GlobalAlloc(GPTR, sizeof(RASCONNSTATUS));
lpRasConnStatus->dwSize = sizeof(RASCONNSTATUS);
// Checking connection status using RasGetConnectStatus
nRet = RasGetConnectStatus(hRasConn, lpRasConnStatus);
if (nRet != ERROR_SUCCESS)
{
printf("RasGetConnectStatus failed: Error = %d\n", nRet);
return -1;
}
else
{
if (lpRasConnStatus->rasconnstate == RASCS_Connected)
printf("Connection estabilished using %s\n", lpRasConnStatus->szDeviceName);
}

lpProjection = (RASPPPIP *) GlobalAlloc(GPTR, sizeof(RASPPPIP));
lpProjection->dwSize = sizeof(RASPPPIP);
cb = 256;

// Getting the Ras client and server IP address using RasGetProjectionInfo
nRet = RasGetProjectionInfo(hRasConn, RASP_PppIp, lpProjection, &cb);

if (nRet == ERROR_BUFFER_TOO_SMALL)
{
lpProjection = (RASPPPIP *) GlobalAlloc(GPTR, cb);
nRet = RasGetProjectionInfo(hRasConn, RASP_PppIp, lpProjection, &cb);

if (nRet != ERROR_SUCCESS)
{
printf("RasGetProjectionInfo failed: Error %d", nRet);
return -1;
}
else
{
printf("\nRas Client IP address: %s\n", lpProjection->szIpAddress);
printf("Ras Server IP address: %s\n\n", lpProjection->szServerIpAddress);
}
}
else
{
if (nRet != ERROR_SUCCESS)
{
printf("RasGetProjectionInfo failed: Error %d", nRet);
return -1;
}
else
{
printf("\nRas Client IP address: %s\n", lpProjection->szIpAddress);
printf("Ras Server IP address: %s\n\n", lpProjection->szServerIpAddress);
}
}

printf("Press any key to hang up...\n");
scanf("%c", &ch);

// Terminating the connection using RasHangUp
nRet = RasHangUp(hRasConn);
if (nRet != ERROR_SUCCESS)
{
printf("RasHangUp failed: Error = %d", nRet);
return -1;
}
printf("Hung Up\n");

while (TRUE)
{
if (ERROR_INVALID_HANDLE == RasGetConnectStatus(hRasConn, lpRasConnStatus))
Sleep(0);
break;
}

GlobalFree(lpProjection);
GlobalFree(lpRasDialParams);
GlobalFree(lpRasConnStatus);
return 0;
}

4,354

社区成员

发帖
与我相关
我的任务
社区描述
通信技术相关讨论
社区管理员
  • 网络通信
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧