python26.dll没有发现_加载python26.dll时出错(14003)

我有一个用python编写的程序,我用pyinstaller将它转换成一个exe文件。现在我想用VBA代码在不同的PC上运行它。

为了直接从程序中获得输出,我使用了在互联网上找到的这段代码:Private Declare Function CreatePipe Lib "kernel32" (phReadPipe As Long, phWritePipe As

Long, lpPipeAttributes As SECURITY_ATTRIBUTES, ByVal nSize As Long) As Long

Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long

Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long

Private Declare Sub GetStartupInfo Lib "kernel32" Alias "GetStartupInfoA" (lpStartupInfo As STARTUPINFO)

Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long

Public Function Redirect(szBinaryPath As String, szCommandLn As String) As String

Dim tSA_CreatePipe As SECURITY_ATTRIBUTES

Dim tSA_CreateProcessPrc As SECURITY_ATTRIBUTES

Dim tSA_CreateProcessThrd As SECURITY_ATTRIBUTES

Dim tSA_CreateProcessPrcInfo As PROCESS_INFORMATION

Dim tStartupInfo As STARTUPINFO

Dim hRead As Long

Dim hWrite As Long

Dim bRead As Long

Dim abytBuff() As Byte

Dim lngResult As Long

Dim szFullCommand As String

Dim lngExitCode As Long

Dim lngSizeOf As Long

tSA_CreatePipe.nLength = Len(tSA_CreatePipe)

tSA_CreatePipe.lpSecurityDescriptor = 0&

tSA_CreatePipe.bInheritHandle = True

tSA_CreateProcessPrc.nLength = Len(tSA_CreateProcessPrc)

tSA_CreateProcessThrd.nLength = Len(tSA_CreateProcessThrd)

If (CreatePipe(hRead, hWrite, tSA_CreatePipe, 0&) <> 0&) Then

tStartupInfo.cb = Len(tStartupInfo)

GetStartupInfo tStartupInfo

With tStartupInfo

.hStdOutput = hWrite

.hStdError = hWrite

.dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES

.wShowWindow = SW_HIDE

End With

szFullCommand = """" & szBinaryPath & """" & " " & szCommandLn

Debug.Print szFullCommand

lngResult = CreateProcess(0&, szFullCommand, tSA_CreateProcessPrc, tSA_CreateProcessThrd, True, 0&, 0&, vbNullString, tStartupInfo, tSA_CreateProcessPrcInfo)

If (lngResult <> 0&) Then

lngResult = WaitForSingleObject(tSA_CreateProcessPrcInfo.hProcess, WAIT_INFINITE)

lngSizeOf = GetFileSize(hRead, 0&)

If (lngSizeOf > 0) Then

ReDim abytBuff(lngSizeOf - 1)

If ReadFile(hRead, abytBuff(0), UBound(abytBuff) + 1, bRead, ByVal 0&) Then

Redirect = StrConv(abytBuff, vbUnicode)

End If

End If

Call GetExitCodeProcess(tSA_CreateProcessPrcInfo.hProcess, lngExitCode)

CloseHandle tSA_CreateProcessPrcInfo.hThread

CloseHandle tSA_CreateProcessPrcInfo.hProcess

'If (lngExitCode <> 0&) Then Err.Raise vbObject + 1235&, "GetExitCodeProcess", "Non-zero Application exit code " & lngExitCode

CloseHandle hWrite

CloseHandle hRead

Else

Err.Raise vbObject + 1236&, "CreateProcess", "CreateProcess Failed, Code: " & Err.LastDllError

End If

End If

End Function

但每当我打电话给它

^{pr2}$

我得到了一个错误:Error loading Python DLL: [program path]\python26.dll (error code 14003)

当我直接从windows命令调用这个程序时,它运行得很好。我还检查了程序.exe.manifest一切都在那里。

很抱歉这段代码太长了,但我想把它包括进来会很好。在

谢谢你的帮助。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值