Why can't pass Marshaled interface as integer(or pointer)

Posted by cemick on Stack Overflow See other posts from Stack Overflow or by cemick
Published on 2010-03-18T11:18:35Z Indexed on 2010/03/18 11:21 UTC
Read the original article Hit count: 306

I passed ref of interface from Visio Add-ins to MyCOMServer (http://stackoverflow.com/questions/2455183/interface-marshalling-in-delphi).I have to pass interface as pointer in internals method of MyCOMServer. I try to pass interface to internal method as pointer of interface, but after back cast when i try call method of interface I get exception. Simple example(Fisrt block execute without error, but At Second block I get Exception after addressed to property of IVApplication interface):

procedure TMyCOMServer.test(const Interface_:IDispatch); stdcall;
var 
  IMy:_IMyInterface;
  V: Variant;
  Str: String;
  I: integer;
  Vis: IVApplication;
begin 

  ......

  Self.QuaryInterface(_IMyInterface,IMy);
  str := IA.ApplicationName;
  V := Integer(IMy);
  i := V;
  Pointer(IMy) :=  Pointer(i);
  str := IMy.SomeProperty; // normal completion


  str := (Interface_ as IVApplication).Path;
  V := Interface_;
  I := V;
  Pointer(Vis) :=  Pointer(i);
  str := Vis.Path;  // 'access violation at 0x76358e29: read of address 0xfeeefeee' 

end;

Why I can't do like this?

© Stack Overflow or respective owner

Related posts about delphi

Related posts about delphi-7