cannot convert from string to System.IntPtr
-
Hello, I have a P/Invoke to a C++ function:
int dll_registerAccount(char* uri, char* reguri, char*);
So I have done this:
[DllImport("pjsipDlld")]
static extern int dll_registerAccount(IntPtr uri,
IntPtr reguri);When I use this in my code:
success = dll_registerAccount("Bob", "Joe");
I get the following error message: cannot convert from string to System.IntPtr Am I going about this the wrong way? Many thanks for any advice,
-
Hello, I have a P/Invoke to a C++ function:
int dll_registerAccount(char* uri, char* reguri, char*);
So I have done this:
[DllImport("pjsipDlld")]
static extern int dll_registerAccount(IntPtr uri,
IntPtr reguri);When I use this in my code:
success = dll_registerAccount("Bob", "Joe");
I get the following error message: cannot convert from string to System.IntPtr Am I going about this the wrong way? Many thanks for any advice,
Change the IntPtr in your declaration to string and you might be all set.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
Hello, I have a P/Invoke to a C++ function:
int dll_registerAccount(char* uri, char* reguri, char*);
So I have done this:
[DllImport("pjsipDlld")]
static extern int dll_registerAccount(IntPtr uri,
IntPtr reguri);When I use this in my code:
success = dll_registerAccount("Bob", "Joe");
I get the following error message: cannot convert from string to System.IntPtr Am I going about this the wrong way? Many thanks for any advice,
Hi, when strings are input parameters and the native code is dealing with ANSI, not Unicode, then just typing the parameters as
string
should be sufficient. for output parameters, you would need a StringBuilder instance with sufficient capacity; and for Unicode native code, you would have to add "CharSet=CharSet.Unicode" to your DllImport. :)Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!