Mattias, please help me.
I don't expect you to do my programming for me, just shine a little light
into the black void of unmanaged type marshalling.
I'm trying to host the scripting engine. In fact I've already got this
working in Delphi, but I just can't get my C# interfaces right.
The interfaces of interest are IActiveScript, IActiveScriptSite,
IActiveScriptSiteWindow, IActiveScriptParse and IActiveScriptError.
They're all documented in MSDN. Oh how I wish there was a typelib for these
interfaces. Just for the sake of argument, here's one example that puzzles
me.
HRESULT AddNamedItem(
LPCOLESTR pstrName, // address of item name
DWORD dwFlags // item flags
);
Research revealed that LPCOLESTR means long pointer to constant wide
string. I'm not really sure how this differs from an LPWStr, but this is
what I made of it (I don't think I've got it right). ScriptItem is an
enumeration I created for the flags.
void AddNamedItem(
[MarshalAs(UnmanagedType.LPWStr)] string pstrName,
ScriptItem dwFlags
);
Mattias, considering that I've already got this to work in another
programming language, I can't believe how much grief I'm getting trying to
map types.
I don't suppose you have a table of equivalences?
Peter Wone
Peter,
>Mattias, please help me.
I'd appreciate if you didn't attribute messages directly to me in
these groups. There are many smart people helping out here that may be
able to help you quicker and better than I can, so I think it's unwise
(and somewhat rude) to exclude them.
>Research revealed that LPCOLESTR means long pointer to constant wide
>string. I'm not really sure how this differs from an LPWStr,
In practice it doesn't. String (or StringBuilder) set to marshal as
LPWStr is the right managed representation of LP(C)OLESTR.
>void AddNamedItem(
> [MarshalAs(UnmanagedType.LPWStr)] string pstrName,
> ScriptItem dwFlags
>);
Looks correct to me. How is it not working?
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Peter Wone - 29 Jan 2004 05:17 GMT
Fair enough, to anyone who felt excluded I apologise.
> >Research revealed that LPCOLESTR means long pointer to constant wide
> >string. I'm not really sure how this differs from an LPWStr,
[quoted text clipped - 6 lines]
> > ScriptItem dwFlags
> >);
There's a whole raft of interfaces involved in hosting a script engine (see
original post) and it is entirely possible that this particular signature
would work if I got that far. I chose that method signature as an example
because it is the simplest method signature I could find that uses
LPCOLESTR.
I'll have another go; knowing the correct translation LPCOLESTR tells me to
look elsewhere for the problems.
Why don't I rip a typelib from the Microsoft Script Control OCX and use
that? That's exactly what I've done as an interim measure. But it hides the
setup of the script site which prevents me from installing hooks for my
debugger - what's the good of an application that supports user defined
scripts if your users can't debug them?
In the short term the scripting OCX is adequate; this isn't holding up the
development cycle. But sooner or later I'll have to deal with it.