|
For systems with fast user switching (XP+) where more than one user
can be logged on at the same time, maybe something like this:
#include <WtsApi32.h>
...
DWORD dwSessionId = WTSGetActiveConsoleSessionId();
if (0xFFFFFFFF != dwSessionId)
{
LPTSTR pUserNameStr = 0;
DWORD dwBytesReturned = 0;
if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, dwSessionId, WTSUserName, &pUserNameStr, &dwBytesReturned))
{
WTSFreeMemory(pUserNameStr);
}
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Go to: project, project property, C/C++, Code Generation, Struct Member Alignment: that gives an option to align all the struct elements on multiples of 1 or 2 or 4 or 8 or 16. Choose 1.
|
|
|
|
|
If you find that doesn't work for your whole project then you can set the alignment on individual types see here[^]. Setting global alignment to 1 may also cause performance issues, problems with calling certain APIs and the effects on COM are probably beyond my comprehension. Microsoft pretty universally assume that alignment will be 8 as that's the default for all MS Compilers since the dark ages so you may even have trouble calling stuff in the runtime with global 1 alignment.
Hey if software development was that easy everyone would be doing it
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Matthew Faithfull wrote: Hey if software development was that easy everyone would be doing it
Indeed everyone is doing it, don't you read the posts?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
CPallini wrote: don't you read the posts?
No I take a random stab at what the question might by reading every second word of the title and then post a reply consisting of artfully rearranged phrases from one of 16 stock replies written for me by a team of genuine Irish code pixies I met in bar in Edinburough. It really saves a lot of time and effort and people seem to like it.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
That must be one of the best of the stock
PS: My regards to such a lovely town.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
That being generally a bad idea aside, didn't someone mention
that here[^] yesterday?
Good luck!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello everyone,
Suppose I have some objects created on local function stack (not on heap). And I allocate and free all the related resources in the constructor and destructor (e.g. memory and file handles). And I do not implement explicit exception handling code in the function for resource free purpose, and simply rely on destructor to free resources if exception occurs, that is,
1. when exception occurs and the exception triggers us to go out of current function stack to the caller to find exception handlers;
2. since objects are allocated on local stack, when exception triggers us to go out of current stack to its caller to find exception handler, the lifecycle of local objects on local stack will expire, and its related destructor will be invoked and free resources.
Pseudo code like this,
void func()
{
Class1 inst1;
Class2 inst2;
...
return;
}
Does above code always safe? Are there any potential risks to leak resources?
thanks in advance,
George
|
|
|
|
|
Yes, that's as safe as you make Class1 and Class2 except in one instance, a stack overflow. In all other cases I know of, provided you have an exception handler somewhere up the stack then the Unwind function will be called in the runtime which uses a bit of compiler magic to ensure that the destructors for inst1 and inst2 are called. In the case of a stack overflow exception you're pretty much dead in the water. There is the _resetstkoflw() runtime function but it won't prevent anything allocated on the heap in your Class1 and Class2 constructors being leaked.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
In general, what the thread does is: Creating and sending an e-mail containing a file attachment using an Outlook or Lotus Notes client (if installed on the system).
Running the thread once always works fine, and it terminates correctly. However, when i try to run it for a second time, it throws an exception in MFC42.DLL, unfortunately not always at the same code line, but more or less randomly, esp. during manual debugging:
UINT CommonSendMailThread(LPVOID pParam)<br />
{<br />
<br />
if (sType == "%OUTLOOK%") {<br />
try { <br />
_DApplication OutlookHandle; <br />
<br />
if (!AfxOleInit())<br />
return 1;<br />
else {
if (OutlookHandle.CreateDispatch("Outlook.Application.8") == FALSE) {<br />
if (OutlookHandle.CreateDispatch("Outlook.Application.9") == FALSE) {<br />
if (OutlookHandle.CreateDispatch("Outlook.Application.10") == FALSE) {<br />
if (OutlookHandle.CreateDispatch("Outlook.Application.11") == FALSE) {<br />
if (OutlookHandle.CreateDispatch("Outlook.Application.12") == FALSE) {<br />
return 1;<br />
}}}}}}<br />
<br />
_DMailItem newMail;<br />
<br />
newMail = OutlookHandle.CreateItem(0);<br />
<br />
<br />
newMail.Send();<br />
<br />
OutlookHandle.ReleaseDispatch();<br />
}<br />
<br />
catch(...) {<br />
return 1;<br />
}<br />
}
<br />
else if (sType == "%NOTES%") {<br />
try {<br />
if (!AfxOleInit())<br />
return 1;<br />
<br />
NOTESSESSION *pNotesSes = NULL;<br />
NOTESDATABASE *pNotesDB = NULL;<br />
NOTESDOCUMENT *pNotesDoc = NULL;<br />
NOTESRICHTEXTITEM *pNotesRichTextItem = NULL;<br />
<br />
pNotesSes = new NOTESSESSION;<br />
<br />
if ( !pNotesSes )<br />
return 1;<br />
<br />
if ( pNotesSes == NULL )<br />
return 1;<br />
<br />
if (!pNotesSes -> CreateDispatch( "Notes.NotesSession" ))<br />
return 1;<br />
<br />
if ( pNotesSes -> m_lpDispatch == NULL ) { <br />
delete pNotesSes;<br />
return 1;<br />
}<br />
<br />
<br />
pNotesDoc ->SEND(0, COleVariant(sRecipientAddress));<br />
pNotesDoc ->REMOVE (0);<br />
<br />
pNotesRichTextItem ->ReleaseDispatch();<br />
pNotesDoc ->ReleaseDispatch();<br />
pNotesDB ->ReleaseDispatch();<br />
pNotesSes ->ReleaseDispatch();<br />
<br />
delete pNotesRichTextItem;<br />
delete pNotesDoc;<br />
delete pNotesDB;<br />
delete pNotesSes;<br />
}<br />
<br />
catch(...) {<br />
return 1;<br />
}<br />
}
else {<br />
return 1;<br />
}<br />
<br />
return 0;<br />
}
I'm totally confused and have no idea how to solve or even access the problem. Any hint or help is greatly appreciated!
|
|
|
|
|
Member 4760200 wrote: In general, what the thread does is: Creating and sending an e-mail containing a file attachment using an Outlook or Lotus Notes client (if installed on the system).
Running the thread once always works fine, and it terminates correctly. However, when i try to run it for a second time, it throws an exception in MFC42.DLL, unfortunately not always at the same code line, but more or less randomly, esp. during manual debugging:
I would look up the MFC implementation of the send mail command in CDocument, and adapt the code to my purposes, rather than sending it through Outlook or Lotus Notes. If I did need to do it that way, one of the first questions I'd ask is "What exception is being thrown?" Also, in general returning 1 is not adequate for handling unknown exceptions. Terminating the whole program is more reasonable. Finally, the random nature of the exception sounds like a race condition, and since it doesn't go away when you debug, I would guess that you are calling functions that are intended to be called from only one thread for the duration of the process. I'm sorry I can't be more helpful.
Nathan
|
|
|
|
|
Hi,
Isn't it possible to subclass a window in the explorer process, using CWnd::SubclassWindow() ?
My intention is to skin the systray clock.
What I did:
1. Created a MFC dll.
2. Injected it to the explorer process using "CreateRemoteThread - LoadLibrary" technique.
3. Took the window handle of systray clock in the dll's InitInstance.
4. Replaced the window proc using SetWindowLong.
These were successful, and in the replaced proc, I could do the custom draw by processing WM_PAINT.
The problem:
I derived a class from CWnd, say CMyClock. And subclassed the systray clock window with CMyClock object (member) instead of proc replacement. Now the explorer crashes.
I tried to debug the explorer process.
I found that subclassing is fine, and InitInstance completed successfully. After a very little time it crashed and the call stack was as follows...
ntdll.dll!7c901230()
> msvcr71d.dll!_CrtDbgBreak() Line 93 C
msvcr71d.dll!_CrtDbgReport(int nRptType=2, const char * szFile=0x01b44c68, int nLine=384, const char * szModule=0x00000000, const char * szFormat=0x00000000, ...) Line 427 C
mfc71d.dll!AfxAssertFailedLine(const char * lpszFileName=0x01b44c68, int nLine=384) Line 28 + 0x14 C++
mfc71d.dll!AfxWndProc(HWND__ * hWnd=0x000f01c8, unsigned int nMsg=15, unsigned int wParam=0, long lParam=0) Line 384 + 0x15 C++
MyClockDll.dll!AfxWndProcDllStatic(HWND__ * hWnd=0x000f01c8, unsigned int nMsg=15, unsigned int wParam=0, long lParam=0) Line 53 + 0x15 C++
user32.dll!7e418734()
user32.dll!7e418816()
user32.dll!7e41b4c0()
user32.dll!7e41b50c()
ntdll.dll!7c90eae3()
user32.dll!7e4194d2()
user32.dll!7e41b530()
user32.dll!7e42d950()
user32.dll!7e418a10()
user32.dll!7e42dbbf()
user32.dll!7e42593f()
user32.dll!7e43a91e()
What could be wrong? Any suggestions or ideas?
Thanks in advance.
|
|
|
|
|
Hello everyone,
Is the conclusion correct? Both const reference and non-const reference are lvalue?
I think it is true and I can not find a sample which does not follow it.
thanks in advance,
George
|
|
|
|
|
I suppose if you're returning a reference from a function then it's not an lvalue.
|
|
|
|
|
Thanks Budric,
Could you show a sample please?
regards,
George
|
|
|
|
|
hi to all
i want to get the number of lines shown in editbox.
thank u
|
|
|
|
|
|
Hello...guru's
I am writing a program in VC++ its database related application.
In this case i fetch data from Oracle database.using CRecordset class.
When i write below code
no_field = rs.GetODBCFieldCount();
while(!rs.IsEOF())
{
for(i=0;i<no_field;i++)
{
rs.GetFieldValue(i,sString);
if(i==0)
{
SetDlgItemText(IDC_EDIT_DATE1,sString);
}
if(i==1)
{
SetDlgItemText(IDC_EDIT_DATE2,sString);
}
if(i==2)
{
SetDlgItemText(IDC_EDIT_UPDT,sString);
}
}
sString.Empty();
rs.MoveNext();
}
Although above code is work fine.........
but i want to get rid of from if else condition.....This method is fine for fetching certain field from database .But if table contain 200 or more entity in a row then i need to write 200 or more if else condition...
Can any one give me berief idea how can i do this apart from this way.........
Thanks in Advanced
Regard's
Kaushik
|
|
|
|
|
Instead use of if you can use of switch.
Switch(i)
{
case 0:
break;
case 1:
break;
default:
break;
}
|
|
|
|
|
And how can he get rid of the 200 tests conditions by using a switch ?
|
|
|
|
|
Open the resource file and give adjacent Id's for your controls. This, way, you can simply do something like this:
SetDlgItemText(IDC_FIRST_CTRL_ID+i,sString);
|
|
|
|
|
Two things you could do here.
Use a switch statement
<br />
switch i<br />
{<br />
case 1:<br />
break;<br />
case 2:<br />
break;<br />
}<br />
but I wouldn't recommend that if you really have 200 fields and 200 controls on your dialog. If that's the case the easiest way is to ensure the values of your control id's are sequential and then do something like this
<br />
for(i=0;i<no_field;i++)<br />
{<br />
rs.GetFieldValue(i,sString);<br />
SetDlgItemText( BASE_FIELD_CONTROL_ID + i, sString);<br />
sString.Empty();<br />
rs.MoveNext();<br />
}<br />
you might want to use different ranges based on field/control types and use a switch to change the SetDlgItemText call.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Thanks for reply ....
I follow second method... give the control adjacent
like IDC_CONTROL , IDC_CONTROL+1, IDC_CONTROL+2, and so on...
and i am very near to solve problem...
Thanks again for reply to all's
Note : Is it possible for me to get control handle at run time.
Regard's
Kaushik
|
|
|
|
|
Hi all,
Actually i want to give my exe, version number, copyright information dynamically. Is it poosible to do so.....
|
|
|
|
|
How dynamic is "dynamically"?
Here, our build-server includes a small, generated file with a version resource in the main resources of the project.
That way, the version number is set automagically.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|