Code Monkey home page Code Monkey logo

Comments (5)

mpoindexter avatar mpoindexter commented on July 20, 2024

I think this should be as simple as creating an IDispatch annotated interface (see http://com4j.java.net/annotations.html), and invoking the method on it. Since IDispatch is just a COM interface like any other I don't think COM4J itself needs to have any special support for this.

from com4j.

schneidh avatar schneidh commented on July 20, 2024

I started down that path:

@IID(IID.IDispatch)
public interface IDispatch extends Com4jObject
{
  @VTID(3)
  int getTypeInfoCount();

  @VTID(5)
  int getIDsOfName(Object riid, String[] names, int count, @LCID int lcid);
}

The getTypeInfoCount method works, but the getIDsOfName method does not. Is there a tlb, ocx or dll that I can generate this from? I searched google and my Windows system32 directory, but couldn't find anything. Otherwise some hints on what these methods need to look like would be appreciated.

from com4j.

mpoindexter avatar mpoindexter commented on July 20, 2024

I think you are on the right track, but your signature for getIDsOfName is wrong. If you read MSDN for that method, it expects a pointer to a caller allocated buffer that it will fill...so you need something like:

@VTID(5)
@returnvalue(type=NativeType.HRESULT)
int getIDsOfNames(Object riid, String[] names, int count, @LCid int lcid, ByteBuffer buffer);

Then when you call it you would pass a byte buffer of the correct size (names.length * 4) allocated with ByteBuffer.allocateDirect.

I think IDispatch may be defined in the stdole32.tlb, but I'm not sure.

While I was looking at the MSDN I also saw this note which seems like it applies to what you are trying to do:
Caution You cannot use this method to access values that have been added dynamically, such as values added through JavaScript. Instead, use the GetDispID of the IDispatchEx interface. For more information, see the IDispatchEx interface.

from com4j.

schneidh avatar schneidh commented on July 20, 2024

Ah, you are correct, IDispatchEx is a better choice. I am able to create a working com4j interface for IDispatchEx. Thanks for the help!

from com4j.

vcschapp avatar vcschapp commented on July 20, 2024

Hi @scheidh -- Would you mind sharing your annotated code for IDispatchEx? I'm trying to get make an annotated interface for vanilla IDispatch but I don't know what to do for the Invoke() method.

from com4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.