|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
calling (and deleting) a string from an unmanaged dllMy (simplifed) vb code is: sub call() Dim ptr As System.IntPtr = readx() Dim str As String = Runtime.InteropServices.Marshal.PtrToStringAnsi(ptr) deletex(ptr) MsgBox(str) end sub <System.Runtime.InteropServices.DllImportAttribute ("stringprovider.dll", CharSet:=Runtime.InteropServices.CharSet.Ansi)> _ Public Function readx() As System.IntPtr End Function <System.Runtime.InteropServices.DllImportAttribute ("stringprovider.dll", CharSet:=Runtime.InteropServices.CharSet.Ansi)> _ Public Sub deletex(ByVal line As System.IntPtr) End Sub ---------------------------------------- And my c++ code the following: extern "C" __declspec(dllexport) char * readx (); char * readx () { char *line = new char(); line = "XXX line for testing XXX " ; } extern "C" __declspec(dllexport) void deletex (char * line); void deletex (char * line) { delete [] line; } Do you think there is som error? Giuseppe Hi,
You would better post the Q in microsoft.public.dotnet.languages.vb. In this group we deal with VB Classic (VB6 and below), and a few MVP's having a different opinion. ;) /Henning Show quoteHide quote "GiuseppeDini" <vv***@libero.it> skrev i meddelandet news:b2eb0693-9f13-4004-9b1d-2a5620d0a0f5@j12g2000vbl.googlegroups.com... >I need to call a string from a dll written in c++. > My (simplifed) vb code is: > > sub call() > Dim ptr As System.IntPtr = readx() > Dim str As String = > Runtime.InteropServices.Marshal.PtrToStringAnsi(ptr) > deletex(ptr) > MsgBox(str) > end sub > > <System.Runtime.InteropServices.DllImportAttribute > ("stringprovider.dll", CharSet:=Runtime.InteropServices.CharSet.Ansi)> > _ > Public Function readx() As System.IntPtr > End Function > > <System.Runtime.InteropServices.DllImportAttribute > ("stringprovider.dll", CharSet:=Runtime.InteropServices.CharSet.Ansi)> > _ > Public Sub deletex(ByVal line As System.IntPtr) > End Sub > > ---------------------------------------- > And my c++ code the following: > > extern "C" __declspec(dllexport) char * readx (); > char * readx () > { > char *line = new char(); > line = "XXX line for testing XXX " ; > } > > > extern "C" __declspec(dllexport) void deletex (char * line); > void deletex (char * line) > { > delete [] line; > } > > Do you think there is som error? > > Giuseppe On 21 Mag, 12:47, "Henning" <computer_h***@coldmail.com> wrote: Thank you!> Hi, > > You would better post the Q in microsoft.public.dotnet.languages.vb. > > In this group we deal with VB Classic (VB6 and below), and a few MVP's > having a different opinion. ;) > > /Henning I browsed all microsoft NGs but this one was the one which seemed to fit more my question. Giuseppe Then your browsing skills need some improvment. MSFT was good enough to
give you people your own groups, up to and including this one: microsoft.public.dotnet.framework.interop You see the word "interop"? Kind of a dead give away that's where interop questions should go. Learn some basic newsgroup or Google skills man and let us off the hook. Thanks ever so much in advance! -- Show quoteHide quote2025 If you do not believe in time travel, your beliefs are about to be tempered. http://www.facebook.com/group.php?gid=43606237254 "GiuseppeDini" <vv***@libero.it> wrote in message news:a05bb7ba-14ef-496d-a972-593477a0cda6@x6g2000vbg.googlegroups.com... | On 21 Mag, 12:47, "Henning" <computer_h***@coldmail.com> wrote: | > Hi, | > | > You would better post the Q in microsoft.public.dotnet.languages.vb. | > | > In this group we deal with VB Classic (VB6 and below), and a few MVP's | > having a different opinion. ;) | > | > /Henning | | Thank you! | I browsed all microsoft NGs but this one was the one which seemed to | fit more my question. | | Giuseppe |
|||||||||||||||||||||||