Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com

In C# library I wanted to call c function from YAZ library

YAZ_EXPORT int yaz_marc_decode_buf(yaz_marc_t mt, const char *buf, int bsize, char **result, int *rsize);

The problem was that I didn't know how to specify char **result in managed declaration. I didn't find similar samplers in Zoom.NET implementation.
The article
Call Unmanaged DLLs from C# recommended to use StringBuilder  for LPSTR (char*) but it wasn't enough.

After some experimentation I found that adding ref will do the trick(which makes sense).
So the c# declaration is the following:

        [DllImport("yaz.dll",

SetLastError = true,

CharSet = CharSet.Ansi,

CallingConvention = CallingConvention.Cdecl,

EntryPoint = "yaz_marc_decode_buf"

)]

        public static extern void yaz_marc_decode_buf(IntPtr yaz_marc_t, String marcBuf, int bsize,

           ref StringBuilder result, ref int rsize);

and the sample code :

StringBuilder result=new StringBuilder() ; /* for result buf */

int result_len = 0; /* for size of result */

YazExt.yaz_marc_decode_buf (_yazMarc, marc_buf, -1, ref result, ref result_len);

string sXml = result.ToString();

Posted on Tuesday, October 31, 2006 1:19 PM .Net Framework , Z39.50 | Back to top


Comments on this post: Calling C unmanaged DLL with with output parameters char **result from C#

# re: Calling C unmanaged DLL with with output parameters char **result from C#
Requesting Gravatar...
Hi friend, how was your work with zoom.net? i was trying to do a client and server z39 project, but i am very lost. Maybe, may you help me??? Sorry for my english :(
Left by Paul on Mar 30, 2009 12:36 PM

# re: Calling C unmanaged DLL with with output parameters char **result from C#
Requesting Gravatar...
I am not working with YAZ any more. Ask at YAZ mailing list. Also look at http://sourceforge.net/projects/zoomdotnet/
Left by Michael Freidgeim on Mar 30, 2009 8:12 PM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net