Groups | Blog | Home
all groups > vj# > february 2004 >

vj# : System.Runtime.InteropServices.MarshalDirectiveException


Sushila
2/13/2004 5:26:14 AM
I am getting System.Runtime.InteropServices.MarshalDirectiveException exception when trying to implement following code in j

private static class RegKin

private int m_regkind
public static int RegKind_Default = 0
public static int RegKind_Register = 1
public static int RegKind_None = 2
RegKind(int n

m_regkind = n

} //RegKin

/** @attribute DllImport("oleaut32.dll", CharSet = CharSet.Unicode, PreserveSig = false
* *
private static native void LoadTypeLibEx(String strTypeLibName, RegKind regKind
/** @attribute MarshalAs(UnmanagedType.Interface
* */Object typeLib[])

public static void main(String[] args

Object typeLib[] = new Object[1]
LoadTypeLibEx("SHDocVw.dll", new RegKind(RegKind.RegKind_None), typeLib)
if ( typeLib[0] == null )
Console.WriteLine("LoadTypeLibEx failed.")
return

TypeLibConverter converter = new TypeLibConverter()
ConversionEventHandler eventHandler = new ConversionEventHandler()
AssemblyBuilder asm = converter.ConvertTypeLibToAssembly(typeLib[0], "ExplorerLib.dll", (TypeLibImporterFlags)0,(ITypeLibImporterNotifySink) eventHandler, null, null, null, null)
asm.Save("ExplorerLib.dll")
} //Mai

Does any one know why this is happenin
Sushila
2/13/2004 8:46:11 PM
Thanks Bob
That just helped me
But Can you tell me wht that is showing such behaviour
Why can't we use Object [] there and use MarshalAs(UnmanagedType.Interface)

Thanks
rlacas NO[at]SPAM online.microsoft.com
2/14/2004 12:29:14 AM
Try using an int[] in place of an Object[] for the out param. Then, you
can wrap the pointer. The following revision worked for me:

import System.Runtime.InteropServices.*;

public class Test
{

public static void main(String[] args)
{
int[] tl = {0};
LoadTypeLibEx("SHDocVw.dll", RegKind.RegKind_None, tl);
UCOMITypeLib iface = (UCOMITypeLib)Marshal.GetObjectForIUnknown(new
System.IntPtr(tl[0]));
System.out.println("info count = "+iface.GetTypeInfoCount());
}

/** @attribute DllImport("oleaut32.dll", CharSet = CharSet.Unicode,
PreserveSig = false)
* */
private static native void LoadTypeLibEx(String strTypeLibName, int
regKind,
int[] typeLib);



private static class RegKind
{
private int m_regkind ;
public static int RegKind_Default = 0;
public static int RegKind_Register = 1;
public static int RegKind_None = 2;
RegKind(int n)
{
m_regkind = n;
}
} //RegKind

}

Does any one know why this is happening
Thanks
[quoted text, click to view]

Bob LaCasse
Microsoft Developer Support - Visual J#.NET

This posting is provided AS IS with no warranties, and confers no rights.
rlacas NO[at]SPAM online.microsoft.com
2/18/2004 8:36:59 PM
Hi - This is a 'too many levels of indirection' problem, because JSharp
doesn't support passing by reference.

In JSharp, an int[] is the only way to do in/out, out or retval params,
unless you are dealing with strings.

With strings, you can pass a BSTR in or get a BSTR returned as a string,
but you have to use StringBuffer to have a parameter value changed or set
by the callee.

This API returns the interface in a pointer to an interface pointer, which
other languages can support by marshalling a by-ref param as a native
interface, which amounts to passing an interface pointer by reference.

But Can you tell me wht that is showing such behaviour?
Why can't we use Object [] there and use MarshalAs(UnmanagedType.Interface)?

Thanks .
Sushila
[quoted text, click to view]

Bob LaCasse
Microsoft Developer Support - Visual J#.NET

This posting is provided AS IS with no warranties, and confers no rights.
AddThis Social Bookmark Button