pywin32中的2个GetLogicalDrives API是否相同?

时间:2015-01-25 09:08:56

标签: python windows winapi pywin32

我发现pywin32中有两个GetLogicalDrives API,一个在win32api模块中,另一个在win32file中。两者的描述似乎相同。它们之间有什么区别吗?我读了一些代码,似乎大多数人使用win32file.GetLogicalDrives而不是其他代码。谁能告诉我原因?

1 个答案:

答案 0 :(得分:1)

他们基本相同。他们都打电话给kernel32!GetLogicalDrives。 win32api版本稍微简单一些,因为它通过调用PyLong_FromLong(Python 3)直接构建结果,而win32file版本调用Py_BuildValue。它们都只返回整数位掩码,所以没有内在的理由要求优先于另一个。使用哪个更方便。例如,如果您使用的是win32api,请不要导入win32file来调用win32file.GetLogicalDrives

cdb调试会话:

<强> WIN32API

>>> win32api.GetLogicalDrives() 
Breakpoint 0 hit
kernel32!GetLogicalDrives:
00000000`772bae00 4883ec68        sub     rsp,68h
0:000> k5
Child-SP          RetAddr           Call Site
00000000`0030f2d8 00000000`670a2735 kernel32!GetLogicalDrives
00000000`0030f2e0 00000000`5ffaf8bd win32api+0x2735
00000000`0030f310 00000000`6002385b python34!PyCFunction_Call+0x12d
00000000`0030f340 00000000`60025c89 python34!call_function+0x2ab
00000000`0030f3a0 00000000`6002770c python34!PyEval_EvalFrameEx+0x2279
0:000> bl
 0 e 00000000`772bae00     0001 (0001)  0:**** kernel32!GetLogicalDrives
 1 d 00000000`5ffa1450     0001 (0001)  0:**** python34!PyLong_FromLong
0:000> be1; g; bd1; k5
Breakpoint 1 hit
Child-SP          RetAddr           Call Site
00000000`0030f308 00000000`5ffaf8bd python34!PyLong_FromLong
00000000`0030f310 00000000`6002385b python34!PyCFunction_Call+0x12d
00000000`0030f340 00000000`60025c89 python34!call_function+0x2ab
00000000`0030f3a0 00000000`6002770c python34!PyEval_EvalFrameEx+0x2279
00000000`0030f4a0 00000000`60027aae python34!PyEval_EvalCodeEx+0x65c

<强> win32file

>>> win32file.GetLogicalDrives()
Breakpoint 0 hit
kernel32!GetLogicalDrives:
00000000`772bae00 4883ec68        sub     rsp,68h
0:000> k5
Child-SP          RetAddr           Call Site
00000000`0030f2d8 00000000`6704c855 kernel32!GetLogicalDrives
00000000`0030f2e0 00000000`5ffaf8bd win32file+0xc855
00000000`0030f310 00000000`6002385b python34!PyCFunction_Call+0x12d
00000000`0030f340 00000000`60025c89 python34!call_function+0x2ab
00000000`0030f3a0 00000000`6002770c python34!PyEval_EvalFrameEx+0x2279
0:000> be1; g; bd1; k5
Breakpoint 1 hit
Child-SP          RetAddr           Call Site
00000000`0030f298 00000000`60046184 python34!PyLong_FromLong
00000000`0030f2a0 00000000`600461f5 python34!va_build_value+0x64
00000000`0030f2e0 00000000`5ffaf8bd python34!Py_BuildValue+0x25
00000000`0030f310 00000000`6002385b python34!PyCFunction_Call+0x12d
00000000`0030f340 00000000`60025c89 python34!call_function+0x2ab

win32api+0x2735win32file+0xc855表示抱歉。我没有PyWin32的调试符号。我从pypiwin32开始安装了轮子。