python报不是有效的 Win32 应用程序

本文最后更新于 2023年9月26日。

`OSError: [WinError 193] %1 不是有效的 Win32 应用程序。

一般报这种错误是由于引用的dll动态链接库和python位数不匹配。例如,python可能是64位但链接库是32位。

如何判断一个dll/exe是32位还是64位?


我把周立功can的链接库zlgcan.dll用记事本打开是PE L所以是32位,和64位的python不匹配。

exescope可以查看到version是1

网传可以使用depends读取dll信息,实际没有成功。

如果按照了visual studio,会有dumpbin程序,将其文件夹加入环境变量,可以使用该工具查看dll中的函数信息。


E:\mydoc\CAN相关\zlgcan_demo\python合集_20221029\python合集_20221029\python带界面demo\demo>dumpbin -exports zlgcan.dll
Microsoft (R) COFF/PE Dumper Version 14.33.31629.0
Copyright (C) Microsoft Corporation.  All rights reserved.
Dump of file zlgcan.dll
File Type: DLL
Section contains the following exports for zlgcan.dll
00000000 characteristics
61E777B4 time date stamp Wed Jan 19 10:30:12 2022
0.00 version
1 ordinal base
39 number of functions
39 number of names
ordinal hint RVA      name
1    0 000098A0 GetIProperty
2    1 000098E0 ReleaseIProperty
3    2 000096A0 ZCAN_ClearBuffer
4    3 00009C50 ZCAN_ClearLINSlaveMsg
5    4 000095E0 ZCAN_CloseDevice
6    5 00009CC0 ZCAN_GetAvailableDevices
7    6 00009600 ZCAN_GetDeviceInf
8    7 00009B90 ZCAN_GetLINReceiveNum
9    8 00009700 ZCAN_GetReceiveNum
10    9 00009CA0 ZCAN_GetReference
11    A 00009860 ZCAN_GetValue
12    B 00009640 ZCAN_InitCAN
13    C 00009B10 ZCAN_InitLIN
14    D 00009620 ZCAN_IsDeviceOnLine
15    E 000095C0 ZCAN_OpenDevice
16    F 000096C0 ZCAN_ReadChannelErrInfo
17   10 000096E0 ZCAN_ReadChannelStatus
18   11 00009740 ZCAN_Receive
19   12 000097E0 ZCAN_ReceiveData
20   13 00009790 ZCAN_ReceiveFD
21   14 00009C00 ZCAN_ReceiveLIN
22   15 00009680 ZCAN_ResetCAN
23   16 00009B50 ZCAN_ResetLIN
24   17 00009D20 ZCAN_SetDeviceChangeCallback
25   18 00009C20 ZCAN_SetLINSlaveMsg
26   19 00009C80 ZCAN_SetReference
27   1A 00009810 ZCAN_SetValue
28   1B 00009660 ZCAN_StartCAN
29   1C 00009B30 ZCAN_StartLIN
30   1D 00009720 ZCAN_Transmit
31   1E 000097C0 ZCAN_TransmitData
32   1F 00009770 ZCAN_TransmitFD
33   20 00009B70 ZCAN_TransmitLIN
34   21 00009980 ZCLOUD_ConnectServer
35   22 00009A30 ZCLOUD_DisconnectServer
36   23 00009A90 ZCLOUD_GetUserData
37   24 000099E0 ZCLOUD_IsConnected
38   25 00009AE0 ZCLOUD_ReceiveGPS
39   26 00009930 ZCLOUD_SetServerInfo
Summary
5000 .data
7000 .rdata
3000 .reloc
1000 .rsrc
2C000 .text