Fantastic, that worked. Thank you very much.
Could I bother you for an explanation as to why this declaration works?
I thought that if strings were going to be allocated within
the my_function() I would need to use StringBuilder.
Ted
Mattias Sjögren wrote:
Hi Ted,
The reason Mattias' example works is because he is telling the CLR to create
pointers to old style un-managed strings. You were asking it to pass in a
stringbuilder object to the dll function by value.
Your dll function will only accept unmanaged strings, of type BStr which is
why he is using Marshalling for the string object, so that the CLR can
recognise this.
Hope this makes sense.
Nick
Fantastic, that worked. Thank you very much.
Could I bother you for an explanation as to why this declaration works?
I thought that if strings were going to be allocated within
the my_function() I would need to use StringBuilder.
Ted
Mattias Sj?gren wrote:
> >[DllImport("mydll.dll")]
> >public static extern int my_function( StringBuilder in,
StringBuilder
> >out);
>
[quoted text clipped - 13 lines]
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
teds@intex.com - 07 Dec 2004 14:59 GMT
[DllImport("mydll.dll")]
public static extern int my_function([MarshalAs(UnmanagedType.BStr)]
ref string input, [MarshalAs(UnmanagedType.BStr)] out string output);
So by making the parameters ref string and out string, this actually
makes them pointers to the variable ? The out is used only to indicate
that the direction of the data flow ? Finally, how do you decide to
use the string type versus the StringBuilder type?
Thanks again.
Ted
> Hi Ted,
>
[quoted text clipped - 44 lines]
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.799 / Virus Database: 543 - Release Date: 19/11/2004
Finally, when I try to do a
Console.Writeln( output ) ;
I get garbage. Do I need to marshal this value to get it to print and
to be accessible to my other code?
Thanks,
Ted