|
Hi DavidCrow,
After reading the MSDN document for NetFileEnum, I am confused. The description is,
--------------------
The NetFileEnum function returns information about some or all open files on a server, depending on the parameters specified.
--------------------
Server means? I just want to find all the used (open) files on the local machine. Any ideas or comments?
regards,
George
|
|
|
|
|
George_George wrote: Server means? I just want to find all the used (open) files on the local machine. Any ideas or comments?
servername
[in] Pointer to a Unicode (Windows NT/2000/XP) or ANSI (Windows 95/98/Me) string specifying the name of the remote server on which the function is to execute. The string must begin with \\. If this parameter is NULL, the local computer is used.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks DavidCrow,
But does it relates to my original question? I just want to find whether a local file is opened or not. Any comments?
regards,
George
|
|
|
|
|
George_George wrote: But does it relates to my original question?
Only you can determine if NetFileEnum() will meet your needs.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi DavidCrow,
This function will find all open files... But I only want to find whether a specific file is open or not, file name is known. The NetFileEnum function is fine, but too heavy for me.
I think using OpenFile with exclusive shared mode option is fine. Any comments?
regards,
George
|
|
|
|
|
George_George wrote: I think using OpenFile with exclusive shared mode option is fine. Any comments
That will only tell you if the file is already open with exclusive access. It will not tell you if the file is already open with shared access. AFAIK, there is no user-mode way to tell that, unless David's previous answer can do that (I haven't ever needed to use the Net set of functions).
Judy
modified on Thursday, April 3, 2008 4:19 PM
|
|
|
|
|
Thanks Judy,
I think I should use ::OpenFile() with OF_SHARE_EXCLUSIVE -- the best choice. Right?
regards,
George
|
|
|
|
|
If you want to test every file under scrutiny, yes that will work. I'd try David's enum suggestion if you're looking to get a list.
Judy
|
|
|
|
|
Thanks Judy,
I only need to test for a specific file. I think OpenFile is enough, agree?
regards,
George
|
|
|
|
|
Yes, using OF_SHARE_EXCLUSIVE
|
|
|
|
|
Thanks JudyL_FL,
Question answered.
regards,
George
|
|
|
|
|
George_George wrote: which API could be used to check whether a file is opened
Depends on your definition of "file is opened". An application can be displaying the contents of a file and even allowing the user to edit the contents without having an active file handle to the disk file used to persist the data. In that case there is no API that's going to tell you that, period.
led mike
|
|
|
|
|
Open I can it is used by other thread/process, they may not open the file in exclusive mode, but I need to detect whether it is used (open) or not. Any ideas?
regards,
George
|
|
|
|
|
You can try opening the file in exclusive mode.
onwards and upwards...
|
|
|
|
|
Thanks basementman!
You mean OF_SHARE_EXCLUSIVE mode of OpenFile?
regards,
George
|
|
|
|
|
|
Thanks Hamid,
I looked through the link, does it relates to my original question?
regards,
George
|
|
|
|
|
I think its helpful about files,right?
|
|
|
|
|
Thanks Hamid,
It is helpful. But not direct relates to my original question.
regards,
George
|
|
|
|
|
|
|
I am far from being a VB expert, but shouldn't you pass the integer ByVal instead of ByRef ? Did you try to debug the dll to see which number you receive and what you are returning ?
|
|
|
|
|
I am not actually sure how to debug DLL :s
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
here's how i debug DLL + VB situations:
1. in the C++ project, "run" the DLL.
2. VS will prompt you for a debug target. tell it to run VB.exe (VB itself)
3. when VB opens, open your VB application
4. put a breakpoint on the call to your DLL
5. run your VB app
now you can step into your C++ DLL
|
|
|
|
|
Quoted from this page[^]:
One important note is that all parameters must be passed with the ByVal keyword. This is because Visual Basic always passes parameters ByRef by default. Since C/C++ usually passes by value, this must be specified in the Visual Basic declaration. This is all that is necessary when standard C variable types (int, long, etc.) are used, however complex data types like strings and arrays require more overhead on both the client and DLL sides.
They also specify that a VB integer correspond to a short in C/C++. So, change the C function to accept a short and check if it works (and don't forget the ByVal).
|
|
|
|