The error reported below only occurs on a Windows 11 x86_64 system.
The code has has been tested on the following systems:
Windows 7 x86 and x86-64
Windows 10 x86 and x86-64
Windows 11 x86-64
MSWord version 2007 (I know it's old, but....)
and 32-bit Lazarus versions 2.0.12, 2.2.6, 3.6 with default versions of FPC.
The following code fragment compiles on all systems without error in both release and debug modes.
The runtime error 219 - Invalid Typecast - only occurs at runtime on Windows 11 x86_64.
I'm reasonable sure that this is the case on Windows 11 21H2, 23H2 and definitely 24H2.
Function OleRunningApp( strOLEObject :String) :IUnknown;
Var
ClassID :TGUID;
Begin
Result := Nil;
CLSIDFromProgID(PWideChar(WideString(strOLEObject)), ClassID);
GetActiveObject( ClassID, Nil, Result); //<< Runtime Error 219 - Invalid Typecast
end;
strOLEObject has the value 'Word.Application'.
GetActiveObject is defined in ActiveX.pp as:
function GetActiveObject(const clsid: TCLSID; pvReserved: Pointer; out unk: IUnknown) : HResult; stdcall; external oleaut32dll name 'GetActiveObject';
I understand that MS is depreciating and / or removing some ActiveX functionality, but I don't know the details.
My questions are:
1. Has anyone else encountered this issue?
2. Does onyone know how to fix / work around this issue?
Regard,
John