0

Python で dll をロードしようとしていますが、絶対パスを入力した場合にのみロードできます。相対パスまたは環境変数を使用したいと思います。動作する唯一のことは、正確なパス (C:...) を指定した場合です。dll を py ファイルと同じフォルダーに直接ビルドしようとしましたが、それでも動作しませんでした。
私が持っているもの:

MY_DLL = r'c:\full_path\output\Win32\Debug\my.dll'
#MY_DLL = r'my.dll'   #this doesn't work but it is what I want
#MY_DLL = r'$(env_var)\dir\output\$(Platform)\$(Configuration)\my.dll'   #this doesn't work either but would be good too     

ヘルプ ?

4

1 に答える 1

1

Windows の cdll について、または一般的な ctypes についてはあまり知りませんが、os.path を使用してパスを非常に簡単に操作できます。

import os.path
p1="path.dll"
print (os.path.abspath(p1))
p2="${env_var}/path.dll"  #Make sure you set env_var in the calling environment...Otherwise it won't be expanded...
print (os.path.expandvars(p2))
于 2012-04-13T20:28:28.413 に答える