How can I use the _GetConfigString function of the new Toradex library in C#? I don’t see any example in the library help file. Only set functions are described
For example “Sys_GetConfigString” is defined in TdxAllLibraries.cs as
This kind of fixed length strings are removed from .NET C#. I can “allocate” the string with Nulls but it doesn’t work.
I think there is something else wrong. If I look at UInt32 (which works) a ref is used:
ref is used to pass an argument as a reference (pointer), so the C/C++ function can change the value in place. This is true for an integer. But, since C/C++ has no concept of “string” type, strings are just pointers to a null-terminated char array. So they don’t need the reference.
You may pre-allocate memory for your string using a StringBuilder and pass it to the API.
Hi Valter.
Yes I could use StringBuilder but I can’t pass a StringBuilder object to the function. It expects a string. Converting the StringBuilder object to a string doesn’t work. Did I oversee something?
You can change the prototype to accept a StringBuilder instead, the .NET runtime should do the marshaling automatically, passing the buffer associated with the StringBuilder to the function. The only thing you have to care about is to pre-allocate this buffer since C APIs usually expect that memory is allocated and released by the caller.
Also allocating a String with: