I'm calling IMetadataImport.EnumUserStrings from managed code and it's
returning me garbage strings.
I've converted the the interface method in managed code this way:
void EnumUserStrings(
ref IntPtr phEnum,
[Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder rStrings,
[In] uint cmax,
out uint pcStrings);
I always set the cmax value to 0. Here is the code that calls it
ArrayList userStrings = new ArrayList();
StringBuilder rStrings = new StringBuilder();
IntPtr phEnum = IntPtr.Zero;
uint pcStrings = 0;
try {
this.IMetaDataImport.EnumUserStrings( ref phEnum, rStrings, 1, out
pcStrings );
while (pcStrings != 0) {
userStrings.Add( rStrings.ToString() );
this.IMetaDataImport.EnumUserStrings( ref phEnum, rStrings, 1, out
pcStrings );
}
return userStrings;
}
finally {
this.IMetaDataImport.CloseEnum( phEnum );
}
Did anyone tried this in managed code and know what I'm doing wrong?
Mattias Sj?gren - 14 Oct 2004 21:58 GMT
>Did anyone tried this in managed code and know what I'm doing wrong?
The second parameter isn't a LPWSTR, but an array of mdString tokens
to be filled. So you should probably change the parameter type to
uint[] in managed code. You then retrieve each string with
GetUserString().
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.