Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

DllIport and char**

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
news.broadpark.no - 09 Mar 2008 18:50 GMT
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
Jeroen Mostert - 09 Mar 2008 20:38 GMT
> 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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.