I have a problem interfacing a DLL written in Ada. In C++ I do as follows:
typedef void(*pfGetItems)( char** ppsc, int num );
....
pfGetItems GetItems = (pfGetItems)::GetProcAddress(hModule, "GetItems");
next I create the char array:
char** pszBuf=new char*[num];
for (int i=0; i<num; i++)
pszBuf[i]=new char[100];
next I call the function and the result is stored in pszBuf. I have trouble
doing this in C#. I have tried the following:
[DllImport(@"Te.dll")]
private static extern void GetItems(ref StringBuilder[]Items, int num);
But, I can't make it work. Any tips on how to do this?
Best regards,
Eirik
> I have a problem interfacing a DLL written in Ada.
Ada? That's your problem right there!
Sorry, too cheap.
> In C++ I do as follows:
>
> typedef void(*pfGetItems)( char** ppsc, int num );
The calling convention is not clear. If this is really the declaration, that
means the function uses the C calling convention. (Most exported functions
in Windows use the stdcall calling convention.)
> ....
>
[quoted text clipped - 14 lines]
>
> private static extern void GetItems(ref StringBuilder[]Items, int num);
It's a little confusing, but StringBuilder only works for single strings.
This should work, if what you've shown so far is accurate:
[DllImport("Te.dll", CallingConvention = CallingConvention.Cdecl, CharSet =
CharSet.Ansi)]
static extern void GetItems([In, Out] string[] items, int num);
You call it like this:
string[] items = new string[<capacity>];
for (int i = 0; i != <capacity>, ++i) {
items[i] = new string('\0', 100);
}
GetItems(items, items.Length);
/* use items here */
It's important that the strings be initialized to a sufficient number of
characters, otherwise GetItems() will overfill. If you need to pass values
in, make sure to pad those to the expected size.

Signature
J.
news.broadpark.no - 10 Mar 2008 17:37 GMT
>> I have a problem interfacing a DLL written in Ada.
>
> Ada? That's your problem right there!
He he.....I agree with you, but we're talking heavy legacy here...
>..... It's a little confusing, but StringBuilder only works for single
>strings. This should work, if what you've shown so far is accurate:
[quoted text clipped - 12 lines]
> /* use items here */
>...
Works fine. Thank you!!!
Eirik