Re: Inverse P/Invoke an pointer to pointer

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Sean Hederman (usemy_at_blogentry.com)
Date: 02/28/05


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



Relevant Pages

  • Re: malloc a struct?
    ... > int number; ... assign to the string member of a structure object that hasn't yet ... been allocated, although you could allocate the memory for the ... That'd have to be sizeof (struct myStruct1) based on your ...
    (comp.lang.c)
  • Re: does a program work in all cases?
    ... int main{ ... char** arr; ... puts("Failed to allocate memory"); ... strcpy(arr, STRING); ...
    (comp.lang.c)
  • Network Impersonation Question
    ... public static extern int LogonUser(String lpszUsername, String lpszDomain, ... String lpszPassword, ... int dwLogonType, int dwLogonProvider, ref IntPtr phToken); ... impersonationContext = tempWindowsIdentity.Impersonate; ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • [PATCH] bigphysarea for 2.6.10 en 2.6.11
    ... +contineous memory for the entire runtime of Linux. ... +The big physical area is mainly managed by two functions. ... +caddr_t bigphysarea_alloc_pages(int count, int align, int priority) ... second it is not possible to allocate some memory ...
    (Linux-Kernel)
  • [PATCH 3/5] swiotlb: Make all bookkeeping functions and variables have same prefix.
    ... When the IOMMU overflows we return a fallback buffer. ... static int late_alloc; ... Allocate and initialize the free list array. ...
    (Linux-Kernel)