Returning a VARIANT ARRAY

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I am wondering what i need to do here in my VB.NET class library.

Overall, the error I am getting is this:

DLLIMPort PInvoke restriction: cannot return variants.

I'm open to changing code. This is what I have now that works under VB6.

Declare Function GetAccessProfileNames _
Lib "wcvb.dll" Alias "vbGetAccessProfileNames" () As Variant

The wcvb.dll wrapper library has this for the function:

VARIANT APIENTRY vbGetAccessProfileNames()
{
VARIANT v;
VariantInit(&v);
int count = GetAccessProfileCount();
TSecurityName *names = new TSecurityName[count];
if (!GetAccessProfileNames(count, names)) {
delete []names;
return v;
}
GetStringArray(v, names[0], SIZE_SECURITY_NAME, count);
delete []names;
return v;
}

and in VB6, it can be uses as

Dim names As Variant
names = GetAccessProfileNames()

For the class library, I have:

<DllImport("wcvb.dll", EntryPoint:="vbGetAccessProfileNames",
SetLastError:=True)>
Public Shared Function GetAccessProfileNames() As Object
End Function

Using it

Dim alist as Object = GetAccessProfileNames()

yields the PInvoke restriction: cannot return variants.

I tried other combinations like:

<DllImport("wcvb.dll", EntryPoint:="vbGetAccessProfileNames",
SetLastError:=True)>
Public Shared Function GetAccessProfileNames() As TSecurityName()
End Function

And I get a Exception:

Cannot marshal 'return value': Invalid managed/unmanaged type
combination.

How should I do this with VB.NET?

Thanks

--
 
' you can try


dim howmanyYouNeed as Int32=100

Dim alist(howmanyYouNeed) as Object = GetAccessProfileNames()
 
Hi,

This is already for years now the area from Tom and Herfried and sometimes
Armin.

I assume that you have to use the Stringbuilder type (therefore Tom).

Tom is probably sleeping now there at the West Coast of the USA.

As long as others have not replied on your message with more than a guess,
have a look at this message from Tom.
It is not the latest he has made much more in this area.

http://groups.google.com/group/microsoft.public.dotnet.languages.vb/msg/5ed901dd13462138

Cor
 
Back
Top