среда, 24 мая 2017 г.

VPN WINAPI | Создание VPN соединения средствами WINAPI

#include <stdio.h>
#include <windows.h>
#include <strsafe.h>

#include <ras.h>
#include <raserror.h>

#include <string.h>
#include <winbase.h>
#include <time.h>
#include <stddef.h>
#include <stdlib.h>
#pragma comment(lib, "rasapi32.lib")

int main(void)
{
HRASCONN hConnection = NULL;
RASDIALPARAMSW RasDialParams;
memset (&RasDialParams, 0, sizeof (RasDialParams));
// Configure the RASDIALPARAMS structure.
RasDialParams.dwSize = sizeof (RasDialParams);
RasDialParams.szPhoneNumber[0] = TEXT('\0');
RasDialParams.szCallbackNumber[0] = TEXT('\0');
wsprintfW(RasDialParams.szEntryName, L"%s", L"test");
wsprintfW(RasDialParams.szUserName, L"%s",  L"test");
wsprintfW(RasDialParams.szPassword, L"%s",  L"test");
wsprintfW (RasDialParams.szDomain, L"%s", L"\0"); //This is optional


DWORD dwRet = RasSetEntryDialParamsW(0, &RasDialParams, 0);
#if (WINVER >= 0x601)
if (dwRet == ERROR_INVALID_SIZE)
{
RasDialParams.dwSize = offsetof(RASDIALPARAMSW, dwIfIndex);
dwRet = RasSetEntryDialParamsW(0, &RasDialParams, 0);
}
#elif (WINVER >= 0x401)
if (dwRet == ERROR_INVALID_SIZE)
{
RasDialParams.dwSize = offsetof(RASDIALPARAMSW, dwSubEntry);
dwRet = RasSetEntryDialParamsW(0, &RasDialParams, 0);
}
#endif

DWORD dwCode = RasDialW(NULL,      // Extension not supported
NULL, // Phone book is in registry
&RasDialParams, // RAS configuration for connection
0xFFFFFFFF, // Notifier type is a window handle
NULL, // Window receives notification message
&hConnection);

RasHangUp(hConnection);

return dwCode;
}

Комментариев нет:

Отправить комментарий