PDA

View Full Version : Converting 32-bit to 64-bit VBA code



Rafael Cella
10-10-2023, 07:04 PM
Dear,

I have a VBA program in Excel that communicates to a PLC. The original VBA code runs on Windows 32 bits.

We changed the PC to a 64-bit, and the code no longer runs. I included the most basic one, which is the inclusion of PtrSafe after Declare, but even so it gives an error, saying it can't find the dll (which is properly placed in the correct folder).

Could anyone tell me what I can do to fix it?

The only change I made from the 32-bit code to the 64-bit code was the inclusion of PtrSafe.


Declare PtrSafe Function OpenModbusSerial Lib "C:\DMT 2.0\Include\DMT.dll" (ByVal conn_num As Long, ByVal baud_rate As Long, _
ByVal data_len As Long, ByVal parity As Byte, ByVal stop_bits As Long, ByVal modbus_mode As Long) As Long
Declare PtrSafe Sub CloseSerial Lib "C:\DMT 2.0\Include\DMT.dll" (ByVal conn_num As Long)
Declare PtrSafe Function OpenModbusTCPSocket Lib "C:\DMT 2.0\Include\DMT.dll" (ByVal conn_num As Long, ByVal ipaddr As Long) As Long
Declare PtrSafe Sub CloseSocket Lib "C:\DMT 2.0\Include\DMT.dll" (ByVal conn_num As Long)
Declare PtrSafe Function RequestData Lib "C:\DMT 2.0\Include\DMT.dll" (ByVal comm_type As Long, ByVal conn_num As Long, ByVal slave_addr As Long, _
ByVal func_code As Long, ByRef buf As Byte, ByVal DataLen As Long) As Long
Declare PtrSafe Function ResponseData Lib "C:\DMT 2.0\Include\DMT.dll" (ByVal comm_type As Long, ByVal conn_num As Long, ByRef slave_addr As Long, _
ByRef func_code As Long, ByRef buf As Byte) As Long
Declare PtrSafe Function ReadSelect Lib "C:\DMT 2.0\Include\DMT.dll" (ByVal conn_num As Long, ByVal time_msec As Long) As Long
Declare PtrSafe Function GetLastSerialErr Lib "C:\DMT 2.0\Include\DMT.dll" () As Long
Declare PtrSafe Sub ResetSerialErr Lib "C:\DMT 2.0\Include\DMT.dll" ()
Declare PtrSafe Function GetLastSocketErr Lib "C:\DMT 2.0\Include\DMT.dll" () As Long
Declare PtrSafe Sub ResetSocketErr Lib "C:\DMT 2.0\Include\DMT.dll" ()

​​​​​​​Thank you

jolivanes
10-10-2023, 09:45 PM
See here: https://www.excelforum.com/excel-programming-vba-macros/1413345-converting-32-bit-to-64-bit-vba-code.html

Aflatoon
10-10-2023, 11:50 PM
Is the dll 64bit? If not, it won't work.

arnelgp
10-11-2023, 12:29 AM
you mayt try to run regsvr32.exe (from SysWow64 folder) and register your dll..