Using Pinvoke with Char*

So I had a c++ .dll that I wanted to use in my vb.net program. I was told that

this was the header

extern “C” __declspec(dllimport)void  getPassword(char *inputString, char *outputString);

After much reading/researching/testing I finally got this to work.

Imports System.Runtime.InteropServices
Imports System.Text

<DllImport(“c:\\Password.dll”)> _
Public Shared Sub getPassword(ByVal inputString As StringBuilder, ByVal outputString As StringBuilder)

Dim input As String = “testing”
Dim result As New StringBuilder
Dim send As New StringBuilder(input)

getPassword(send, result)
MsgBox(result.ToString)

The trick was using the StringBuilders for the Char*

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 242 other followers

%d bloggers like this: