Re: DLL Marshalling : How do I treat a char FAR * HUGE * FAR * in C# ?



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.
>


.



Relevant Pages

  • PInvoke Issues...
    ... I think I'm having PInvoke issues because I imported the service API ... strings and the DWORD correctly - yes? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Equivalent to GetKeyNameText for WM_APPCOMMAND messages?
    ... >> Is there an equivalent of the GetKeyNameText API for the WM_APPCOMMAND ... I need to create user-readable strings to use in my keyboard ... WM_APPCOMMAND has nothing directly to do with keyboard input. ...
    (microsoft.public.win32.programmer.ui)
  • Re: Suggested Alternative Unicode Implementation (for Rudy+ miscothers)
    ... Only if you were using strings other that UTF16 in your application. ... You want conversions? ... A versions of function prototypes as appropriate to an applications ... i.e. you have an ANSIString in your hand, you call the A API. ...
    (borland.public.delphi.non-technical)
  • Re: Compare words (not Strings)
    ... > In the core API, Strings can be checked either case sensitively are ... > use Soundex, Metaphone, or Levenshtein. ... > Soundex and Metaphone return Strings which are approximate pronunciations ... database might hold spices. ...
    (comp.lang.java.programmer)