Click here to Skip to main content
15,899,025 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalperfomance improvement Pin
Member 118907820-Jun-04 23:14
Member 118907820-Jun-04 23:14 
GeneralRe: perfomance improvement Pin
Johan Rosengren21-Jun-04 2:38
Johan Rosengren21-Jun-04 2:38 
GeneralRe: perfomance improvement Pin
basementman21-Jun-04 7:29
basementman21-Jun-04 7:29 
QuestionHow to open a file with corresponded program Pin
ngocdq20-Jun-04 23:01
ngocdq20-Jun-04 23:01 
AnswerRe: How to open a file with corresponded program Pin
Ghazi H. Wadi20-Jun-04 23:07
Ghazi H. Wadi20-Jun-04 23:07 
AnswerRe: How to open a file with corresponded program Pin
gamitech22-Jun-04 13:40
gamitech22-Jun-04 13:40 
GeneralTo Ghazi Al Wadi Pin
ngocdq20-Jun-04 21:08
ngocdq20-Jun-04 21:08 
GeneralRe: To Ghazi Al Wadi Pin
Ghazi H. Wadi20-Jun-04 22:46
Ghazi H. Wadi20-Jun-04 22:46 
Hi,
The issue is you have to find the required buffer for each parameter. see the example below.
Simply open up an MFC Dialog project and place this code in the OnOk () function.
Browse for and select the fpasted file and clikc ok.

Cheers

<br />
void CFindOwnerDlg::OnOK() <br />
{<br />
	 char szFilters[]=<br />
      "MyType Files (*.*)|All Files (*.*)|*.*||";<br />
<br />
	// TODO: Add extra validation here<br />
 // Create an Open dialog<br />
   CFileDialog fileDlg (TRUE, "*", "*.*",<br />
      OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);<br />
   <br />
   // Display the file dialog. When user clicks OK, fileDlg.DoModal() <br />
   // returns IDOK.<br />
   if( fileDlg.DoModal ()==IDOK )<br />
   {<br />
	ULONG uSizeSD ;        // Buffer size to store Owner's SID<br />
    PSID pOwner = NULL ; //            Pointer to the Owner's SID<br />
    char szName[MAX_PATH] ;// String           Name of the file owner<br />
    char  szDomain_name[MAX_PATH] ;// Name of the first domain for the owner<br />
<br />
	// use of MAX_PATH should be removed and replaced with memory allocation <br />
<br />
   ULONG uName_len ; //        Required length for the owner name<br />
   ULONG domain_len; //        Required length for the domain name<br />
   char *sdBuf; //          Buffer for Security Descriptor<br />
   SID_NAME_USE  deUse ; //            Pointer to a SID_NAME_USE enumerated<br />
<br />
<br />
	int 	bSuccess = 0;<br />
      szName[0] = 0;<br />
      szDomain_name [0] = 0;<br />
      uName_len = 0;<br />
      domain_len = 0;<br />
     // *pOwner = 0;<br />
 <br />
BOOL fOwnerExists = FALSE;<br />
<br />
<br />
<br />
	   CString pathName = fileDlg.GetFileName ();<br />
<br />
<br />
  bSuccess = GetFileSecurity( <br />
           pathName, <br />
           OWNER_SECURITY_INFORMATION, <br />
           0, <br />
           0, <br />
           &uSizeSD);<br />
  // its should fial here as the buffer is not big enough<br />
  if (bSuccess != 0) <br />
         MessageBox ("It should not happen as it should be an error  ");     <br />
  else<br />
  {<br />
	  sdBuf = new char [uSizeSD];<br />
<br />
	   bSuccess = GetFileSecurity( <br />
           pathName, <br />
           OWNER_SECURITY_INFORMATION, <br />
           sdBuf, <br />
           uSizeSD, <br />
           &uSizeSD);<br />
<br />
	   bSuccess = GetSecurityDescriptorOwner(sdBuf, &pOwner, &fOwnerExists);<br />
<br />
	   // this first run is to find out about the length<br />
<br />
	bSuccess = LookupAccountSid (NULL /*Empty for Local Host*/, pOwner /* Sid To Look info for*/,szName,  &uName_len, szDomain_name, &domain_len,  &deUse);<br />
	// the second one will tell them the size	<br />
	bSuccess = LookupAccountSid (NULL /*Empty for Local Host*/, pOwner /* Sid To Look info for*/,szName,  &uName_len, szDomain_name, &domain_len,  &deUse);<br />
	<br />
	if (bSuccess == 0) <br />
         MessageBox ("Error ");    // use get last error    <br />
    else<br />
  {<br />
	  CString msg;<br />
	  msg = szDomain_name ;<br />
	  msg= msg +  "\\";<br />
	msg =msg + szName;<br />
      MessageBox (msg);<br />
  }<br />
  }<br />
   }<br />
<br />
<br />
<br />
// P.S. remove allocated memeory <br />
<br />
}<br />


It is Illogical to define an inventor by his invention
GeneralRe: To Ghazi Al Wadi Pin
ngocdq21-Jun-04 15:38
ngocdq21-Jun-04 15:38 
GeneralRe: Hi Wadi, my problem is: Pin
ngocdq21-Jun-04 15:42
ngocdq21-Jun-04 15:42 
GeneralRe: Hi Wadi, my problem is: Pin
Ghazi H. Wadi22-Jun-04 19:18
Ghazi H. Wadi22-Jun-04 19:18 
Generalreflection Pin
Jerome Conus20-Jun-04 20:24
Jerome Conus20-Jun-04 20:24 
GeneralRe: reflection Pin
Roger Wright20-Jun-04 21:02
professionalRoger Wright20-Jun-04 21:02 
GeneralRe: reflection Pin
wb21-Jun-04 1:05
wb21-Jun-04 1:05 
GeneralRe: reflection Pin
Prakash Nadar21-Jun-04 0:14
Prakash Nadar21-Jun-04 0:14 
GeneralRe: reflection Pin
Johnny ²21-Jun-04 1:14
Johnny ²21-Jun-04 1:14 
GeneralRe: reflection Pin
Ryan Roberts21-Jun-04 1:29
Ryan Roberts21-Jun-04 1:29 
QuestionProgram exited with code 2 (0x02). What does it mean? Pin
uus9920-Jun-04 20:13
uus9920-Jun-04 20:13 
AnswerRe: Program exited with code 2 (0x02). What does it mean? Pin
Michael Dunn20-Jun-04 20:23
sitebuilderMichael Dunn20-Jun-04 20:23 
AnswerRe: Program exited with code 2 (0x02). What does it mean? Pin
Antony M Kancidrowski21-Jun-04 2:40
Antony M Kancidrowski21-Jun-04 2:40 
GeneralRe: Program exited with code 2 (0x02). What does it mean? Pin
uus9921-Jun-04 14:04
uus9921-Jun-04 14:04 
GeneralRe: Program exited with code 2 (0x02). What does it mean? Pin
Antony M Kancidrowski22-Jun-04 10:25
Antony M Kancidrowski22-Jun-04 10:25 
Generalinverting an image Pin
Naga the bug fixer20-Jun-04 19:39
Naga the bug fixer20-Jun-04 19:39 
GeneralRe: inverting an image Pin
ThatsAlok21-Jun-04 22:31
ThatsAlok21-Jun-04 22:31 
GeneralWindows Messages Pin
aamir121a20-Jun-04 18:36
aamir121a20-Jun-04 18:36 

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.