OLE Control failed to run when compiled as 64-bit application

Symptom

When the application includes some OLE control, it works fine when it runs in the IDE or when compiled as a 32-bit application. But the OLE control fails to run when the application is compiled as 64-bit.

Environment

PowerBuilder 2017 or later

Cause

It is caused due to that a 32-bit OLE object/control is used in a 64-bit application.

In PowerBuilder IDE, when you insert an OLE to a window/user object, it is a 32-bit OLE object/control. When you compile it as a 64-bit application, it cannot call the 32-bit OLE object/control.

Solution

Firstly, you need to use 64-bit registering tool to register the OLE object/control:

If you are using regsvr32.exe, you can use these commands:

C:\Windows\System32\regsvr32.exe  //64bit
C:\Windows\SysWOW64\regsvr32.exe  //32bit

If you are using RegAsm.exe, you can use these commands:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe    //32bit
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe  //64bit

Secondly, add a blank OLE control (without any class name) on a window in PowerBuilder IDE. Then use this.insertclass(‘…’) to dynamically load the target OLE object in its code. Of course, you can also use InsertObject() function to load it at runtime, which will pop a dialog box for the user to choose the OLE object.