Re: Inverse P/Invoke an pointer to pointer
From: Sean Hederman (usemy_at_blogentry.com)
Date: 02/28/05
- Next message: Matt Dee: "Re: Quick question on the Managed Heap"
- Previous message: William DePalo [MVP VC++]: "Re: Quick question on the Managed Heap"
- In reply to: Louis Haußknecht: "Re: Inverse P/Invoke an pointer to pointer"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 28 Feb 2005 07:12:58 +0200
You're going to need the System.Runtime.InteropServices.Marshal class for
this one:
int Configure(IntPtr iu_parentHandle, ref IntPtr iop_config, int ini_size) {
Marshal.FreeHGlobal(iop_config); //
LocalFree
iop_config = Marshal.StringToHGlobalAnsi("My string"); // Assuming
ANSI - This uses LocaAlloc to allocate for the size of string you pass in.
...
}
"Louis Haußknecht" <haussknecht@hapas.de> wrote in message
news:422262e3$0$26540$9b4e6d93@newsread4.arcor-online.net...
> Hey Sean,
>
> thank you very much for your help. No the native app is loading my plugin,
> but i encountered another problem.
> The string parameter is used to store the configuration of the plugin.
> According to the API documentation we have to resize the memory if it is
> too small using LocalFree and LocalAlloc.
>
> Is it true that we have to use these functions to allocate memory or is
> the GC doing this task for us?
>
> Regards,
> Louis
>
> "Sean Hederman" <usemy@blogentry.com> schrieb im Newsbeitrag
> news:cvqqip$a57$1@ctb-nnrp2.saix.net...
>> Well it's a pointer to a char*, and char* is a string, so:
>>
>> int Configure(IntPtr iu_parentHandle, ref string iop_config, int
>> ini_size);
>>
>> unless the Configure call is creating the string, in which case use out
>> instead of ref.
>>
>> "Louis Haußknecht" <haussknecht@hapas.de> wrote in message
>> news:4220afaa$0$26554$9b4e6d93@newsread4.arcor-online.net...
>>> Hi,
>>>
>>> this is the first time I'm using "inverse P/Invoke".
>>>
>>> I need to build a plugin for a unmanaged application. This application
>>> is needing three functions.
>>>
>>> One of the function (#Configure) has to be called like this:
>>>
>>> int Configure(HWND iu_parentHandle,char **iop_config, const int
>>> ini_size)
>>>
>>> My question is how to handle a pointer to a pointer?
>>>
>>>
>>>
>>> Thanks in advance,
>>>
>>> Louis Haußknecht
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>
>
- Next message: Matt Dee: "Re: Quick question on the Managed Heap"
- Previous message: William DePalo [MVP VC++]: "Re: Quick question on the Managed Heap"
- In reply to: Louis Haußknecht: "Re: Inverse P/Invoke an pointer to pointer"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|