In my mind the DWORD does not compute - each of those options is represented by a checkbox in the normal Windows configuration GUI, and therefore it seems to me each should be a simple Boolean option.
That's exactly what they are...simple booleans. In fact each option is represented by a single binary bit. It's just that all the bits are put together into a lump of memory that is convenient for the processor to manipulate, in this case, a 32-bit unsigned value.
The ras.h #defines for this field are
/* RASENTRY 'dwfOptions' bit flags. */ #define RASEO_UseCountryAndAreaCodes 0x00000001 #define RASEO_SpecificIpAddr 0x00000002 #define RASEO_SpecificNameServers 0x00000004 #define RASEO_IpHeaderCompression 0x00000008 #define RASEO_RemoteDefaultGateway 0x00000010 #define RASEO_DisableLcpExtensions 0x00000020 #define RASEO_TerminalBeforeDial 0x00000040 #define RASEO_TerminalAfterDial 0x00000080 #define RASEO_ModemLights 0x00000100 #define RASEO_SwCompression 0x00000200 #define RASEO_RequireEncryptedPw 0x00000400 #define RASEO_RequireMsEncryptedPw 0x00000800 #define RASEO_RequireDataEncryption 0x00001000 #define RASEO_NetworkLogon 0x00002000 #define RASEO_UseLogonCredentials 0x00004000 #define RASEO_PromoteAlternates 0x00008000 #if (WINVER >= 0x401) #define RASEO_SecureLocalFiles 0x00010000 #endif #if (WINVER >= 0x500) #define RASEO_RequireEAP 0x00020000 #define RASEO_RequirePAP 0x00040000 #define RASEO_RequireSPAP 0x00080000 #define RASEO_Custom 0x00100000
As you can see, each option is a represented by a seperate bit in the 32-bit DWORD. This means that to determine the value required to set the options you were trying to set
$RASOPTIONS = "RASEO_IpHeaderCompression+RASEO_RemoteDefaultGateway+RA +SEO_SwCompression";
You need to combine the numeric values defined for each of the options you require. You can use +, but oring (|)them is the usual idiom with boolean values like this.
my $RASOPTIONS = 0x00000008 | 0x00000010 | 0x00000200;
This leaves $RASOPTIONS with a value of 0x00000218, which may not make much sense until you look at that in binary.
0x00000008 0000 0000 0000 0000 0000 0000 0000 1000 | 0x00000010 0000 0000 0000 0000 0000 0000 0001 0000 | 0x00000200 0000 0000 0000 0000 0000 0010 0000 0000 = 0x00000218 0000 0000 0000 0000 0000 0010 0001 1000
By representing these booleans this way, up to 32 different options can be stored in an efficient manor. Currently 21 of them are used which leaves 11 for future expansion without requiring big changes to the APIs.
It also make it possible to set, clear and test individual or combinations of options easily and efficiently.
# Set options # RASEO_IpHeaderCompression # RASEO_RemoteDefaultGateway # RASEO_SwCompression # without affecting any other options. $options |= 0x00000008 | 0x00000010 | 0x00000200; # Clear those same options again leaving every other option as it was $options &= ~(0x00000008 | 0x00000010 | 0x00000200); # do something if all three options are set # regardless of what other options are set. if( ($options & (0x00000008 | 0x00000010 | 0x00000200)) == (0x0000000 +8 | 0x00000010 | 0x00000200) ) { # do something } # Do something if ONLY those three options are set if( $options == (0x00000008 | 0x00000010 | 0x00000200) ) { # do it }
Of course, it is much more readable to use symbolic names instead of binary or hex constants for this, and you can do this nicely in perl by
use constant RASEO_IpHeaderCompression = 0x00000008;
which makes for nice, readable and efficient code. The only downside is that you will have to define these yourself as Perl doesn't read C header files. Actually it is possible to ask perl to pre-process your script through a C pre-preocessor using the -P option, but is "highly discouraged" and perlrun lists a whole bunch of reasons why you shouldn't do this. It also gives a better solution, Filter::cpp. If you have a compiler on your system, and therefor have access to ras.h, then you could use this to save you needing to hand-code all the constant definitions.
It is also fairly trivial matter to write a perl script to convert all the simple #defines in a header file into a set of constant definitions for inclusion into your module. If you built your own copy of perl, then there is at least one script included in sources for doing this.
Hope that this makes some sense and will assist you when you get time to persue the matter further. Good luck.
In reply to Re: Re: Re: help with Win32::API (Struct and general)
by BrowserUk
in thread help with Win32::API (Struct and general)
by mabman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |