PInvoke restriction: can not return variants

G

Guest

Any ideas why the following error occurs when "BuildExplicitAccessWithName"
is called?

PInvoke restriction: can not return variants

-----------------------------------------------------

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto, Pack:=4)> _
Public Structure EXPLICIT_ACCESS
Dim grfAccessPermissions As Integer
Dim grfAccessMode As Integer
Dim grfInheritance As Integer
Dim Trustee As TRUSTEE
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto, Pack:=4)> _
Public Structure TRUSTEE
Dim pMultipleTrustee As IntPtr
Dim MultipleTrusteeOperation As Integer
Dim TrusteeForm As Integer
Dim TrusteeType As Integer
Dim ptstrName As String
End Structure

Public Enum ACC_PERM
UserFullControl = &H10000000
UserExecute = &H20000000
UserRead = &H80000000
UserWrite = &H40000000
End Enum

Declare Function BuildExplicitAccessWithName Lib "advapi32.dll" Alias
"BuildExplicitAccessWithNameA" ( _
ByRef pExplicitAccess As EXPLICIT_ACCESS, _
ByVal pTrusteeName As String, _
ByVal AccessPermissions As Integer, _
ByVal AccessMode As Integer, _
ByVal Inheritance As Integer)

Const SET_ACCESS = 2&

' Inheritance Flags
Const CONTAINER_INHERIT_ACE = &H2

Const OBJECT_INHERIT_ACE = &H1

'Example to a calling Function
----------------------------------------

Public Function BuildExAcc() as EXPLICIT_ACCESS

Dim ea as EXPLICIT_ACCESS = New EXPLICIT_ACCESS()

Dim strUserName as String = "USERDOMAIN\USER" 'Replace with something valid

BuildExplicitAccessWithName(ea, strUserName, ACC_PERM.UserFullControl,
SET_ACCESS, CONTAINER_INHERIT_ACE Or OBJECT_INHERIT_ACE)

' If succesfull it will return "ea" with the "EXPLICIT_ACCESS"

Return ea
End Sub
 
H

Herfried K. Wagner [MVP]

Sterling said:
Any ideas why the following error occurs when
"BuildExplicitAccessWithName"
is called?

PInvoke restriction: can not return variants
[...]
Declare Function BuildExplicitAccessWithName Lib "advapi32.dll" Alias
"BuildExplicitAccessWithNameA" ( _
ByRef pExplicitAccess As EXPLICIT_ACCESS, _
ByVal pTrusteeName As String, _
ByVal AccessPermissions As Integer, _
ByVal AccessMode As Integer, _
ByVal Inheritance As Integer)

'Function' -> 'Sub'.
 
G

Guest

Thanks very much. That was it. I wasn't paying attention. You are the man.

Sterling

Herfried K. Wagner said:
Sterling said:
Any ideas why the following error occurs when
"BuildExplicitAccessWithName"
is called?

PInvoke restriction: can not return variants
[...]
Declare Function BuildExplicitAccessWithName Lib "advapi32.dll" Alias
"BuildExplicitAccessWithNameA" ( _
ByRef pExplicitAccess As EXPLICIT_ACCESS, _
ByVal pTrusteeName As String, _
ByVal AccessPermissions As Integer, _
ByVal AccessMode As Integer, _
ByVal Inheritance As Integer)

'Function' -> 'Sub'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top