|Re: Calling .NET DLL method from SWT java [message #728620 is a reply to message #727114]
||Fri, 23 September 2011 14:25
| Grant Gayed
Registered: July 2009
Is the thing you've written in .NET an actual OLE control, or just some
functionality living in your .dll that should be accessible via COM?
Assuming the latter, I think you would just use a straight COM call like
CoCreateInstance() to get started, which is defined in swt's COM class.
Note that swt's COM class is not considered API, it's there to support
swt components that use COM behind the scenes. Therefore the
methods/constants in there could change in future versions, though it's
not likely that something as core as CoCreateInstance() would disappear.
Once you have an instance of your COM object created then you can invoke
methods on it by making vtbl calls (for examples of this see any of the
I* classes in swt's org.eclipse.swt.internal.ole.win32 package). If you
find that COM.java is missing any COM functions or vtbl invocations that
you absolutely need then you may find it easier to just write a C
function that you call out to via JNI to make the COM calls, since this
case would not be constrained to the set of natives that is defined in
swt's COM class.
On 9/20/2011 8:43 AM, Sharad wrote:
> I have written a .NET dll (here for example DemoCOM_SWT) exposed as COM
> component and registered it as a Type Library (using REGASM from visual
> studio command prompt). I wanted to access few methods from one of
> public class in above .NET dll. For this, i have also generated SWT
> wrapper over type library using SWT based utility. Now, i wanted to
> execute methods.
> Below is sample code i have written but it's throwing an exception as
> "failed to create ole client. result = -2147467262". Can you please
> suggest what might be wrong here?
> Display.getDefault().syncExec( new Runnable()
> public void run()
> Shell parent = PlatformHelper.getCurrentShell();
> OleFrame frame = new OleFrame( parent, SWT.NONE );
> OS.OleInitialize( 0 );
> OleClientSite clsite = new OleClientSite( frame, SWT.BORDER,
> "DemoCOM_SWT.DemoClass" );
> OleAutomation oleAutomation = new OleAutomation( clsite );
> _DemoClass odm = new _DemoClass( oleAutomation );
> } );
> Am i doing right way or is their in other way to access
> functions/methods of .NET dll.
> Any help will be appreciated?
> Thanks and Regards
Powered by FUDForum
. Page generated in 0.01516 seconds