Using Sys_GetConfigString in C#


I’ve being trying to use function Sys_GetConfigString from Toradex CE Lib 2.1 in C# with .NET Compact Framework 3.5 with Visual Studio 2008 to get Mac Address.

public static extern bool Sys_GetConfigString(IntPtr hSys, string paramName, string pValue, UInt32 maxBytes);

I did everything to pre-allocate string for pValue but nothing works. Even changing lib to support StringBuilder instead of a string for pValue still doesn’t work.

string mac = new string('\0', 12);
StringBuilder mac = new StringBuilder(12);

Am I missing something? Please, I need help on this. Function Sys_GetConfigInt works perfectly to get all parameters involved like BspVersion, EbootVersion, etc.

Hi @rafael.assakawa

Please try the following for importing the function:

public static extern Int32 Sys_GetConfigString(IntPtr hSys, byte[] paramName, byte[] pValue, UInt32 maxBytes);

And the following for calling it:

IntPtr sys = Sys_Init();
Int32 ret;
byte[] mac = new byte[48];
ret = Sys_GetConfigString(sys, Encoding.Unicode.GetBytes("Mac"), mac, 48);

This should hopefully work.


Thanks. Using byte array instead of string I managed to get Mac Address.

Another option would be to use a stringbuilder. The definition then looks as follows:

public static extern UInt32 Gpio_GetConfigString(IntPtr hGpio, gpio.uIo io, string paramName2, StringBuilder pValue , Int32 maxBytes);

Regards, Andy

Can confirm the StringBuilder approach works on WEC2013:

public static extern UInt32 Sys_GetConfigString(IntPtr hSys, string paramName, StringBuilder pValue, UInt32 maxBytes);

It’d be nice if this was included in TdxAllLibraries.cs so (more) people don’t have to waste time debugging and searching for solutions.

Dear @Monomix
Thank you for the feedback. I added your suggestion to our bug and feature tracking system.
Regards, Andy