Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2004

Tip: Looking for answers? Try searching our database.

Mattias - I got the UnmanagedType blues

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Wone - 26 Jan 2004 22:40 GMT
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
Mattias Sj?gren - 28 Jan 2004 21:58 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.