Using IActiveScript interfaces in C#

Using IActiveScript interfaces in C#

Post by David McAliste » Wed, 28 May 2003 15:51:40



Hello,

I am trying to write a script engine host in C#, specifically the JScript
engine.  I was wondering if anyone has a definition for the IActiveScriptXXX
interfaces in C# ?  I have got so far by looking at the IDL and header
files, but came across a problem.  I create the script engine and give it my
C# class (this) as the Site - it calls GetItemInfo to get a named item that
I added - but I am not sure how to define this function for .Net interop.
The problem seems to be that when the engine asks for an IUnknown pointer
(SCRIPTINFO_IUNKNOWN), the ITypeLib** pointer is not a valid pointer and
causes the .Net marshaller to crash.  The only way I have been able to get
further is do define the GetItemInfo as follows :-

void GetItemInfo([In,MarshalAs(UnmanagedType.LPWStr)] string pstrName,
    [In,MarshalAs(UnmanagedType.U4)] uint dwReturnMask,
    [Out,MarshalAs(UnmanagedType.IUnknown)] out object ppiunkItem,
    [Out,MarshalAs(UnmanagedType.Interface)] UCOMITypeLib ppti);

This is basically a hack, by making the 'ppti' a non-out param it is not
marshalled and I no longer get a crash, however I am unable to pass back
ITypeInfo if required (currently I don't need to do this).

Any help appreciated.

Dave McAlister

 
 
 

Using IActiveScript interfaces in C#

Post by Mattias Sj?gre » Wed, 28 May 2003 16:51:42


David,

Quote:>The problem seems to be that when the engine asks for an IUnknown pointer
>(SCRIPTINFO_IUNKNOWN), the ITypeLib** pointer is not a valid pointer and
>causes the .Net marshaller to crash.

Sounds like the script engine is passing in NULL for that parameter,
which is allowed according to the docs. Therefore you should declare
the last parameter as an IntPtr passed by value.

void GetItemInfo([MarshalAs(UnmanagedType.LPWStr)] string pstrName,
uint dwReturnMask, [MarshalAs(UnmanagedType.IUnknown)] out object
ppiunkItem, IntPtr ppti);

Quote:>This is basically a hack, by making the 'ppti' a non-out param it is not
>marshalled and I no longer get a crash, however I am unable to pass back
>ITypeInfo if required (currently I don't need to do this).

If you get a nun-NULL pointer passed in at some time, you could handle
it like this

if ( ppti != IntPtr.Zero ) {
  Marshal.WriteIntPtr(ppti,
    Marshal.GetITypeInfoForType(obj.GetType()));

Quote:}

Mattias

===

http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

 
 
 

1. Add-Ins for office using vs7 and c#

I'm running xp prof. OS and Office.
I've rune the add-in wizard that builds an office add-in and setup for the
add-in.
I've inserted a simple "hello world" to be displayed when word finishes
loading all add-ins.
I've compiled and run the setup (wooping 22mb).
I've got a new folder under program files that among other things contains
an xxx.dll and xxx.tlb.
Now what?
How do i register this with word and test that I get my "hello world" when
stating word?

Regards,
Tim

2. CW Technology Handyboard Kit CLEARANCE!!!

3. .NET Add-ins in Excel do not show up in Add-ins

4. Estimating FLOPS

5. How to create two COM servers with the same interface using C# ?

6. Need help deciding on a Magneto Optical

7. Using Interop with the COM IStorage interface, using StgOpenStorage and using IPropertySetStorage.Open

8. Fax after connection

9. Microsoft Money Interface using Visual C#. Help needed.

10. C#.NET GUI interface - using a browser instead of a custom "form"

11. Create a Excel file using Microsoft Interop interface in C#

12. using long parameters in C# COM interface

13. Trouble using an interface in a COM dll with C#