Well I need to pass the location of a string in memory to a function. In C++ you would just do &string but what do you do in C#? I have tried many things and nothing seems to work.
Printable View
Well I need to pass the location of a string in memory to a function. In C++ you would just do &string but what do you do in C#? I have tried many things and nothing seems to work.
Just on C# you don't need to use Pointers and you don't need to delete them because of garbage collection. But you can use pointers. You declare them like so...
Code:int *a;
Ya but I need to call a function that uses the strings location.Quote:
Originally Posted by Hell-Lord
You can also use the Marshal.StringToBSTR to get an IntPtr to an unmanaged string that you can then pass to your function. BSTRToString will convert back again if needed. Make sure you read the documentation first if you choose to use these methods.
Are you talking about a DLL function? Just use a StringBuilder, they are automatically marchalled as char*.
(you'll have to alter your DllImport statement to change char* to Stringbuilder in your C# code).