Thursday, December 31, 2015

Generating OPC Automation IDL, TLB and header files from OPCDAAuto.dll

OPC Automation IDL, TLB and header files are not easy to find. You can obtain this files from OPC Foundation if you are a member or maybe from OPC application vendor.

The IDL file can be reverse engineered using OLE-Com Object Viewer. Once the IDL is generated TLB and other files can be generated from it as well. Below is a general direction how to do this.

Steps to reverse generate IDL, TLB and header files for OPCDAAuto.dll:

  1. Download Windows 7 SDK. I am using GRMSDKX_EN_DVD.iso as the OS is Windows 7 64-bit.
  2. Install the SDK.
  3. Open CMD Shell (Start | All Programs | Microsoft Windows SDK v7.0 | CMD Shell)
  4. Change directory to bin folder.
  5. Run oleview.exe, this will open a 32-bit version of the application. Note that this is important as the OPCDAAuto.dll I have is 32-bit as well.
  6. Navigate to Type Libraries | OPC Automation 2.0 (Ver 1.0)
  7. Double click to view Type Library definition.
  8. Do File | Save As... to D:\OPCDaAuto\OPCDaAuto.IDL.
  9. Go back to the cmd.exe as per step 3. Change directory to D:\OPCDaAuto.
  10. Fix OPCDaAuto.IDL
    1. Compile the IDL file, like, midl /win32 OPCDaAuto.IDL /header OPCDaAuto.h 
    2. This will fail about OPCGroups type specification.
    3. Fix this by moving OPCGroups definition in line 188-195 to line 104, this is above OPC Server Object. Save the file, this will change the numbering.
    4. Compile again as per sub-step 1 above.
    5. This will fail again about single type specification. Change single to float for the lines as per the output of the compilation.
    6. Compile again. This time it will complain about OPCGroup type specification.
    7. Fix this by moving OPCGroup around line 255-262 to around line 196. This above definition of Collection of OPC Group Objects.
    8. Compile again. This will fail again for another single data type. Convert it to float in 2 more places. Line location should be indicated in the compilation output.
    9. Compile again. This time it should be successful.
Note that I haven't used the corresponding TLB and header files, yet. I am hoping it will work.

Saturday, December 12, 2015

Check Windows input message queue idle in Python

Code below shows how to check for message queue input idle. Note that WaitForInputIdle waits only once per process on any thread. So if one of the thread returns idle then it will return right away. 

Tested on:
Windows 10 TH2 (build 1511)
Python 3.5.1 64-bit

Also need to install pywin32, like:
c:\> pip install pypiwin32
This should be run on elevated prompt.

Saturday, December 05, 2015

How to resolve external hosts when using pfSense as firewall/router

pfSense 2.2.5 does not automatically resolve external hosts (but not hosts from the internet) using DNS servers provided by DHCP from the WAN interface. To force it resolve, do:

Navigate via Web UI:

  • Services | DNS Resolver
  • Scroll down to Domain Overrides
  • Add entry
    • Domain: [a domain suffix, e.g., test.org]
    • IP address: [DNS server IP]


What are the side effects without the above changes?

  • pfSense clients not able to access internet, especially when internet is controlled via a proxy.
  • Windows clients unable to access Windows share even using FQDN


Windows 10 Mail app "Something went wrong We're sorry, but we weren't able to do that."

Upgraded from Windows 8 to Windows 10, Mail app stopped working with the following message

Something went wrong
We're sorry, but we weren't able to do that.
Error code: 0x8007000d.


Workaround is to re-install the app, see http://8thstring.blogspot.com/2015/12/how-to-remove-windows-10-mail-and.html to remove it. Once removed you can go to Windows Store to install Mail again.

How to remove Windows 10 Mail and Calendar app

c:\> Get-AppxPackage | Where-Object {$_.Name -like "*microsoft.windowscommunications*"} | Remove-AppxPackage

Note that you have to run PowerShell in elevated mode.