< Back
Import-Struct
Post
NAME Import-Struct
SYNOPSIS
Defines a struct.
SYNTAX
Import-Struct [-ModuleBuilder] <ModuleBuilder> [-Name] <String> [-Fields] <Hashtable[]> [[-PackingSize]
{Unspecified | Size1 | Size2 | Size4 | Size8 | Size16 | Size32 | Size64 | Size128}] [<CommonParameters>]
DESCRIPTION
Defines a struct in the ModuleBuilder specified.
PARAMETERS
-ModuleBuilder <ModuleBuilder>
The ModuleBuilder to define the struct in.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Name <String>
The name of the struct to define.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Fields <Hashtable[]>
A list of hashes that define the fields of the struct. Each value in the fields list should be a hash with the
following keys;
Name: The name of the field.
Type: The type of the field.
MarshalAs: Optional hash that defines the MarshalAs attribute based on the Set-MarshalAsAttribute
parameters.
Type: Sets the [MarshalAs(UnmanagedType.)] value for the parameter.
SizeConst: Optional SizeConst value for MarshalAs.
ArraySubType: Optional ArraySubType value for MarshalAs.
Required? true
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-PackingSize
Set the Pack value for the StructLayout attribute.
Required? false
Position? 4
Default value Unspecified
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$module_builder = New-DynamicModule -Name PInvokeHelper
$struct_definition = @{
Name = 'TOKEN_PRIVILEGES'
Fields = @(
@{
Name = 'PrivilegeCount'
Type = ([System.UInt32])
},
@{
Name = 'Privileges'
Type = 'LUID_AND_ATTRIBUTES[]'
MarshalAs = @{
Type = [System.Runtime.InteropServices.UnmanagedType]::ByValArray
SizeConst = 1
}
}
)
}
Import-Struct -ModuleBuilder $module_builder @struct_definition
RELATED LINKS
SYNOPSIS
Defines a struct.
SYNTAX
Import-Struct [-ModuleBuilder] <ModuleBuilder> [-Name] <String> [-Fields] <Hashtable[]> [[-PackingSize]
{Unspecified | Size1 | Size2 | Size4 | Size8 | Size16 | Size32 | Size64 | Size128}] [<CommonParameters>]
DESCRIPTION
Defines a struct in the ModuleBuilder specified.
PARAMETERS
-ModuleBuilder <ModuleBuilder>
The ModuleBuilder to define the struct in.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Name <String>
The name of the struct to define.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Fields <Hashtable[]>
A list of hashes that define the fields of the struct. Each value in the fields list should be a hash with the
following keys;
Name: The name of the field.
Type: The type of the field.
MarshalAs: Optional hash that defines the MarshalAs attribute based on the Set-MarshalAsAttribute
parameters.
Type: Sets the [MarshalAs(UnmanagedType.)] value for the parameter.
SizeConst: Optional SizeConst value for MarshalAs.
ArraySubType: Optional ArraySubType value for MarshalAs.
Required? true
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-PackingSize
Set the Pack value for the StructLayout attribute.
Required? false
Position? 4
Default value Unspecified
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$module_builder = New-DynamicModule -Name PInvokeHelper
$struct_definition = @{
Name = 'TOKEN_PRIVILEGES'
Fields = @(
@{
Name = 'PrivilegeCount'
Type = ([System.UInt32])
},
@{
Name = 'Privileges'
Type = 'LUID_AND_ATTRIBUTES[]'
MarshalAs = @{
Type = [System.Runtime.InteropServices.UnmanagedType]::ByValArray
SizeConst = 1
}
}
)
}
Import-Struct -ModuleBuilder $module_builder @struct_definition
RELATED LINKS