I have looked and looked and tried everything I can think of or have found suggested. I'm still not having any luck getting the data I need.
I'm using a third party DLL, which I believe is written in C. I need to access the functions from this DLL in C#. For the most part, I have this working, except for one function. The function I'm having problems with has the following header:
uint queryNumOfServers(USHORT *NumOfServers, char ServerNames[8][16]);
I have the following declared in my C# application
[DllImport("client.dll", CharSet=CharSet.Ansi]
public static extern uint queryNumOfServers(ref short numberofServer, StringBuilder serverNames);
I call this as follows:
StringBuilder serverNames = new StringBuilder(128);
short numServers = -1;
queryNumberOfServers(ref numServers, serverNames);
The problem is, while numberOfServers come back equal to 4, I only get one name in serverNames. I have tested the above C function in a small C program. I get back numberOfServer = 4 but I also get 4 names back.
I have tried the following with no success:
[DllImport("client.dll", CharSet=charSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern uint queryNumOfServers(ref short numberOfServer,[MarshalAs(UnmanagedType.LPStr)] string serverNames);
Called this with
string serverNames = new string('\0', 128);
queryNumOfServers(ref numServers, serverNames);
There is no change to serverNames with this option.
The development environment is Visual Studio 2008.