Adjustment of API in VFP

xiaoxiao2021-03-06  92

Dial-up mesh features in Visual FoxPro are difficult to call the corresponding Windows API function. Several API functions related to dial-up networks require complex structural types of parameters, in the VFP Help File "Programmer Guide - Access API", but is simpler, not enough to solve the problem, further discussion. I hope to solve the actual problem of achieving dial-up Internet access, more hoped to help with this example of how to invoke a complex API function in the VFP environment to extend the VFP application.

Because of the boundary, this article only discusses the key part, please refer to the reference file, please refer to the reference file.

The Rasdial function in the Windows API can realize dial-up metrics, and you can check in the MSDN help, and its parameters are as follows:

DWord rasdial (// Returns the four-by-one integer, corresponding to the INTEGER variable of VFP LPRASDIALEXTENSIONS LPRASDIALEXTENSISONS, / / ​​pointer, set NULL, LPCTSTSTR LPSZPHONEBOOK, / / ​​pointer, set NULL, LPRASDIALPARAMS LPRASDIALPARAMS, / / ​​pointer, point to parameter structure variables RasdialParams DWORD DWNOTIFIERTYPE, / / ​​4-Terminal integer, set 0, LPVOID LPVNOTIFIER, / / ​​pointer, set NULL, LPHRASCONN LPHRASCONN / / pointer, point to remote access connection handle Hrasconn. // Negulus first HRASCONN is NULL );

The structure RasdialParams is described below:

TypeDef struct _rasdialparams {dWord dwsize; // 4 byte, the value is this structure occupies the total byte number / / Before calling this function, you must assign this variable Tchar SzenTryName [RAS_MaxEnTryName 1]; // 257 bytes, dial-up network phone The connection name in the book, // is on the first modem port, establish the connection TCHAR SZPHONENUMBER [RAS_MAXPHONENUMBER 1]; // 129 bytes, phone number tchar szcallbacknumber [ras_maxcallbacknumber "with the following telephone number, user name, password 1]; // 129 bytes, reply number, empty tchar szusername [unlen 1]; // 257 bytes, username Tchar Szpassword [PWLEN 1]; // 257 bytes, password Tchar szdomain [ DNLEN 1]; // 16 bytes, domain name, blank #IF (WinVER> = 0x401) // By default, Winver = OX400, no two DWORD DWSUBENTRY; DWORD DWCALLBACKID; #ENDIF} rasdialparams;

The predefined values ​​such as RAS_MaxEntryName are available from Ras.H and LMCons.h. The difficulty is the determination of the dwsize value: the length of each variable byte in the structure is accumulated to 1049 bytes, but the 1049 is energized into DWSIZE to call the Rasdial function but return an error. After starting VC 6.0 defined a RasdialParams type structural variable, it is found that its length is 1052 bytes, i.e., closest to 1049 and can be removed by 4 (Dow of DWORD).

To this, the various parameters of the function rasdial are clear, and the call in the VFP is as follows: *! * First registration function

DECLARE INTEGER RasDial in rasapi32; INTEGER,; && lpRasDialExtensionsINTEGER,; && lpszPhonebookSTRING @,; && point RasDialParamsINTEGER,; && dwNotifierTypeINTEGER,; && lpvNotifierINTEGER @ && point hRasConn * * RasDialParams to structural variables in each variable initial values ​​dwSize = CHR (! 28) CHR (4) CHR (0) CHR (0) && is 4 * 256 28 = 1052SzENTRYNAME = Replicate (chr (0), 257) && does not use phone book STEMP = "95963" && server (Internet Phone number Tszphonenumber = STEMP Replicate (chr (0), 129-LEN (STEMP)) & Quick 129 byte szcallbacknumber = replicate (chr (0), 129) && call dial, blank STEMP = "263" && user name szusername = STEMP Replicate (chr (0), 257-len (stemp) && apostograms STEMP = "263" && password szpassword = STEMP Replicate (CHR (0), 257 -Len (STEMP) && Adjustments Szdomain = Replicate (CHR (0), 16) && If the self-built server, you can fill in the corresponding domain name *! * Generate Structure Variable RasdialParams Attenu RasdialParams = DWSIZE SZENTRYNAME TSZPHENENUMBER SzcallbackNumber; SzuserName Szpassword Szdomain Replicate (chr (0), 3) HRASCONN = 0 && Remote Access Connection handle, the initial value is 0DialResult = rasdial (0, 0, @ rasdialparams, 0, 0, @ harasconn)

The procedure for the disconnection is as follows:

Declare Integer Rashangup in Rasapi32 IntegerhangResult = Rashangup (Hrasconn)

Note the following:

* Pointer parameters (P or LP start) are usually passed in reference. The NULL pointer is special, its value is 0, the corresponding value of 0 in the VFP is 0 Integer type variables. The handle parameter (H starting) corresponds to the interger variable.

* API function hollow character ASCII code is 0, ie CHR (0).

The procedures in this article are compiled under Visual FoxPro 6.0, running in Windows98 and Windows2000.

转载请注明原文地址:https://www.9cbs.com/read-123318.html

New Post(0)