Some of it looks good, some is less clear. It is always difficult to pinpoint what exactly is wrong; I tend to (1) keep data exchange simple and (2) add logging code on both sides, so I can see which arguments get accross correctly and which don't.
I do have 2 comments:
a native long* can be passed as a managed out long or ref long, it does not need an IntPtr at all. The way your template has it, it is promising the managed world will receive an output pointer, which then natively would require long**
Chances are this is what is causing the error.
I just don't know about szTemplate, I never use [MarshalAs(UnmanagedType.LPStr)] StringBuilder. I prefer a more verbose but easier to understand style as in:
public static extern long MatchPage(..., StringBuilder szTemplate, ...);
StringBuilder sb=new StringBuilder(1000);
MatchPage(..., sb, ...);
You must set an initial capacity, that is the size used to allocate the character buffer; and the safe way is to pass that Capacity to the native world so it won't overflow the buffer (similar to strncpy).
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:42 AM