Re: DLL Marshalling : How do I treat a char FAR * HUGE * FAR * in C# ?
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 13 Jul 2005 13:25:39 -0400
Reynardine,
The P/Invoke layer doesn't know how to marsal arrays back to the managed
world. The reason for this is that it doesn't know what the size of the
array is (after all, it's only a pointer).
Because of this, you will have to marshal it as an IntPtr (or a ref
IntPtr) and then dereference the data yourself (you can use the methods on
the Marshal class to do this).
Also, are you supplying the memory where the strings are written to? If
not, then you need to make sure you dispose of the memory allocated by the
function correctly (whomever wrote the API should have provided a function
to do so).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Reynardine" <Reynardine@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E29E1ED9-5B36-4759-9955-10F1D49C3F5C@xxxxxxxxxxxxxxxx
>I am calling a C/C++ DLL from C# and I am marshalling the parameters to the
> API call by doing a type conversion for each parameter.
>
> For example, here is my C++ API method :
>
> short int XENO_API XcDatabaseCodes
> (
> HWND hwnd,
> char FAR * pszDatabase,
> char FAR * HUGE * FAR * pszItemCategories
> )
>
> The char FAR * HUGE * FAR * parameter is the address to return huge array
> of
> null terminated strings i.e. a list
>
> Here is my C# marshalling definition for this API :
>
> [DllImport("Xenoc32.dll")]
> public static extern int XcDatabaseCodes(
> string hWindowHandle ,
> string pszDatabase,
> ref string [] pszItemCategories );
>
> and here is my API call from C#
>
> const string pszDatabase = "\\\\NETWORK\\DATABASE";
> string [] pszItemCategories = {};
> int shReturnCode = XcDatabaseCodes(
> null,
> pszDatabase,
> ref pszItemCategories );
>
> The call returns ok but the trouble is I only get one item back.
>
> How should I declare and pass pszItemCategories to get the list.
>
.
- References:
- DLL Marshalling : How do I treat a char FAR * HUGE * FAR * in C# ?
- From: Reynardine
- DLL Marshalling : How do I treat a char FAR * HUGE * FAR * in C# ?
- Prev by Date: Getting just filename from FileDialog.FileName without path
- Next by Date: Re: I need Just a Grid, Not DataGrid
- Previous by thread: DLL Marshalling : How do I treat a char FAR * HUGE * FAR * in C# ?
- Next by thread: Flicker in setting opacity.
- Index(es):
Relevant Pages
|