[Mono-devel-list] P/Invoke question
Julio David Quintana
jdq at jdqi.com
Sun Aug 22 18:54:42 EDT 2004
Thanks for the tips and links. Looking at the code that calls
rrd_graph(), prdata (calcpr) looks to be a pointer to an array of
strings for holding some messages generated during the graph creation
process. xsize and ysize are filled during the process as well.. I am
not interested in any of this returned info (calcpr, xsize, ysize), so
I'd like to just fill the spots with dummy vars.
----- BEGIN rrd-tool.c -----
char **calcpr;
int xsize, ysize;
int i;
int tostdout = (strcmp(argv[2],"-") == 0);
if( rrd_graph(argc-1, &argv[1], &calcpr, &xsize, &ysize) != -1 ) {
if (!tostdout)
printf ("%dx%d\n",xsize,ysize);
if (calcpr) {
for(i=0;calcpr[i];i++){
if (!tostdout)
printf("%s\n",calcpr[i]);
free(calcpr[i]);
}
free(calcpr);
}
----- END -----
>Also important: if `prdata' is an "out" array of strings, what is the
>memory allocator? malloc(3)? g_malloc()? GlobalAlloc()?
>CoTaskMemAlloc()?
It is, and malloc is used. I checked out your P/Invoke doc, but most of
it went over my head. :)
Marcus:
Thanks for the code snippets. However, I could not get them to work
properly. data.cpp compiles and runs fine standalone, and compiles fine
as a shared lib, however, whenever data.cs calls it, garbage is
returned. Maybe I'm doing something silly.
Thanks again for all the help.
JDQ
Jonathan Pryor wrote:
>On Sat, 2004-08-21 at 18:56, Julio David Quintana wrote:
>
>
>>I'm trying to write bindings for rrdtool (librrd.so) and have run across
>>a triple-pointer situation that I'm not quite sure how to handle.
>>
>>Code:
>>int rrd_graph(int argc, char **argv, char ***prdata, int *xsize, int *ysize)
>>
>>
>
>Well, you could always use IntPtr, or `ref IntPtr', or...
>
>A better question is this: what does `prdata' represent? Is it an "out"
>pointer to an array of strings? Is it a triply-indirected single
>character pointer (unlikely, but possible). Is it an "in" pointer to a
>3-D matrix?
>
>You need to know what you're dealing with to properly P/Invoke with it.
>
>Also important: if `prdata' is an "out" array of strings, what is the
>memory allocator? malloc(3)? g_malloc()? GlobalAlloc()?
>CoTaskMemAlloc()?
>
>For more information, see:
>
> - The "Managed and Unmanaged Code Integration" guide, in monodoc
> (/Mono Handbook/Advanced Topics/Interoperability/Platform Invoke),
> or http://www.jprl.com/~jon/interop.html.
>
> - Interop Marshaling at MSDN (beware line wrapping):
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconinteropmarshaling.asp
>
> - Jon
>
>
>_______________________________________________
>Mono-devel-list mailing list
>Mono-devel-list at lists.ximian.com
>http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
More information about the Mono-devel-list
mailing list