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 / Interop / June 2005

Tip: Looking for answers? Try searching our database.

Marhalling LPSTR

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Henning Krause [MVP - Exhange] - 20 Jun 2005 22:34 GMT
Hello,

I posted this question already, but in the wrong newsgroup... so here again:

I have a COM interface which has the following method:
HRESULT Item(
 [in] DWORD dwIndex,
 [in] DWORD dwWhichName,
 [in] DWORD cchLength,
 [out,size_is(cchLength)] LPSTR pszName
);

When I create a Wrapper-Dll with midl.exe and tlbimp.exe, this method is
converted to:

public void Item ( System.UInt32 dwIndex , System.UInt32 dwWhichName ,
System.UInt32 cchLength , System.String pszName )

pszName is supposed to be a buffer, so obviously, this won't work. I've
already decompiled the dll I generated with ildasm, the result is this:

.method public hidebysig newslot abstract virtual
           instance void  Item([in] unsigned int32 dwIndex,
                               [in] unsigned int32 dwWhichName,
                               [in] unsigned int32 cchLength,
                               [out] string  marshal( lpstr) pszName)
runtime managed internalcall

My question is: How do I need to modify this so that pszName becomes a
buffer that can be filled by the called method?

Some time ago I read something about using a StringBuilder... but I lost the
link.

Any ideas?

Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)
Ajit - 24 Jun 2005 18:56 GMT
Instead of using string use long and pass address of string. Use Marshalling
to manipulate the address to get back buffer.

Regards,
Ajit

> Hello,
>
[quoted text clipped - 38 lines]
> Try my free Exchange Explorer: Mistaya
> (http://www.infinitec.de/software/mistaya.aspx)
Henning Krause [MVP - Exchange] - 26 Jun 2005 15:12 GMT
Hello,

if anyone has a similar problem, here is a possible solution:

.method public hidebysignewslot abstract virtual instance void Item(
   [in] unsigned int32 dwIndex,
   [in] unsigned int32 dwWhichName,
   [in] unsigned int32 chLength,
   class [mscorlib]System.Text.StringBuilder marshal( lpstr) pszName)
   runtime managed internalcall

Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)

> Instead of using string use long and pass address of string. Use
> Marshalling
[quoted text clipped - 47 lines]
>> Try my free Exchange Explorer: Mistaya
>> (http://www.infinitec.de/software/mistaya.aspx)

Rate this thread:







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.