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.

How to pass string from COM to .Net using interop and change these strings in .Net ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
javd - 01 Jun 2005 16:31 GMT
Hi all,

I need to
1. .Net dll with a method
   public bool myMethod (string inVal, ref StringBuilder outVal)
   {
               string temp = "test";
               int size = temp.Length;
               StringBuilder res = new StringBuilder(size);
               res.Append(Iterator.Current.Value);
               outVal = res;
   }

2. c++ program that calls this .Net dll

   LPWSTR* outVal;
   bool result = myMethod ("xyz",outVal);

I have not managed yet to get this working. I have a runtime error :

   Windows has triggered a breakpoint in ATLtest.exe.

   This may be due to a corruption of the heap, and indicates a bug in
ATLtest.exe or any of the DLLs it has loaded.

   The output window may have more diagnostic information

What is the correct way to pass strings from a COM component to a .Net,
modify the string in .Net, and pass it back again to the COM component ?
Mattias Sjögren - 02 Jun 2005 13:34 GMT
>What is the correct way to pass strings from a COM component to a .Net,
>modify the string in .Net, and pass it back again to the COM component ?

Make the parameter type a ref string. It will marshal to a BSTR* on
the unmanaged side.

Mattias

Signature

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


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.