Click here to Skip to main content
15,612,595 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to get the HWND from the windows on the "locked screen" Pin
SandipG 5-Nov-08 20:49
SandipG 5-Nov-08 20:49 
NewsRe: how to get the HWND from the windows on the "locked screen" Pin
Krzysztof Gorgolewski5-Nov-08 21:21
Krzysztof Gorgolewski5-Nov-08 21:21 
QuestionAny beginner's SDK tutorials? Pin
Megidolaon5-Nov-08 3:03
Megidolaon5-Nov-08 3:03 
AnswerRe: Any beginner's SDK tutorials? Pin
Saurabh.Garg5-Nov-08 3:11
Saurabh.Garg5-Nov-08 3:11 
AnswerRe: Any beginner's SDK tutorials? Pin
achainard5-Nov-08 3:47
achainard5-Nov-08 3:47 
AnswerRe: Any beginner's SDK tutorials? Pin
SandipG 5-Nov-08 4:01
SandipG 5-Nov-08 4:01 
AnswerRe: Any beginner's SDK tutorials? Pin
Megidolaon6-Nov-08 7:06
Megidolaon6-Nov-08 7:06 
QuestionCalls to windows API is failing for directory created by same process [modified] Pin
Aseem Sharma5-Nov-08 2:34
Aseem Sharma5-Nov-08 2:34 
Hi,

My application create a directory using CreateDirectory(). Then I want to lock this directory so that it can't be accessed by any other process. For that I call CreateFile() (Openning that directory and getting its handle) and doing so lock the directory and it is now not accessible to any other process. Then I create some file in this directory. The problem is that when I try to get the status of a file in that directory, I get the error code that file does not exist. When I try to rename a file in that directory, I get the error code that file is being used by some other process. but I can delete file without any problem. I could not understand that if the directory is locked by same process why calls to Windows APIs to get the status or renaming the <file in="" that="" directory=""> are failing. On the other side file could be deleted. Plz have a look at my code and if you can tell something that calls to those APIs don't fail, let me know plz. Or if this problem can't be resolved, can you give me any other idea by which I can lock the directory so that only current process is able to Create/Read/Write/Delete/GettingFileStatus files in that directory. The code is as below:

/* ----------------- Code is here -----------------*/

CreateDirectory("C:\\MyDir", NULL);

// Calling below function lock the folder and other processes can't access "C:\\MyDir"
HANDLE handleDirectory = CreateFile("C:\\MyDir",
GENERIC_ALL,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS, NULL);

// File is created successfully by calling below function
HANDLE handleFile = CreateFile("C:\\MyDir\\MyFile",
GENERIC_ALL,
FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);

CloseHandle(handleFile); // Closing file handle

// Getting file status
STATINFO statinfo;
int result;
result = stat("C:\\MyDir\\MyFile", &statinfo); //This call fails
// error code can be seen in c-runtime library's global variable "errno".

// Renaming also fails
result = rename("C:\\MyDir\\MyFile", "C:\\MyDir\\YourFile");
// error code can be seen in C-RunTime Library's global variable "errno".

// File deletion succeeds
result = remove("C:\\MyDir\\MyFile");
// error code can be seen in c-runtime library's global variable "errno".

/* ----------------- End of the code -----------------*/

Please tell me something that after locking the folder:
1 Directory is accessible to current process only.
2 Current process can get the status of a file in that directory.
3 Current process can Create/Read/write/Rename/delete a file in that directory
4 Or any other way of doing the same

Thanks in advance
Best Regards
Aseem Sharma

modified on Wednesday, November 5, 2008 10:18 PM
GeneralRe: Calls to windows API is failing for directory created by same process Pin
led mike5-Nov-08 4:16
led mike5-Nov-08 4:16 
GeneralRe: Calls to windows API is failing for directory created by same process Pin
Aseem Sharma5-Nov-08 20:45
Aseem Sharma5-Nov-08 20:45 
GeneralRe: Calls to windows API is failing for directory created by same process Pin
led mike6-Nov-08 5:34
led mike6-Nov-08 5:34 
GeneralRe: Calls to windows API is failing for directory created by same process Pin
Aseem Sharma6-Nov-08 19:13
Aseem Sharma6-Nov-08 19:13 
QuestionCFileDialog problem in MFC REGULAR DLL [modified] Pin
W.Kim 19875-Nov-08 2:32
W.Kim 19875-Nov-08 2:32 
QuestionRe: CFileDialog problem in MFC EXT DLL Pin
Mark Salsbery5-Nov-08 4:40
Mark Salsbery5-Nov-08 4:40 
AnswerRe: CFileDialog problem in MFC EXT DLL Pin
W.Kim 19875-Nov-08 17:34
W.Kim 19875-Nov-08 17:34 
GeneralRe: CFileDialog problem in MFC EXT DLL Pin
Mark Salsbery6-Nov-08 15:03
Mark Salsbery6-Nov-08 15:03 
GeneralRe: CFileDialog problem in MFC EXT DLL Pin
W.Kim 19878-Nov-08 1:15
W.Kim 19878-Nov-08 1:15 
Question3D array Pin
kDevloper4-Nov-08 23:48
kDevloper4-Nov-08 23:48 
AnswerRe: 3D array Pin
Iain Clarke, Warrior Programmer4-Nov-08 23:56
Iain Clarke, Warrior Programmer4-Nov-08 23:56 
GeneralRe: 3D array Pin
kDevloper5-Nov-08 0:00
kDevloper5-Nov-08 0:00 
GeneralNah! Pin
CPallini5-Nov-08 0:14
mveCPallini5-Nov-08 0:14 
GeneralRe: Nah! Pin
kDevloper5-Nov-08 0:33
kDevloper5-Nov-08 0:33 
GeneralRe: Nah! Pin
CPallini5-Nov-08 0:41
mveCPallini5-Nov-08 0:41 
GeneralRe: Nah! Pin
kDevloper5-Nov-08 0:51
kDevloper5-Nov-08 0:51 
JokeRe: Nah! Pin
Rajesh R Subramanian5-Nov-08 2:11
professionalRajesh R Subramanian5-Nov-08 2:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.