Skip to content

Commit

Permalink
Bugfix: -EntryPoint is not always applied properly
Browse files Browse the repository at this point in the history
Addresses #13. Thanks @jaredcatkinson!
  • Loading branch information
Matt Graeber committed Jun 25, 2017
1 parent 4861ffb commit 172a5cf
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions PSReflect.psm1
Expand Up @@ -207,14 +207,17 @@ are all incorporated into the same in-memory module.
Param(
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
[String]
[ValidateNotNullOrEmpty()]
$DllName,

[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
[String]
[ValidateNotNullOrEmpty()]
$FunctionName,

[Parameter(ValueFromPipelineByPropertyName = $True)]
[String]
[ValidateNotNullOrEmpty()]
$EntryPoint,

[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
Expand Down Expand Up @@ -304,12 +307,14 @@ are all incorporated into the same in-memory module.
$EntryPointField = $DllImport.GetField('EntryPoint')
if ($SetLastError) { $SLEValue = $True } else { $SLEValue = $False }

if ($PSBoundParameters['EntryPoint']) { $ExportedFuncName = $EntryPoint } else { $ExportedFuncName = $FunctionName }
if ($EntryPoint) { $ExportedFuncName = $EntryPoint } else { $ExportedFuncName = $FunctionName }

# Equivalent to C# version of [DllImport(DllName)]
$Constructor = [Runtime.InteropServices.DllImportAttribute].GetConstructor([String])
$DllImportAttribute = New-Object Reflection.Emit.CustomAttributeBuilder($Constructor,
$DllName, [Reflection.PropertyInfo[]] @(), [Object[]] @(),
$DllName,
[Reflection.PropertyInfo[]] @(),
[Object[]] @(),
[Reflection.FieldInfo[]] @($SetLastErrorField,
$CallingConventionField,
$CharsetField,
Expand Down

0 comments on commit 172a5cf

Please sign in to comment.