0

I want to send Interface Ref of IVApplication from Visio Add-in to my other one COM server. But I have Ole exception. Now i do that:

Code in Visio Add-in:

var 
  IStrm: IStream;
  hres: HResult;
  rhglobal: HGLOBAL;
  VisioAppl: IVApplication; 
begin

   hres := CreateStreamOnHGlobal(0, TRUE, IStrm);
      if Succeeded(hres) then
        hres := CoMarshalInterface(IStrm, IID_IVApplication, VisioAppl,
                            MSHCTX_LOCAL, 0,
                            MSHLFLAGS_NORMAL);
      if (Succeeded(hres)) then
      begin
          hres := GetHGlobalFromStream(IStrm, rhglobal);
          if Succeeded(hres)  then
             Result := rhglobal;
          IStrm := nil;
      end;
 end;

After this I create instance of my COM server and pass rhglobal to him.

Code of my COM server:

procedure (AHGlobal: HGlobal);
var
  VisioAppl: Visio_TLB.IVApplication;
  iStrm: IStream;
  hres: HResult;
begin

      iStrm := Nil;
      VisioAppl:= nil;
      hres := CreateStreamOnHGlobal(AHGlobal, FALSE, iStrm);
      if (SUCCEEDED(hres)) then
      begin

        hres := CoUnmarshalInterface(iStrm, Visio_TLB.IVApplication, VisioAppl);
        iStrm := nil;
        ShowMessage('Result:' + BoolToStr(SUCCEEDED(hres)));  <-- result 0 
        ShowMessage(VisioAppl.ProductName); <----  Error
      end;

end;
Semyon.Khmelev
  • 197
  • 1
  • 14
  • Welcome to Stack Overflow. What "result is 0" are you asking about? If you're talking about "hres", it's assigned to 5 times in your two code samples. Which one are you asking about? If you actually ask a question, you stand a much better chance of getting it answered. – Ken White Mar 16 '10 at 16:55
  • I thought it's eviden. Place in the code at undesirable result have marked by comment "<-- result 0". – Semyon.Khmelev Mar 16 '10 at 18:03
  • How about actually working out what hres is set to in this case and push it through something to work out the error code, just sometimes they actually tell you how you have messed up :) My personal guess is probably your specific visio interface doesn't have a proxy. – tyranid Mar 16 '10 at 21:38

1 Answers1

0

Why don't you just define a method in your COM server and make a VARIANT parameter? (or IDispatch* or IUknown*).

Then you can just pass the VisioApplication to your COM server and at the serverside cast it back to the Visio_TLB.IVApplication interface.

So it will look like this:

Addin:

procedure SendAppToComServer(aIntf: Visio_TLB.IVApplication);
begin
  MyComServer.PassVisioApp(aIntf);
end;

Comserver:

procedure TMyComServer.PassVisioApp(VisioApp: OleVariant);
var
  VisioAppIntf: Visio_TLB.IVApplication;
begin
  VisioAppIntf := VisioApp;
  ShowMessage(VisioAppIntf.ProductName);
end;
The_Fox
  • 6,992
  • 2
  • 43
  • 69
  • That doesn't matter with COM. I automated OpenOffice.org and I can pass interfaces to listeners without a problem to the out-of-process COM-server of OpenOffice.org. Ofcourse there will be a problem when Visio and your addin closes and your COM-server wants to access the Visio app, but that is something you have to take care of. – The_Fox Mar 17 '10 at 07:47
  • Oh, thanks! it's really works! when i passed param as IDispatch instead of OleVariant. But I can't undestand why it work. – Semyon.Khmelev Mar 17 '10 at 08:46