Home All Groups Group Topic Archive Search About

calling (and deleting) a string from an unmanaged dll

Author
21 May 2009 9:37 AM
GiuseppeDini
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

Author
21 May 2009 10:47 AM
Henning
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
Author
21 May 2009 11:45 AM
GiuseppeDini
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
Author
21 May 2009 10:11 PM
Kevin Provance
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!

--
2025
If you do not believe in time travel,
your beliefs are about to be tempered.

http://www.facebook.com/group.php?gid=43606237254
Show quoteHide quote
"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