You can simply check if the required environment variable is set:
dim PPath as string PPath = trim(Environ("PYTHONPATH")) if (PPath<>"") <call dll> else msgbox ("Error!") end if
Or you can run the DLL in the nother test process: if this call works, you know that it is normal to call the DLL - it depends on the DLL call of your use, so I'm not sure about that:
Private Declare Function CloseHandle Lib "kernel32" (ByVal _ hObject As Long) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal _ dwDesiredAccess As Long, ByVal bInheritHandle As _ Long, ByVal dwProcessId As Long) As Long Private Declare Function GetExitCodeProcess Lib "kernel32" _ (ByVal hProcess As Long, lpExitCode As Long) As Long Const STILL_ACTIVE = &H103 Const PROCESS_ALL_ACCESS = &H1F0FFF ... dim IsActive as boolean dim Handle as long Dim TaskID As Long TaskID = Shell("rundll32.exe pyton.dll Py_Initialise()", vbNormalNoFocus) <wait for some time> '- check if pyton.dll is still running Handle = OpenProcess(PROCESS_ALL_ACCESS, False, TaskID) Call GetExitCodeProcess(Handle, ExitCode) Call CloseHandle(Handle) IsActive = IIf(ExitCode = STILL_ACTIVE, True, False) if (not IsActive) then msgbox ("Error!") else <kill process> <call dll normally> end if
Regards, Thomas
source share