what do i put here?

i dont know what to put for the part of the code at line 24 and 25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);
    
    hd_file = CreateFile("C:\\Users\\Kyle\\Desktop\\watcher",0,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
    
//    ReadDirectoryChangesW(hd_file FILE_LIST_DIRECTORY,
////  __out        PVOID lpBuffer,       // this here
////  __in         DWORD nBufferLength,  // and this here
////  __in         FALSE,
////  __in         FILE_NOTIFY_CHANGE_LAST_ACCESS,
////  __out_opt    PDWORD lpBytesReturned,
////  __inout_opt  OVERLAPPED,
////  __in_opt     LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
////); 
Last edited on
Still a noob so I don't know that this is correct:

Try declaring a FILE_NOTIFY_INFORMATION variable and passing it by reference as the lpBuffer param, for nBufferLength, pass sizeof(FILE_NOTIFY_INFORMATION).

like

1
2
FILE_NOTIFY_INFORMATION buffer;
ReadDirectoryChangesW(hd_file, buffer, sizeof(buffer)....etc.);
Last edited on
actually i tried something close to that but it didnt work. had to use char [] for the buffer

this is what i have now and the errors below that:
1
2
3
4
5
6
7
8
9
10
11
12
13
ShowWindow (hwnd, nFunsterStil);
    
    hd_file = CreateFile("C:\\Users\\Kyle\\Desktop\\watcher",0,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
    
    ReadDirectoryChangesW(
     hd_file,
     file_buff,
     1200,
     FALSE,
     FILE_NOTIFY_CHANGE_LAST_ACCESS,
     1200,
     NULL,    // this seems to be the only error so far
     ERROR_SUCCESS);

1
2
3
4
76 C:\Users\Kyle\Desktop\folderlockprog\main.cpp invalid conversion from `int' to `DWORD*'

76 C:\Users\Kyle\Desktop\folderlockprog\main.cpp   initializing argument 6 of `BOOL ReadDirectoryChangesW(void*, void*, DWORD, BOOL, DWORD, DWORD*, _OVERLAPPED*, void (*)(DWORD, DWORD, _OVERLAPPED*))'
 
The error is indicating that the 6th paramater has to be passed by reference, it's looking for a pointer to an integer.

1
2
3
4
5
6
7
8
9
10
11
DWORD bytesReturned;

ReadDirectoryChangesW(
     hd_file,
     file_buff,
     1200,
     FALSE,
     FILE_NOTIFY_CHANGE_LAST_ACCESS,
     &bytesReturned,
     NULL,    // this seems to be the only error so far
     ERROR_SUCCESS);


MSDN:

1
2
lpBytesReturned [out, optional] 
For synchronous calls, this parameter receives the number of bytes transferred into the lpBuffer parameter. For asynchronous calls, this parameter is undefined. You must use an asynchronous notification technique to retrieve the number of bytes transferred.
ok so instead of a number use a variable.?.

when i do i get this:
1
2
3
77 C:\Users\Kyle\Desktop\folderlockprog\main.cpp invalid conversion from `DWORD' to `DWORD*'

77 C:\Users\Kyle\Desktop\folderlockprog\main.cpp   initializing argument 6 of `BOOL ReadDirectoryChangesW(void*, void*, DWORD, BOOL, DWORD, DWORD*, _OVERLAPPED*, void (*)(DWORD, DWORD, _OVERLAPPED*))' 


never mind i was missing the &,lol

now do i put this in the main program loop if i want it to continuously check for changes?
Last edited on
Read the MSDN article on using this API.

Not sure why you're passing ERROR_SUCCESS for your last param.

Notes from MSDN:

1
2
lpCompletionRoutine [in, optional] 
A pointer to a completion routine to be called when the operation has been completed or canceled and the calling thread is in an alertable wait state. For more information about this completion routine, see FileIOCompletionRoutine.


You should be passing a function pointer to a FileIOCompletionRoutine for your last parameter.
You should be passing a function pointer to a FileIOCompletionRoutine for your last parameter.


umm... not sure what u mean. can you give an example?
I do not mean any offense by this, buy I would strongly suggest that you get a good C++ book and read up on that(I'd recommend C++ for Dummies, which is what I learned off of).

Back to your question.

You need to create a FileIOCompletionRoutine function, and then pass the function's address to the last parameter of the ReadDirectoryChanges function.

If you do not understand that, refer to the above advice.
no i got it.(no offence taken)
i thought that FileIOCompletionRoutine function was in windows.h or another headerfile. something like that. didn't know that i needed to write that function myself.
Topic archived. No new replies allowed.