Click to See Complete Forum and Search --> : Error: ByRef Type Mismatch


CecileR
July 13th, 2001, 04:38 AM
What's wrong with my code. It has an error ByRef
Type Mismatch.

dim Servername() As Byte
dim grpusr as USER_INFO_2
dim user() As Byte
Dim num_entries As Long
Dim res
Dim h AS Long


Private Type GROUP_USERS_INFO_0
grui0_name As String
End Type

Private Declare Function NetUserSetGroups Lib "netapi32" _
(servername As Byte, _
username As Byte, _
ByVal level As Long, _
lpBuffer As Long, _
num_entries As Long) As Long

h = 0
grpusr.grui0_name = StrConv("Users" & Chr$(0), vbUnicode)
res = NetUserSetGroups(bServername(0), user(0), ByVal h, grpusr, num_entries) '-----This line gets an error

The more u read, the more u do not know

phunkydude
July 13th, 2001, 06:46 AM
If you gave all the code that's implicated then here's a run down...
Always put you constants at the top of the module,
then the type declarations,
then the API declarations
Having done that you may also notice that nowhere do you define USER_INFO_2 (I think you meant GROUP_USERS_INFO_0 instead).

HTH

CecileR
July 13th, 2001, 06:55 AM
Yes, sorry i was wrong in typing..bec of wanting to get it done.. and the code is longer so i extracted it. Anyway. thanks for the correction.

it should be

grp_usr As GROUP_USERS_INFO_0

..I have a hint why its passing Error 2221.
Maybe i passed only the username as it is..not
telling where it comes from like
user = "\\domainname\username"

But when I replace this code it gives an error
no 87. Why is that?

cecile

The more u read, the more u do not know

Clearcode
July 13th, 2001, 07:15 AM
LpBuffer is wanting a pointer to the structure. Either pass the structure type in the declaration:


private Type GROUP_USERS_INFO_0
grui0_name as string
End Type

private Declare Function NetUserSetGroups Lib "netapi32" _
(servername as Byte, _
username as Byte, _
byval level as Long, _
lpBuffer as GROUP_USERS_INFO_0, _
num_entries as Long) as Long




or if you don't wish to do this (maybe the API accepts different structures?) the use VarPtr to pass the pointer thus:


res = NetUserSetGroups(bServername(0), user(0), byval h, VarPtr(grpusr), num_entries)




The former method is considered more correct as VarPtr is an undocumented command in VB.

Hope this helps,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com