|
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).
|
|
|
|
|
Hi first of all thanks for quick reply.
Some how I realised that the speed of DLL and EXE could vary, so now I have timer which will get number every second. AND I did what you just said and now it's giving me random number between 0(1) - 100 (never seen 0 or 100) but yeh. But what happens now is that the numbers comes in ascending order.
2
12
43
56
78
90
95
1
3
5
and so on...
What surprises me most is that the same code works perfect with C but not with VB.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
Cedric Moonen wrote: ...but shouldn't you pass the integer ByVal instead of ByRef ?
I don't see this making any difference since the ByVal /ByRef keyword only affect how the argument is sent to rndNum() , not what type of value is returned from it.
"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
|
|
|
|
|
I don't know how it is implemented in VB, but if the ByRef is in fact passing the address of the variable, then this is the problem because that will have an impact on what the function returns (because the random number will be between 0 and that number).
|
|
|
|
|
killerp wrote: ...I'm trying to receive RANDOM number from C and add to my VB form.
Unless this is just a test to see if the two can communicate, or you are just wanting to see how a DLL works, why not just let your VB app generate its own random numbers?
killerp wrote: But the number received is not random...
How are you verifying this?
killerp wrote: But the number received is...way to big than what I pass into the parameter.
This statement makes little sense. The argument passed to rndNum() is simply used to seed the random number generator. It has no bearing on anything else.
"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
|
|
|
|
|
I'm doing bit of research on random numbers from different language, and I am already using VB, C# and C So I see what you are trying to say, but I want to use this.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|