DeviceIoControl and reparse points.



Hi,

I'm attempting to create a reparse point (directory junction) from VB.
After having read the MSDN on this subject, I tried it out. This is
what I have so far:

----------
Private Type TMN_REPARSE_DATA_BUFFER
ReparseTag As Long
ReparseDataLength As Integer
Reserved As Integer

' IO_REPARSE_TAG_MOUNT_POINT specifics follow
SubstituteNameOffset As Integer
SubstituteNameLength As Integer
PrintNameOffset As Integer
PrintNameLength As Integer
PathBuffer() As Integer
End Type

Private Const TMN_REPARSE_DATA_BUFFER_HEADER_SIZE = 8

Public Function MakeJunction(strJunctionDir As String, strDestDir As
String)
Dim lngDirHandle As Long
Dim rdbBuffer As TMN_REPARSE_DATA_BUFFER
Dim nDestMountPointBytes As Integer
Dim lngRet As Long, lngBytes As Long
Dim ovrLapped As OVERLAPPED
Dim strDestinationDir As String

lngDirHandle = CreateFile("\\?\" & strJunctionDir & Chr(0),
GENERIC_READ Or GENERIC_WRITE, 0, ByVal 0&, _
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS
Or FILE_FLAG_OPEN_REPARSE_POINT, 0)

If lngDirHandle = INVALID_HANDLE_VALUE Then
PrintError
Exit Function
End If

strDestinationDir = "\??\" & strDestDir & Chr(0)

nDestMountPointBytes = (Len(strDestinationDir) - 1) * 2
rdbBuffer.ReparseTag = IO_REPARSE_TAG_MOUNT_POINT
rdbBuffer.ReparseDataLength = nDestMountPointBytes + 12
rdbBuffer.Reserved = 0
rdbBuffer.SubstituteNameOffset = 0
rdbBuffer.SubstituteNameLength = nDestMountPointBytes
rdbBuffer.PrintNameOffset = nDestMountPointBytes + 2
rdbBuffer.PrintNameLength = 0
rdbBuffer.PathBuffer = StringToIntArray(strDestinationDir)

lngRet = DeviceIoControl(lngDirHandle, FSCTL_SET_REPARSE_POINT,
rdbBuffer, rdbBuffer.ReparseDataLength + _
TMN_REPARSE_DATA_BUFFER_HEADER_SIZE, ByVal
0&, 0, lngBytes, ByVal 0&)

If lngRet = 0 Then
PrintError
End If

CloseHandle lngDirHandle
End Function
Private Function StringToIntArray(strIn As String) As Integer()
Dim intOut() As Integer
ReDim intOut(0 To Len(strIn) - 1) As Integer

CopyMemory intOut(0), ByVal StrPtr(strIn), Len(strIn) * 2
StringToIntArray = intOut
End Function
----------

The types are taken from the tutorial at
http://www.codeproject.com/w2k/junctionpoints.asp, and converted to VB.
So, I give it a directory, and run this. It's OK up until
DeviceIoControl, which returns 0. The error it returns is 4392 (The
data present in the reparse point buffer is invalid). So, my first
thought was that I was converting the string to an integer array wrong.
I ran the code in C++, had it print the array, and I had it right.

Note: I'm converting it to an integer array to mimic the C++ type
LPCWSTR.

I also tried creating a junction on the exact same directory from C++,
and it works perfectly. So, does anyone have any idea why this isn't
working?


Thanks in advance,
--AD

.



Relevant Pages

  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Help answer these 70-310 questions
    ... One argument is the string ... Dim output As New StringBuilder ... EmployeeLocations. ... You create a strongly named serviced component. ...
    (microsoft.public.cert.exam.mcad)
  • Help answer these 70-310 questions
    ... One argument is the string ... Dim output As New StringBuilder ... EmployeeLocations. ... You create a strongly named serviced component. ...
    (microsoft.public.cert.exam.mcsd)