We use ctypes.WinDLL to load all shared libraries in Windows but that's wrong. We should be using ctypes.CDLL even on Windows for some libraries.
We have been using WinDLL under the incorrect assumption that's what one needs to do in Windows. However, the choice is not about the underlying OS, it's about the calling convention used by the functions. We should be using WinDLL to access functions that use the stdcall calling convention and CDLL to access functions that use the standard C calling convention (called cdecl on Windows).
If I understood this correctly, we need to check the header files and see if in Windows the functions are defined with __stdcall (may happen indirectly such as when the WINAPI macro is used). If not, then we should be using CDLL even on windows. It seems that using the wrong one will not immediately lead to issues but may lead to weird unpredictably issues later.
I've checked the header files and seems we need to change for Alpao and BMC mirrors, for Hamamatsu cameras, and for Linkam stages:
| device (module) |
checked header |
needs fix |
alpao mirrors (microscope/_wrappers/asdk.py) |
yes |
probably |
BMC mirrors (microscope/_wrappers/BMC.py) |
yes |
probably |
hamamatsu cameras (microscope/_wrappers/dcamapi4.py) |
yes |
probably |
mirao mirrors (microscope/_wrappers/mirao52e.py) |
yes |
no (MIRAOCALL expands to __stdcall) |
pvcam cameras (microscope/cameras/pvcam.py) |
yes |
no (PV_DECL expands to __stdcall on Windows) |
andor SOLIS (microscope/cameras/atmcd.py) |
yes |
maybe (uses WINAPI on one version but nothing on other) |
andor SDK3 cameras (microscope/cameras/_SDK3.py) |
yes |
no (AT_EXP_CONV expands to WINAPI) |
linkam stage (microscope/stages/linkam.py) |
yes |
probably |
However, I no longer have access to any of these. Could someone who does have access test it?
We use
ctypes.WinDLLto load all shared libraries in Windows but that's wrong. We should be usingctypes.CDLLeven on Windows for some libraries.We have been using
WinDLLunder the incorrect assumption that's what one needs to do in Windows. However, the choice is not about the underlying OS, it's about the calling convention used by the functions. We should be usingWinDLLto access functions that use thestdcallcalling convention andCDLLto access functions that use the standard C calling convention (calledcdeclon Windows).If I understood this correctly, we need to check the header files and see if in Windows the functions are defined with
__stdcall(may happen indirectly such as when theWINAPImacro is used). If not, then we should be usingCDLLeven on windows. It seems that using the wrong one will not immediately lead to issues but may lead to weird unpredictably issues later.I've checked the header files and seems we need to change for Alpao and BMC mirrors, for Hamamatsu cameras, and for Linkam stages:
microscope/_wrappers/asdk.py)microscope/_wrappers/BMC.py)microscope/_wrappers/dcamapi4.py)microscope/_wrappers/mirao52e.py)MIRAOCALLexpands to__stdcall)microscope/cameras/pvcam.py)PV_DECLexpands to__stdcallon Windows)microscope/cameras/atmcd.py)WINAPIon one version but nothing on other)microscope/cameras/_SDK3.py)AT_EXP_CONVexpands toWINAPI)microscope/stages/linkam.py)However, I no longer have access to any of these. Could someone who does have access test it?