Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / October 2004

Tip: Looking for answers? Try searching our database.

IMetadataImport.EnumUserStrings garbage

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sacha Faust - 14 Oct 2004 20:06 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.