Click here to Skip to main content
15,890,512 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC CScrollView update problem when scrolling Pin
baumchen20-Jan-10 11:12
baumchen20-Jan-10 11:12 
QuestionGetting Function Signatures from a DLL Pin
thatonegirl18-Jan-10 10:31
thatonegirl18-Jan-10 10:31 
AnswerRe: Getting Function Signatures from a DLL Pin
Stuart Dootson18-Jan-10 11:56
professionalStuart Dootson18-Jan-10 11:56 
GeneralRe: Getting Function Signatures from a DLL Pin
thatonegirl19-Jan-10 3:20
thatonegirl19-Jan-10 3:20 
AnswerRe: Getting Function Signatures from a DLL Pin
Garth J Lancaster18-Jan-10 15:31
professionalGarth J Lancaster18-Jan-10 15:31 
QuestionHow to read/process locked files? Pin
ZystemsK18-Jan-10 10:12
ZystemsK18-Jan-10 10:12 
QuestionRe: How to read/process locked files? Pin
David Crow18-Jan-10 10:29
David Crow18-Jan-10 10:29 
AnswerRe: How to read/process locked files? Pin
ZystemsK18-Jan-10 11:19
ZystemsK18-Jan-10 11:19 
Here's my sample code and output:

#include <windows.h>
#include <iostream>
#include <time.h>
#include <tchar.h>


using namespace std;
BOOL	SetPrivilege(LPCTSTR lpszPrivilege, BOOL bEnablePrivilege);
HANDLE hFile;

void main() {

	BOOL ret = SetPrivilege(SE_BACKUP_NAME,TRUE);
	cout << "Ret: " << ret << endl;

	DWORD dwErr=0;
	hFile = CreateFile(L"c:\\windows\\system32\\config\\system", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
	cout << "Handle: " << hFile << endl;
	if (INVALID_HANDLE_VALUE == hFile) {
		dwErr = GetLastError();
		CloseHandle(hFile);
		cout << "Could not open file: " << dwErr << endl;
	}
	
	CloseHandle(hFile);
	SetPrivilege(SE_BACKUP_NAME,FALSE);
}

BOOL	SetPrivilege(LPCTSTR lpszPrivilege, BOOL bEnablePrivilege)
{
	TOKEN_PRIVILEGES tp;
	LUID luid;
	HANDLE hToken; 

	OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
	if ( !LookupPrivilegeValue(NULL, lpszPrivilege, &luid) )    
		return FALSE; 
	
	tp.PrivilegeCount = 1;
	tp.Privileges[0].Luid = luid;
	
	if (bEnablePrivilege)
		tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
	else
	    tp.Privileges[0].Attributes = 0;

	AdjustTokenPrivileges(hToken, FALSE, &tp, 0, (PTOKEN_PRIVILEGES) NULL, 0); 

	return ( (GetLastError()!=ERROR_SUCCESS)?FALSE:TRUE);
}


<br />
Ret: 1<br />
Handle: FFFFFFFF<br />
Could not open file: 32<br />


As you can see, it gave an Error 32, which is:
ERROR_SHARING_VIOLATION
32 (0x20)
The process cannot access the file because it is being used by another process.

I think I'm doing it properly... Mad | :mad:
AnswerRe: How to read/process locked files? Pin
Peter Weyzen18-Jan-10 14:09
Peter Weyzen18-Jan-10 14:09 
GeneralRe: How to read/process locked files? Pin
ZystemsK19-Jan-10 3:09
ZystemsK19-Jan-10 3:09 
GeneralRe: How to read/process locked files? Pin
ZystemsK19-Jan-10 4:19
ZystemsK19-Jan-10 4:19 
QuestionReading a file from disk in C Pin
Danzy8318-Jan-10 3:07
Danzy8318-Jan-10 3:07 
AnswerRe: Reading a file from disk in C Pin
Covean18-Jan-10 3:20
Covean18-Jan-10 3:20 
GeneralRe: Reading a file from disk in C Pin
Danzy8318-Jan-10 3:28
Danzy8318-Jan-10 3:28 
GeneralRe: Reading a file from disk in C Pin
Covean18-Jan-10 3:37
Covean18-Jan-10 3:37 
AnswerRe: Reading a file from disk in C Pin
CPallini18-Jan-10 3:23
mveCPallini18-Jan-10 3:23 
GeneralRe: Reading a file from disk in C Pin
Danzy8318-Jan-10 3:36
Danzy8318-Jan-10 3:36 
GeneralRe: Reading a file from disk in C Pin
Electron Shepherd18-Jan-10 3:43
Electron Shepherd18-Jan-10 3:43 
GeneralRe: The _stat function Pin
Danzy8318-Jan-10 3:56
Danzy8318-Jan-10 3:56 
GeneralRe: The _stat function Pin
Electron Shepherd18-Jan-10 3:59
Electron Shepherd18-Jan-10 3:59 
GeneralThanks CPallini and Covean Pin
Danzy8318-Jan-10 3:53
Danzy8318-Jan-10 3:53 
GeneralRe: Thanks CPallini and Covean Pin
CPallini18-Jan-10 6:56
mveCPallini18-Jan-10 6:56 
GeneralRe: Thanks CPallini and Covean Pin
Rozis18-Jan-10 11:32
Rozis18-Jan-10 11:32 
AnswerRe: Reading a file from disk in C PinPopular
Joe Woodbury18-Jan-10 7:14
professionalJoe Woodbury18-Jan-10 7:14 
QuestionUsing Zend library in vc++ Pin
Ash_VCPP18-Jan-10 3:02
Ash_VCPP18-Jan-10 3:02 

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.