You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VB6读取Access2003含变音字符路径后传递给VLC无法识别的问题

Fixing VLC File Not Found Errors with Accented Paths in VB6 + Access 2003

Let's break down your problem and walk through the fix step by step:

The Root Cause

Even though VB6 stores strings as Unicode internally, the Shell function you're using to launch VLC is an ANSI-only function. When you pass a VB6 String (even if it started as Unicode from Access) to Shell, it gets converted to ANSI behind the scenes—and that's where your accented characters get mangled or stripped entirely. This is why VLC can't locate the files.

The Solution: Bypass VB6 String Conversion + Use Unicode-Aware API

Instead of storing the Access field value in a VB6 String variable first, pass the ADO recordset field directly, and replace the Shell function with its Unicode counterpart ShellExecuteW to preserve the full Unicode path.

Modified Code Snippets

1. Update the GoPlay Subroutine

Modify it to accept an ADODB.Field instead of a String, so we skip the problematic variable conversion:

Private Sub GoPlay(FileToPlayField As ADODB.Field)
    Const vlc_exe = "C:\Program Files\VideoLAN\VLC\vlc.exe "
    ' Build the command line using the field's raw value (no String variable detour)
    Dim fullCommand As String
    fullCommand = vlc_exe & """" & FileToPlayField.Value & """"
    
    Me.Enabled = False ' Block form actions during playback
    StartVLC_common fullCommand
    Me.Enabled = True
    Me.ZOrder
End Sub

2. Replace Shell with ShellExecuteW (Unicode-Compliant)

First, add this API declaration to a standard module (not a form module):

Declare Function ShellExecuteW Lib "shell32.dll" ( _
    ByVal hWnd As Long, _
    ByVal lpOperation As Long, _
    ByVal lpFile As Long, _
    ByVal lpParameters As Long, _
    ByVal lpDirectory As Long, _
    ByVal nShowCmd As Long _
) As Long

Const SW_SHOWNORMAL = 1

Then rewrite StartVLC_common to use this API instead of Shell:

Public Function StartVLC_common(VideoToShow As String)
    On Error Resume Next
    StopVLC_common ' Kill existing VLC instance first
    
    VideoToShow = Trim$(VideoToShow)
    If VideoToShow = "" Then Exit Function
    
    ' Use ShellExecuteW to pass Unicode paths correctly
    Dim result As Long
    ' Pass pointers to Unicode strings with StrPtr()
    result = ShellExecuteW(Me.hWnd, 0, StrPtr("vlc.exe"), StrPtr(VideoToShow), 0, SW_SHOWNORMAL)
    
    ' Check for errors (values <=32 indicate failure)
    If result <= 32 Then
        MsgBox "Could not start VLC process", vbExclamation, "Error"
    End If
End Function

3. How to Call GoPlay

When reading from your ADO recordset, pass the field directly instead of assigning it to a String:

' Example: Inside your recordset loop
GoPlay rs("Directory+Filenames (full path)")

Bonus Tip

Double-check your ADO connection string to ensure it's configured to handle Unicode. For Access 2003, use a connection string like this to make sure you're pulling full Unicode data from the table:

Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\YourDB.mdb;Unicode=True;"
conn.Open

内容的提问来源于stack exchange,提问作者Slobodan Dijakovic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 08:18:14