[AccessD] OT VB 6 Quirk (Posted to VB List several days ago, with no response)

Drew Wutka DWUTKA at Marlow.com
Mon Jan 18 15:59:07 CST 2010


Ok, I'm sure not many of you are using VB 6 anymore.  I really don't
develop much anymore myself.  However, I have a user that is running
into a quirk with Adobe.  It's a form pdf, that creates an XFDF
extension.  Inside this 'data file' (that she receives in email), it's
got a tag that shows a full URL of what the user used to view the pdf
form.  This is an http://.... URL.  On her full version of Acrobat, it
has a problem dealing with the URLs, it just keeps prompting if you want
to allow access to http://...

Now, if you go into that .xfdf data file, and just change that href
property to the actual network path (\\server\share\...), then it opens
just fine.  It seems that Acrobat Reader is adding the URL on the end
users end, so it's not something we can fix in the pdf form. (At least
we can't find a property to do so).  Since it's a pretty simple fix to
change the URL to the UNC path, I figured I'd whip up a little VB
program to do that.

Did that, piece of cake.  Wanted to make it an 'invisible process', by
having the program just monitor a folder where she could save these
emailed .xfdf data files too.  When a new file is added to the monitored
folder, it does it's job, and saves the new file as
'converted_.....xfdf'.  Program works like a charm..IN DEBUG mode.
Compile it, and run it, and the CreateFile API which gets the handle to
start the monitoring process kicks back a DLLError 998.  Now, why would
code work perfectly in debug mode, but not work in a compiled state.
Here is my file monitoring class:  The line 'If hDir=-1' is getting
skipped in debug mode (because it's getting a valid handle), and in a
compiled state, it dumps out the LastDllError as 998 (actually, it was
doing 998, until I added the strPathToMonitor variable,a nd now it's
doing 1305.

I'm stumped.  Anyone have any ideas?

Option Explicit
Event FileActivity(strFileName As String, Action As FS_File_Actions)
Public PathToMonitor As String Dim blKeepMonitoring As Boolean Private
Declare Function FS_CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal
lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode
As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As
Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long)
As Long Private Declare Function FS_ReadDirChanges Lib "kernel32" Alias
"ReadDirectoryChangesW" (ByVal hDir As Long, ByVal lpBuffer As Long,
ByVal lenBuffer As Long, ByVal bWatchSubtree As Boolean, ByVal
dwNotifyFilter As Long, ByRef dwBytesReturned As Long, ByVal
lpOverLapped As Long, ByVal dwCallBack As Long) As Long Private Declare
Function FS_CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal
hObject As Long) As Long Private Declare Function FS_CreateEvent Lib
"kernel32" Alias "CreateEventA" (lpEventAttributes As Any, ByVal
bManualReset As Long, ByVal bInitialState As Long, ByVal lpName As
String) As Long Private Declare Function FS_ResetEvent Lib "kernel32"
Alias "ResetEvent"
(ByVal hEvent As Long) As Long
Private Declare Sub FS_CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
(ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
Private Declare Function FS_WaitForSingleObject Lib "kernel32" Alias
"WaitForSingleObject" (ByVal hHandle As Long, ByVal dwMilliseconds As
Long) As Long
Private Const FILE_LIST_DIRECTORY = (&H1) Private Const
FILE_SHARE_DELETE = &H4 Private Const FILE_SHARE_READ = &H1 Private
Const FILE_SHARE_WRITE = &H2 Private Const OPEN_EXISTING = 3 Private
Const FILE_FLAG_BACKUP_SEMANTICS = &H2000000 Private Const
FILE_FLAG_OVERLAPPED = &H40000000 Private Const
FILE_NOTIFY_CHANGE_ATTRIBUTES = &H4 Private Const
FILE_NOTIFY_CHANGE_CREATION = &H40 Private Const
FILE_NOTIFY_CHANGE_DIR_NAME = &H2 Private Const
FILE_NOTIFY_CHANGE_FILE_NAME = &H1 Private Const
FILE_NOTIFY_CHANGE_LAST_ACCESS = &H20 Private Const
FILE_NOTIFY_CHANGE_LAST_WRITE = &H10 Private Const
FILE_NOTIFY_CHANGE_SECURITY = &H100 Private Const
FILE_NOTIFY_CHANGE_SIZE = &H8 Private Const WAIT_TIMEOUT = 258& Public
Enum FS_File_Actions
    FILE_ACTION_ADDED = &H1
    FILE_ACTION_MODIFIED = &H3
    FILE_ACTION_REMOVED = &H2
    FILE_ACTION_RENAMED_NEW_NAME = &H5
    FILE_ACTION_RENAMED_OLD_NAME = &H4
End Enum
Private Type FS_FILE_NOTIFY_INFORMATION
    NextEntryOffset As Long
    Action As FS_File_Actions
    FileNameLength As Long
    FileName(1024 - 1) As Byte
End Type
Private Type FS_OVERLAPPED
    Internal As Long
    InternalHigh As Long
    Offset As Long
    OffsetHigh As Long
    hEvent As Long
End Type
Public Function StartMonitoring()
'On Error GoTo ErrorHandler
Dim hDir As Long
Dim dwReturn As Long
Dim intReturnSize As Long
Dim ovr As FS_OVERLAPPED
Dim hEvent As Long
Dim intWatchFilter As Long
Dim fni As FS_FILE_NOTIFY_INFORMATION
Dim fniBuf(0 To 1024 * 5 - 1) As Byte
Dim BufferPos As Long
Dim strFileName As String
Dim strPathToMonitor As String
strPathToMonitor = PathToMonitor
blKeepMonitoring = True
intWatchFilter = FILE_NOTIFY_CHANGE_ATTRIBUTES +
FILE_NOTIFY_CHANGE_CREATION + FILE_NOTIFY_CHANGE_DIR_NAME +
FILE_NOTIFY_CHANGE_FILE_NAME + FILE_NOTIFY_CHANGE_LAST_ACCESS +
FILE_NOTIFY_CHANGE_LAST_WRITE + FILE_NOTIFY_CHANGE_SECURITY +
FILE_NOTIFY_CHANGE_SIZE hDir = FS_CreateFile(strPathToMonitor,
FILE_LIST_DIRECTORY, FILE_SHARE_READ Or FILE_SHARE_DELETE Or
FILE_SHARE_WRITE, Null, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS Or
FILE_FLAG_OVERLAPPED, 0) If hDir = -1 Then
    MsgBox "Invalid Handle Value...Error: " & Err.LastDllError End If
hEvent = FS_CreateEvent(0&, True, True, "FS_IOEvent") ovr.hEvent =
hEvent dwReturn = FS_ReadDirChanges(hDir, VarPtr(fniBuf(0)),
UBound(fniBuf) + 1, True, intWatchFilter, intReturnSize, VarPtr(ovr),
0&) If dwReturn = 0 Then
    MsgBox "Error Calling ReadDirChanges"
    MsgBox Err.LastDllError
    MsgBox ovr.hEvent
    MsgBox hDir
End If
Do Until blKeepMonitoring = False
    BufferPos = 0
    dwReturn = FS_WaitForSingleObject(hEvent, 100)
    If dwReturn <> WAIT_TIMEOUT Then
        'MsgBox fniBuf(0)
        FS_CopyMemory VarPtr(fni), VarPtr(fniBuf(BufferPos)), Len(fni)
        strFileName = fni.FileName
        strFileName = Left(strFileName, fni.FileNameLength / 2)
        RaiseEvent FileActivity(strFileName, fni.Action)
        While fni.NextEntryOffset <> 0
            BufferPos = BufferPos + fni.NextEntryOffset
            FS_CopyMemory VarPtr(fni), VarPtr(fniBuf(BufferPos)),
Len(fni)
            strFileName = fni.FileName
            strFileName = Left(strFileName, fni.FileNameLength / 2)
            RaiseEvent FileActivity(strFileName, fni.Action)
        Wend
        FS_ResetEvent hEvent
        dwReturn = FS_ReadDirChanges(hDir, VarPtr(fniBuf(0)),
UBound(fniBuf) + 1, True, intWatchFilter, intReturnSize, VarPtr(ovr),
0&)
    End If
    DoEvents
Loop

ErrorHandler:

FS_CloseHandle hEvent
FS_CloseHandle hDir
End Function
Public Function StopMonitoring()
blKeepMonitoring = False
End Function
Private Sub Class_Initialize()
blKeepMonitoring = False
End Sub

The information contained in this transmission is intended only for the person or entity 
to which it is addressed and may contain II-VI Proprietary and/or II-VI Business 
Sensitive material. If you are not the intended recipient, please contact the sender 
immediately and destroy the material in its entirety, whether electronic or hard copy. 
You are notified that any review, retransmission, copying, disclosure, dissemination, 
or other use of, or taking of any action in reliance upon this information by persons 
or entities other than the intended recipient is prohibited.





More information about the AccessD mailing list