|
You could also use a timer catching the WM_TIMER message. To make the trade terminate, send it the WM_QUIT message, which it will also catch.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
|
The suggestion is NOT to use Sleep, because it is blocking, so you are unable to tell the thread to cleanup and quit.
The use of either WaitForSingleObject with a 1800000 milliseconds time-out or SetTimer and catching the WM_TIMER and WM_QUIT messages is better.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
A console application in debug mode, using STL:
#include "stdafx.h"
#include <iostream.h>
#include <vector>
using namespace std;
typedef vector<int> intvector;
struct S
{
intvector v;
};
int main(int argc, char* argv[])
{
S *pS=new S;
intvector::iterator it;
cout<<"before crush"<<endl; <code>
for (it=pS->v.begin(); it!=pS->v.
end(); it++);
delete pS;
return 0;
}
If i run it step by step it will crush on the attempt of executing the for line. If i modify it like this:
for (it=pS->v.begin(); it!=pS->v.end(); it++); and repeat the step by step procedure, everything will be ok.
Could you tell me what is the difference between the two variants?
This message is related to the one i wrote yesterday. I thank everyone who sent me answers. I still think it was not about memory...
rechi
|
|
|
|
|
Hmmm... Don't know if it helps, but I think this is a compiler bug.
1. In VS.NET I compile it and run it fine
2. In VC++ 6.0 the whole MSDEV crashes and exit! I never saw this!
3. I've changed your code to this, for spotting the error:
int main(int argc, char* argv[])
{
S *pS=new S;
intvector::iterator it = pS->v.begin();
cout<<"before crush"<<endl;
while (it!=pS->v.end())
it++;
delete pS;
return 0;
}
And it works fine, even on VC 6.0!
I'm using SP5 of VS 6.0.
My latest articles:
XOR tricks for RAID data protection
Win32 process suspend/resume tool
|
|
|
|
|
Daniel Turini wrote:
I think this is a compiler bug
That's the point (on VC 6.0). Unfortunately, it took me a day to find out.
Thanx for your suggestions!
rechi
|
|
|
|
|
I've been wrestling with this one for four days now. Time to ask the experts...
I'm trying to run an application as Administrator... My app is supposed to have the functionality of Linux' SU...
Im trying to do this with CreateProcessAsUser, which spits out error 1314, meaning something like "missing client privilige."
I believe those privileges refer to those of the calling process, whose lacking SE_ASSIGNPRIMARYTOKEN_NAME privilege. When I try to assign that one, using a method that uses AdjustTokenPrivileges, that one spits out error 1300, "haven't assigned your privilege". Errors 1300 and 1314 are the only errors spit out.Some other notes: The assure method is a debug routine, it does not interfere anywhere... That's not really my admin password, mine is trice as long and quadruple complex Besides SetPrivilege and CreateProcessAsUser no functions called return an error...
What's going wrong? What should I change? Comments, suggestions, questions and URL's are welcome... BTW, I've got working SU code using the largely undocumented CreateProcessWithLogon fucntion, but this one doesn't work in NT 4.0, which is where this code should work...
The code:
<br />
STARTUPINFO *si = (STARTUPINFO *)allocm(sizeof(STARTUPINFO));<br />
PROCESS_INFORMATION *pi = (PROCESS_INFORMATION *)allocm(sizeof(PROCESS_INFORMATION));<br />
si->cb = sizeof(STARTUPINFO);<br />
<br />
LogonUser(<br />
"Administrator", <br />
".",<br />
"09nnj!ty&56t",<br />
LOGON32_LOGON_INTERACTIVE,<br />
LOGON32_PROVIDER_DEFAULT,<br />
&hToken <br />
);<br />
assure("LogonUser");<br />
<br />
OpenProcessToken(GetCurrentProcess(),TOKEN_ALL_ACCESS,&hToken2);<br />
assure("OpenProcessToken");<br />
<br />
DuplicateTokenEx(<br />
hToken,<br />
TOKEN_ALL_ACCESS,<br />
NULL,<br />
SecurityImpersonation,<br />
TokenPrimary,<br />
&hToken3<br />
);<br />
assure("DuplicateToken");<br />
<br />
ImpersonateLoggedOnUser(hToken3);<br />
assure("ImpersonateLoggedOnUser");<br />
<br />
SetPrivilege(hToken2,SE_INCREASE_QUOTA_NAME,true);<br />
assure(SE_INCREASE_QUOTA_NAME);<br />
<br />
SetPrivilege(hToken2,SE_ASSIGNPRIMARYTOKEN_NAME,true);<br />
assure(SE_ASSIGNPRIMARYTOKEN_NAME);<br />
<br />
CreateProcessAsUser(<br />
hToken3,<br />
NULL,<br />
"Taskmgr",<br />
NULL,<br />
NULL,<br />
0,<br />
CREATE_DEFAULT_ERROR_MODE |<br />
NORMAL_PRIORITY_CLASS,<br />
NULL,<br />
NULL,<br />
si,<br />
pi<br />
);<br />
assure("CreateProcessAsUser");<br />
Regards,
Georg Haan (.NL)
|
|
|
|
|
|
Thanks for your comment, but there must be a way to use impersonation functions without upgrading to a (local) service? ImpersonateLoggedOnUser works fine by the way, and the RCMD example Mr. Saurwein refers (see next message) to doesn't upgrade itself to service neiter...
Regards,
Georg Haan(.NL)
|
|
|
|
|
The RCMD sample from the SDK shows how to do it:
if(!OpenThreadToken(
GetCurrentThread(),
TOKEN_DUPLICATE,
TRUE,
&hImpersonationToken
))
{
DisplayLastError("OpenThreadToken");
goto cleanup;
}
if(!DuplicateTokenEx(
hImpersonationToken,
TOKEN_IMPERSONATE | TOKEN_READ |
TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE,
NULL,
SecurityImpersonation,
TokenPrimary,
&hPrimaryToken
))
{
DisplayLastError("DuplicateTokenEx");
goto cleanup;
}
RevertToSelf();
CloseHandle(hImpersonationToken);
if(!CreateProcessAsUser(
hPrimaryToken,
NULL,
COMMANDLINE,
NULL,
NULL,
TRUE,
0,
NULL,
NULL,
&si,
&pi
))
{
DisplayLastError("CreateProcessAsUser");
goto cleanup;
}
Take a look at the flags passed to DuplicateTokenEx() and OpenThreadToken();
...if you're under 8 or younger. Chris Maunder, the Lounge
|
|
|
|
|
Again, thanks for your comment too.
I have tried the server.c you refer to already, it gives errors opening the threadtoken. A peculiar error that is, it says, "The specified token doesn't exist".
The general problem can't be due to flags, because the ALL_ACCESS flag used, symbolizes complete access including all possible flags. I use it to be sure I don't miss one...
Regards,
Georg Haan(.NL)
|
|
|
|
|
Georg Haan wrote:
I have tried the server.c you refer to already, it gives errors opening the threadtoken. A peculiar error that is, it says, "The specified token doesn't exist".
Which is pretty strange as the current threads token just HAS to exist.
Georg Haan wrote:
The general problem can't be due to flags, because the ALL_ACCESS flag used, symbolizes complete access including all possible flags. I use it to be sure I don't miss one...
Exactly this may be a reason for failures. Sometimes functions may fails because you are requesting more than you are privileged to do.
Always follow the principle of the least privileges. Never ask more than you need. If you open a file for reading for which you have only read privileges, requesting all access, the function will fail although you really would have access to read it. But, greedy as you are, you are asking for more.
...if you're under 8 or younger. Chris Maunder, the Lounge
|
|
|
|
|
Again, thanks for your quick response...
Andreas Saurwein wrote:
Which is pretty strange as the current threads token just HAS to exist.
Peculiar is another way of saying pretty strange...
The peculiarity of the error is why I posted my message on CodeProject...
Andreas Saurwein wrote:
Exactly this may be a reason for failures. Sometimes functions may fails because you are requesting more than you are privileged to do.
You are right. But the functions in which I request ALL_ACCESS do not generate an error, therefore I must be being granted full access... The trouble starts when some functions (CreateProcessAsUser, AdjustTokenPrivileges) imply I have too little access...
Andreas Saurwein wrote:
But, greedy as you are, you are asking for more.
A friendly word of advice: Don't be too quick on judgements like that, nor too generous with such statements...
Regards,
Georg Haan(.NL)
|
|
|
|
|
Georg Haan wrote:
A friendly word of advice: Don't be too quick on judgements like that, nor too generous with such statements...
Sorry, I didnt mean this as insult but rather jokingly on the ALL_ACCESS thing.
...if you're under 8 or younger. Chris Maunder, the Lounge
|
|
|
|
|
Hi,
I ve read into an article (Q186120) of microsoft knowledge base, which explain how to fill a range with an array. But when i test it , it doesn't work really well. In fact, i don't realy understand how works the function called in the sample GetResize(), because when i test my application (which is based on the application described in the article, but which can't fill cells with string element)which simply have to fill some excel's range with the figure "1", and when i run my application it just fill the cell "A1"!
Why?
Thanks in advance for your answer
gerald
|
|
|
|
|
The sample detailed in Q186120 works perfectly well. I have just tested it with Excel 97.
She's so dirty, she threw a boomerang and it wouldn't even come back.
|
|
|
|
|
Hi,
... I have my ATL ActiveX control, when I want to edit the properties of that ActiveX in Ms Word, I have to go to properties, and then press "custom" to have my properties dialog.
... But... What I have seen is that a control like "Calendar Control", adds properties to the Ms Word properties grid... how did they do that ???, how can I do that ?...
Thanks in advance, greetings
Braulio
|
|
|
|
|
hi
how can i fetch the harddisk serial number not harddisk volume serial number using MFC, WIN32API,C,C++ program. And where it is stored in the system. any professionals know please help me
thank you
from
venu
|
|
|
|
|
I have this:
CString csRoot( "C:\\" );
DWORD max = _MAX_PATH;
DWORD maxLen = 0;
DWORD fileFlags;
DWORD serialNo;
char szName[ _MAX_PATH ];
char szSerialNo[ _MAX_PATH ];
char szFileSystem[ _MAX_PATH ];
::GetVolumeInformation( 0, // root directory
szName, // volume name buffer
_MAX_PATH, // length of name buffer
&serialNo, // volume serial number
&maxLen, // maximum file name length
&fileFlags, // file system options
szFileSystem, // file system name buffer
max // length of file system name buffer
);
|
|
|
|
|
Probably you should try exploring Windows Management Instrumentation.
I've seen lot of stuff related to hardware over there...
Cheers
Kannan
|
|
|
|
|
|
warning C4312: 'reinterpret_cast' : conversion from 'DWORD' to 'CMyClass *' of greater size
CMyClass* pMyClass = reinterpret_cast<CMyClass*>(arg);
arg is a DWORD
A DWORD is 32 bits. A pointer is 32 bits. So what the heck is the compiler telling me???
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Didnt you recognize that you have now a 64bit machine on your table? So the pointers are now 64bit instead of 32bit.
...if you're under 8 or younger. Chris Maunder, the Lounge
|
|
|
|
|
|
Hi everybody,
I would like to export data from a safearray to range in excel. So, ii've read the articles Q186120 which gives an explantion and an example to do it. I've tried to test it in my application, first i ve done simply in trying to put in a specific set of range the figure "1". But when i test it it doesn't work the only first cell ("A1") is filled by "1", WHY??? So, you could find the code i've wrote, so, if someone could help me!
Thanks in advance
.
.
.
.
_Application FracApp;
_Workbook FracBook;
_Worksheet FracSheet;
Workbooks FracBooks;
Worksheets FracSheets;
Range FracRange;
LPDISPATCH lpDisp;
COleVariant Optional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
COleSafeArray FracArray;
DWORD NumOfElements[2];
int NumberOfRows,NumberOfCols; //pour le "SAFEARRAY"
long FracIndex[2];
long lRow,lCol;
double Temporary;
if(!FracApp.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Pb avec CreateDispatch sur Excel");
return;
}
lpDisp=FracApp.GetWorkbooks();
ASSERT(lpDisp);
FracBooks.AttachDispatch(lpDisp);
lpDisp=FracBooks.Open("D:\\FractaLab\\Fractal_v1_0\\Test.xls",Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional);
ASSERT(lpDisp);
FracBook.AttachDispatch(lpDisp);
lpDisp=FracBook.GetWorksheets();
ASSERT(lpDisp);
FracSheets.AttachDispatch(lpDisp);
lpDisp=FracSheets.GetItem(COleVariant((short)1));
ASSERT(lpDisp);
FracSheet.AttachDispatch(lpDisp);
lpDisp=FracSheet.GetRange(COleVariant("A1"),COleVariant("A1"));
ASSERT(lpDisp);
FracRange.AttachDispatch(lpDisp);
NumberOfRows=m_dlgNumHisto+1-m_dlgNumSample;
NumberOfCols=256;
FracRange.GetResize(COleVariant((short)(NumberOfRows)),COleVariant((short)(NumberOfCols)));
FracApp.SetVisible(TRUE);
FracRange.Clear();
//Création du tab de type SAFEARRAY.
NumOfElements[0]=NumberOfRows; NumOfElements[1]=NumberOfCols;
FracArray.Create(VT_R8,2,NumOfElements);
//Remplissage du SAFEARRAY
for(lCol=0;lCol
|
|
|
|
|