"gbraux" <gb****@supinfo.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
Hello,
I am using the Advapi32.dll CredEnumerate function through P/Invoke.
The CredEmunmerate is declared like this :
BOOL CredEnumerate(
LPCTSTR Filter,
DWORD Flags,
DWORD* Count,
PCREDENTIAL** Credentials
);
As you see, Credentials returns an array of pointers ... I know how to
work with single pointers (with PtrToStrucutre ...) but how to access
an array of pointers in C# ?
Thanks,
Guillaume
You need to enumerate the buffer returned marshaling each pointer into an IntPtr, something
like this will do:
[DllImport("advapi32", SetLastError = true, CharSet=CharSet.Unicode)]
static extern bool CredEnumerate(string filter, int flag, out int count, out IntPtr
pCredentials);
.....
int count = 0;
IntPtr pCredentials = IntPtr.Zero;
IntPtr[] credentials = null;
bool ret = CredEnumerate(null, 0, out count, out pCredentials);
if (ret != false)
{
credentials = new IntPtr[count];
IntPtr p = pCredentials;
for (int n = 0; n < count; n++)
{
if(Marshal.SizeOf(p) == 4) //32 bit CLR?
p = new IntPtr(p.ToInt32() + n);
else
p = new IntPtr(p.ToInt64() + n);
credentials[n] = Marshal.ReadIntPtr(p);
}
}
else
// failed....
.....
Willy.