Using Pinvoke with Char*

So I had a c++ .dll that I wanted to use in my 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)

The trick was using the StringBuilders for the Char*


Leave a Reply

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

You are commenting using your 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 )

Connecting to %s