Click here to Skip to main content
15,896,111 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Edit Box Problem!! Pin
HP31-Aug-00 1:17
HP31-Aug-00 1:17 
GeneralTab Control Help Pin
sunny30-Aug-00 11:02
sunny30-Aug-00 11:02 
GeneralRe: Tab Control Help Pin
Erik Funkenbusch30-Aug-00 13:50
Erik Funkenbusch30-Aug-00 13:50 
GeneralRe: Tab Control Help Pin
jschacker31-Aug-00 9:59
jschacker31-Aug-00 9:59 
GeneralData to Printer Port Pin
Gary30-Aug-00 10:36
Gary30-Aug-00 10:36 
GeneralMultimedia Timer Class Pin
C. Hampton30-Aug-00 7:33
sussC. Hampton30-Aug-00 7:33 
GeneralRe: Multimedia Timer Class Pin
Paolo Messina30-Aug-00 8:26
professionalPaolo Messina30-Aug-00 8:26 
GeneralAcquiring PSID for ReportEvent Pin
sai30-Aug-00 5:52
sai30-Aug-00 5:52 
Hello fellow developers,

Please help me diagnose why this piece of code crashes my simple MFC Dialog based application. Essentially this code is supposed to retrieve the SID of the currently logged in user. When I pass through debugger I do see the SID being retrieved properly, SID also passes the IsValisSid() API call and all return codes tally. However, after passing through this code segment, the memory gets corrupted (m_hWnd = ??? among other things) and the app crashes. Stack trace is leading me no where. Please let me know what might be wrong, or what else I can do to figure out the problem or if there is a better way of doing this in the first place.

Many thanks.

Sai

#define SIDS 1
#if SIDS // USER NAME START

SID userSID ;//NULL;
DWORD cbUserSID = 0;
char *szDomain = NULL;
DWORD cbDomain = 0;
PSID_NAME_USE peUse = NULL;
SID_NAME_USE tSnu;
BOOL fAPISuccess = FALSE;
char *szUserName = NULL;
DWORD cbUserName = 0;

fAPISuccess = GetUserName(szUserName, &cbUserName);

// API should have failed with insufficient buffer.
if (fAPISuccess)
{
return;
}
else if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
printf("GetUserName() failed. Error %d\n", GetLastError());
return;
}

szUserName = new char[cbUserName];
if (!szUserName)
{
printf("HeapAlloc() failed. Error %d\n", GetLastError());
return;
}

fAPISuccess = GetUserName(szUserName, &cbUserName);
if (!fAPISuccess)
{
printf("GetUserName() failed. Error %d\n", GetLastError());
return;
}

// STEP 2: Get SID for current user.
//
fAPISuccess = LookupAccountName((LPSTR) NULL, szUserName,
&userSID, &cbUserSID, szDomain, &cbDomain, peUse);

// API should have failed with insufficient buffer.
if (fAPISuccess)
{
return;
}
else if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
printf("LookupAccountName() failed. Error %d\n",
GetLastError());
return;
}

szDomain = new char[cbDomain];
if (!szDomain)
{
printf("HeapAlloc() failed. Error %d\n", GetLastError());
return;
}

fAPISuccess = LookupAccountName((LPSTR) NULL, szUserName,
&userSID, &cbUserSID, szDomain, &cbDomain, &tSnu);
if (!fAPISuccess)
{
printf("LookupAccountName() failed. Error %d\n",
GetLastError());
return;
}

if (szUserName)
{
delete szUserName;
}

if (szDomain)
{
delete szDomain;
}

if(IsValidSid(&userSID))
{
m_pSid = &userSID;
}

#endif // USER NAME END
GeneralSocketproblem using service Pin
Andreas30-Aug-00 5:03
Andreas30-Aug-00 5:03 
GeneralGenerating COM-TypeLibraries with MIDL Pin
Sven Wiegand30-Aug-00 4:08
Sven Wiegand30-Aug-00 4:08 
QuestionHow can I use ownerdraw in a CCtrlView based on listbox Pin
Ronald L. Russell (Ron)30-Aug-00 4:00
sussRonald L. Russell (Ron)30-Aug-00 4:00 
GeneralTransparency ... Pin
Oleg Zhuk30-Aug-00 0:29
Oleg Zhuk30-Aug-00 0:29 
QuestionHow do you use the CToolTipCtrl? Pin
Newbie29-Aug-00 17:37
Newbie29-Aug-00 17:37 
AnswerRe: How do you use the CToolTipCtrl? Pin
Jeremy Davis29-Aug-00 22:23
Jeremy Davis29-Aug-00 22:23 
AnswerRe: How do you use the CToolTipCtrl? Pin
jschacker1-Sep-00 8:12
jschacker1-Sep-00 8:12 
GeneralAbout SMB (CIFS) example code Pin
Joe Huang29-Aug-00 17:18
Joe Huang29-Aug-00 17:18 
GeneralTab Contorl Pin
sunny29-Aug-00 10:22
sunny29-Aug-00 10:22 
GeneralPrinting in Document-View architecture Pin
André Dewispelaere29-Aug-00 5:55
André Dewispelaere29-Aug-00 5:55 
GeneralRe: Printing in Document-View architecture Pin
jschacker31-Aug-00 10:48
jschacker31-Aug-00 10:48 
GeneralRe: Printing in Document-View architecture Pin
André Dewispelaere20-Sep-00 3:52
André Dewispelaere20-Sep-00 3:52 
GeneralString Table - message boxes interference Pin
André Dewispelaere29-Aug-00 5:33
André Dewispelaere29-Aug-00 5:33 
GeneralRe: String Table - message boxes interference Pin
André Dewispelaere20-Sep-00 4:06
André Dewispelaere20-Sep-00 4:06 
GeneralHooks:WH_HARDWARE Pin
alainserge26-Aug-00 6:35
alainserge26-Aug-00 6:35 
GeneralRe: Hooks:WH_HARDWARE Pin
Michael Dunn26-Aug-00 7:33
sitebuilderMichael Dunn26-Aug-00 7:33 
GeneralDialog from console Pin
Erik26-Aug-00 4:53
Erik26-Aug-00 4:53 

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.