Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Calling .NET DLL method from SWT java
Calling .NET DLL method from SWT java [message #727114] Tue, 20 September 2011 08:43 Go to next message
Sharad  is currently offline Sharad
Messages: 1
Registered: September 2011
Junior Member
Hi,

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()
{

@Override
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
Sharad
Re: Calling .NET DLL method from SWT java [message #728620 is a reply to message #727114] Fri, 23 September 2011 10:25 Go to previous message
Grant Gayed is currently offline Grant Gayed
Messages: 2149
Registered: July 2009
Senior Member
Hi,

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.

HTH,
Grant


On 9/20/2011 8:43 AM, Sharad wrote:
> Hi,
> 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()
> {
>
> @Override
> 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
> Sharad
Previous Topic:[closed]
Next Topic:Why isn't key released event sent when two keys are pressed?
Goto Forum:
  


Current Time: Sat Aug 30 00:26:14 EDT 2014

Powered by FUDForum. Page generated in 0.01950 seconds