Dear all,
I am declare the problem variant (HANDLE hBoard) in the following sentense:
---------------MyDll.dll-------------------
HANDLE hBoard;
...
__declspec (dllexport) Open(...){
hBoard=OpenFile(...);
}
...
__declspec(dllexport) Close(...){
CloseHandle(hBoard);
}
The application refers to the above dll file
---------------myExe.exe--------------------
#pragma comment(lib,"MyDll.dll");
......
......
Open(...);
Access(...);
Close(...);
Now,I am do the following steps:
1.Spaw two instance of application which may use this dll.
2.Close one instance which I am executed in step 1.
I am found that if I do step 2.All of two application runnig instance’s handle will be closed.
It means that the variant [hBoard] seems be shared by two process.And the one of the procedure running will be cause the other one.I am want to prevent it happening.
I am try to change codes to the following like:
__declspec(thread) HANDLE hBoard;
Now,the application will result in out of order.
I want to know,How can I define global variant which will not be changed in other process running?
Thanks a lot.
Yours
Gamma Folk.
> I want to know,How can I define global variant which will not be changed in other process running?
Just declare it the way you normally declare global variables. If you wanted to do the opposite, i.e. make it shared by all processes your DLL is loaded to, you would have to put it into a shared section, i.e. take some extra steps. However, in order to achieve your goal, no special steps are needed…
I am found that if I do step 2.All of two application runnig instance’s handle will be closed.
It means that the variant [hBoard] seems be shared by two process.
This conclusion is simply wrong. Furthermore, even if a handle value was shared, closing a handle in the process X objectively cannot affect the process Y, because they have their separate descriptor tables, so that it would be meaningful only for the process that has opened it with CreateFile()…
Anton Bassov
Thank Anton Bassov for quickly response.
>This conclusion is simply wrong. Furthermore, even if a handle value was shared,
closing a handle in the process X objectively cannot affect the process Y,
because they have their separate descriptor tables, so that it would be
meaningful only for the process that has opened it with CreateFile()…
<< Your are right. when I close the Handle.I set the handle to INVLID_HANDLE_VALUE
>Just declare it the way you normally declare global variables. If you wanted to
do the opposite, i.e. make it shared by all processes your DLL is loaded to, you
would have to put it into a shared section, i.e. take some extra steps. However,
in order to achieve your goal, no special steps are needed…
<< Yes,It is right too,I make a mistack in my driver’S cleanup rounter.
Thank you a lot.