Another P Invoke Question

  • Thread starter Thread starter ba.hons
  • Start date Start date
B

ba.hons

Hello,

I have another method in a DLL which i am trying to use and i keep
getting null reference exception can anyone shed any light on this.

int GetConnectedControllers(char * controllers , int controllersSize)

which should return buffer of chars which indicates readers connected.
which i imagine looks like

"reader1,reader2 etc"

my decleration for this method in c# is

[DllImport("MyDll.dll", SetLastError = true, CharSet = CharSet.Ansi)]
static extern int GetConnectedControllers(out
System.Text.StringBuilder test5,
int ControllersSize);

then i call in my application

int x=Form1.GetConnectedControllers(out test5, 1000);

then test5 seems to go out of scope.

I am completely lost on this.

any help appreciated!

Adam
 
[DllImport("MyDll.dll", SetLastError = true, CharSet = CharSet.Ansi)]
static extern int GetConnectedControllers(out System.Text.StringBuilder test5,
^^^

Remove the out modifier.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top