473,494 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DeviceIOControl works but output buffer contains all zeros

I am trying to query the change journal using the deviceIOControl API. The API doesn't return an error, but all of the values in the output buffer are zero, and they shouldn't be. My code is below. I have also tried specifying different pack values in my USN_JOURNAL_DATA structure definition but this didn't change anything. Any help would be greatly appreciated

Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const OPEN_EXISTING = 3
Private Const METHOD_BUFFERED = &H0
Private Const FILE_DEVICE_FILE_SYSTEM = &H9
Private Const FILE_ANY_ACCESS = &H0
Private Const FILE_SPECIAL_ACCESS = FILE_ANY_ACCESS

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> Public Structure USN_JOURNAL_DATA
Public UsnJournalID As Long
Public FirstUsn As Int64
Public NextUsn As Int64
Public LowestValidUsn As Int64
Public MaxUsn As Int64
Public MaximumSize As Long
Public AllocationDelta As Long
End Structure

Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal DesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long

Declare Auto Function DeviceIoControl Lib "kernel32.dll" (ByVal hDevice As Long, ByVal dwIoControlCode As Integer, ByVal lpInBuffer As Integer, ByVal nInBufferSize As Integer, <MarshalAs(UnmanagedType.Struct)> ByRef lpOutBuffer As USN_JOURNAL_DATA, ByVal nOutBufferSize As Integer, ByRef lpBytesReturned As Integer, ByVal lpOverlapped As Integer) As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim FSCTL_QUERY_USN_JOURNAL As Long = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 61, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
Dim aHandle As Long
Dim anObject As Long
Dim byteBack As Long
Dim ujd As USN_JOURNAL_DATA

aHandle = CreateFile("\\.\I:", 0&, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0&, OPEN_EXISTING, 0&, 0&)
anObject = DeviceIoControl(aHandle, FSCTL_QUERY_USN_JOURNAL, 0, 0, ujd, Marshal.SizeOf(ujd), byteBack, 0)
If anObject = 0 Then
MsgBox(Marshal.GetLastWin32Error.ToString & Marshal.GetHRForLastWin32Error.ToString)
Else
MsgBox(ujd.UsnJournalID.ToString)
MsgBox(ujd.UsnJournalID)
MsgBox(ujd.FirstUsn)
MsgBox(ujd.NextUsn)
MsgBox(ujd.MaxUsn)
MsgBox(ujd.LowestValidUsn)
MsgBox(ujd.AllocationDelta)
MsgBox(ujd.MaximumSize)
End If
End Sub

Public Function CTL_CODE(ByVal DeviceType As Integer, ByVal Func As Integer, ByVal Method As Integer, ByVal Access As Integer) As Long
Return (DeviceType << 16) Or (Access << 14) Or (Func << 2) Or Method
End Function
Nov 20 '05 #1
1 2507
* "=?Utf-8?B?UGl4aWU=?=" <Pi***@discussions.microsoft.com> scripsit:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> Public Structure USN_JOURNAL_DATA
Public UsnJournalID As Long
Public FirstUsn As Int64
Public NextUsn As Int64
Public LowestValidUsn As Int64
Public MaxUsn As Int64
Public MaximumSize As Long
Public AllocationDelta As Long
End Structure

Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal DesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long

Declare Auto Function DeviceIoControl Lib "kernel32.dll" (ByVal hDevice As Long, ByVal dwIoControlCode As Integer, ByVal lpInBuffer As Integer, ByVal nInBufferSize As Integer, <MarshalAs(UnmanagedType.Struct)> ByRef lpOutBuffer As USN_JOURNAL_DATA, ByVal nOutBufferSize As Integer, ByRef lpBytesReturned As Integer, ByVal lpOverlapped As Integer) As Long


Notice that 'Long' is a 64-bit datatype in .NET, but 'DWORD' is 32-bit.
You will have to change some of the 'As Long' to 'As Int32'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
840
by: ewoo | last post by:
I'm trying to write a wrapper in csharp to wrap DeviceIoControl() win32 method for IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS control code--without much luck. I've seen lots of examples out there for...
9
2712
by: Jay Donnell | last post by:
I have a function that is a few thousand lines of code (I didn't write it) and I want to capture the output and save it as a variable. This is very easy to do in php. It would look something like...
8
5448
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
0
1027
by: ttan | last post by:
How do I send a buffer down to a driver and receive back a new buffer from that driver? I received the new buffer from the driver but it give me the wrong data. And how do I know if...
3
8223
by: Jacky | last post by:
Hi, I am trying to make network card interface with VB.NET 2002. I use DeviceIOControl-function. I have tried to define inbuffer and outbuffer using byte array and it's pointer. The second I...
0
2302
by: Pixie | last post by:
We are successfully getting a handle to a drive using createfile then using that handle to query the change journal using DeviceIOControl with the paramter FSCTL_QUERY_USN_DATA. However when we try...
1
4543
by: Juan Pedro Gonzalez | last post by:
Helo, I'm having problems here with the input buffer.... Ive defined the API call as: <System.Runtime.InteropServices.DllImport("kernel32", SetLastError:=True)> _ Private Shared Function...
2
3747
by: Jim | last post by:
I'm not sure how to perform this operation in Python. The difficulty is in knowing the size of the output buffer: if it is too small, I get an "insufficient buffer" exception; too large, and I get...
3
3736
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
0
7119
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.