[Mono-dev] Interop with Native Libraries Question
Sebi Onofrei
sebastian.onofrei at eyepartner.com
Wed Mar 5 05:09:27 EST 2008
Hello everyone.
Please help me translating one function in the correct way
I have a library from which I have to use some methods which is written
in C++.
The method I need to correctly translate is this:
*integer method_name(const void* a_handle, char* name, int* length)*
Now, what I tried looks like this:
* [DllImport (libraryName, EntryPoint = "method_name", CharSet =
CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
private static unsafe extern integer EXT_method_name(void*
handle, out string name, out int length);*
when I test the code I receive an integer that informs me that I
delivered Invalid parameters
Next I tried this:
* [DllImport (libraryName, EntryPoint = "method_name", CharSet =
CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
private static unsafe extern integer EXT_method_name(void*
handle, StringBuilder name, ref int length);*
this doesn't work either
Then I tried this:
* [DllImport (libraryName, EntryPoint = "method_name", CharSet =
CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
private static unsafe extern integer EXT_method_name(IntPtr
handle, StringBuilder name, out int length);*
and this doesn't work either :(
I have a similar method which works and looks like this:
*integer method_name(const void* a_handle, int* length)
*And my working "translation" is this:
* [DllImport (libraryName, EntryPoint = "method_name", CharSet =
CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
private static unsafe extern integer EXT_method_name(void*
handle, out int length);*
Any ideas about what I did wrong? I'm a total newbie with Interop
communication :)
I understood correctly that when I pass strings as parameters to that
external method I have to Marshal them, but when I need strings as
output... how
should I do this?
In mono's wiki there is an example with StringBuilder (the strncpy
example), but either I did something wrong or some different approach is
needed.
Thank you for all your efforts in helping me
With kind regards,
Sebastian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080305/bf042852/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sebastian_onofrei.vcf
Type: text/x-vcard
Size: 611 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080305/bf042852/attachment.vcf
More information about the Mono-devel-list
mailing list