ActiveX - Attaching java object to existing activex interfaced object

ActiveX - Attaching java object to existing activex interfaced object

Post by Tony » Fri, 10 Jan 2003 10:20:11



Hi,

I would like to customize Autocad by calling the Autocad
activex interface from java. I have used the jactivex to
transform acad.tlb to *.java and after compiling I could
successfuly run my first example that opens an autocad
application:

IAcadApplication a = (IAcadApplication) new AcadApplication
();
a = a.getApplication();

The problem is that I would like to controle an already
existing autocad session. The code I just exposed
previously would open a new window each time.

I have found the C++ code that allows to access an already
existing session, but I can't find the equivalent in Java.

    HRESULT hr = NOERROR;
    CLSID clsid;
    LPUNKNOWN pUnk = NULL;
    LPDISPATCH pDisp = NULL;

    hr = ::CLSIDFromProgID(L"AutoCAD.Application", &clsid);

    if (SUCCEEDED(hr)){
     if(::GetActiveObject(clsid, NULL, &pUnk) == S_OK){
      VERIFY(pUnk->QueryInterface(IID_IDispatch, (LPVOID*)
&pDisp) == S_OK);
      m_IApp.AttachDispatch(pDisp);
      pUnk->Release();
     }

Any help on this would be apreciated,

TonyS