Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
this code it lists all processes and all threads of the process, but I want it lists only the thread of a process by pid ... example: explorer.exe pid = 5454 through the pid wanted him to have the ids of threads and thread state.
How about passing the process ID as a command line argument to the program and filter out the content required.
while( pi )
{
SYSTEM_PROCESS_INFORMATION* next = PROCESS_INFORMATION_NEXT( pi );
UINT32 count, n;
if (argc > 1 && pi->UniqueProcessId == (HANDLE)atoi(argv[1])) {
printf("**************************************\n");
if( pi->ImageName.Buffer )
wprintf(L"%u %s <------ PROCESSO\r\n", pi->UniqueProcessId, pi->ImageName.Buffer);
else
wprintf(L"%u %s *\r\n", pi->UniqueProcessId, L"System Idle Process");
if( next )
count = ThreadCount( pi, (ULONG_PTR)next );
else
count = ThreadCount( pi, (ULONG_PTR)spi + size );
for( n=0; n<count; n++ )
{
SYSTEM_THREAD_INFORMATION* th = pi->Threads + n;
wprintf(L" [%u] StartAddress=%p ID Processo=%u IdThred=%u State=%u \r\n",
n+1, th->StartAddress, th->ClientId.UniqueProcess, th->ClientId.UniqueThread,th->WaitReason);
}
}
pi = next;
}
you can see this on msdn
i think this is what you are looking for.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
public async Task < IActionResult > Events(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest httpRequest,
ILogger log) {
ValidateResponse res = eventService.ValidateSchema();
if (res.Valid == false && res.Errors != null) {
string[] messages = new string[100];
int k = 0;
for (int i = 0; i < res.Errors.Count; i++) {
string value = res.Errors[i].ToString();
if (value.StartsWith("Invalid type")) {
messages[k++] = value.Substring(10);
continue;
}
}
return new OkObjectResult($ "No of events posted {cloudEvents.Count} and errors :{messages[k]}");
}
But the values in messages are not returned. I understand that its an array . But unable to figure out the ways to loop here in return all array values once.
Once option is to join the messages array to a string:
return new OkObjectResult($"No of events posted {cloudEvents.Count} and errors:{String.join(\",\", messages}");
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am coding for an arduino project and i came across this problem, can anyone help me out!
if(condition1){
//my codes here
}
if(condition2){
//my codes here
}
if(condition3){
//my codes here
}
......
if(condition100){
//my codes here
}
else{
my codes here
}
I want to check all my if conditions, and execute the codes if the conditions are true, and run the else statement only if none of the if condition become true.
Note that i cant use else if because i want to check all the if conditions, and if none are true i want to run the else
If conditions are not dependent on each other
You can use a Boolean flag which is set in any of your ifs.
bool noPathTaken = true;
if ( condition1 ) {
noPathTaken = false;
// ...
}
if ( condition2 ) {
noPathTaken = false;
// ...
}
// ...
if ( noPathTaken ) { // this would be your "else"
// ...
}
must set off all else flag in each test
bool elseFlag = 1;
if(condition1){
elseFlag = 0;
my codes here
}
if(condition2){
elseFlag = 0;
my codes here
}
if(condition3){
elseFlag = 0;
my codes here
}
......
if(condition100){
elseFlag = 0;
my codes here
}
if (elseFlag) {
my codes here
}
because else gets binded only into preceding test operation, here if(condition100) {
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I want to generate and handle exceptions (SEH).
How can I write a code that will lead to an "illegal instruction"-exception?
You can do something like this:
#include <Windows.h>
#include <cstdio>
::DWORD FilterFunction(::DWORD const _exception_code)
{
if(EXCEPTION_ILLEGAL_INSTRUCTION == _exception_code)
{
::std::printf("filtered\n");
return EXCEPTION_EXECUTE_HANDLER;
}
else
{
::std::printf("not filtered\n");
return EXCEPTION_CONTINUE_SEARCH;
}
}
int main()
{
__try
{
::std::printf("trying...\n");
::RaiseException
(
EXCEPTION_ILLEGAL_INSTRUCTION // exception id
, 0 // continuable exception
, 0 // args count
, nullptr // args
); // no arguments
::std::printf("finished trying\n");
}
__except(FilterFunction(GetExceptionCode()))
{
::std::printf("exception handled\n");
}
return 0;
}
trying...
filtered
exception handled
You can raise a structured exception in Windows with:
RaiseException(EXCEPTION_ILLEGAL_INSTRUCTION, EXCEPTION_NONCONTINUABLE, 0, nullptr);
Reference:
https://msdn.microsoft.com/en-us/library/ms680552%28VS.85%29.aspx
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
can someone explain me on what does these codes did? this is only part of the code...
// Create the window of the application
sf::RenderWindow myWindow(sf::VideoMode(myWorldWidth, myWorldHeight, 32), "Battleship!");
myWindow.setVerticalSyncEnabled(true);
bool showHardwareMouse;
bool started;
bool drag;
float dragOffsetX, dragOffsetY;
bool LeftMouseButtonDown = false;
bool reset = true;
//----- Main Loop Start here -----
while (myWindow.isOpen())
{
if (reset)
{
// Reset
showHardwareMouse = true;
drag = false;
dragOffsetX = dragOffsetY = 0.0f;
started = true;
reset = false;
}
the program is actually based on SFML library, what does dragOffsetX = dragOffsetY = 0.0f; means?
and this is how actually the program work like...
http://i1146.photobucket.com/albums/o530/HTHVampire/C%20plus%20plus/Capture2_zps1fe188cd.jpg
I will post the full codes of it if you guys can't get it. Thanks!
dragOffsetX = dragOffsetY = 0.0f;
is the same as
dragOffsetX = (dragOffsetY = 0.0f);
where an assignment a = b has the "value" b. So the above line is the same as:
dragOffsetX = 0.0f;
dragOffsetY = 0.0f;
The rest of the code consists mainly of declarations and initializations and should be obvious.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to open an explorer window showing a specific folder, lets say "C:\\Windows" What function should I use to reach my goal? I'm using Windows so can use API, also I can use boost, but I can't use C++11.
You can use the SHOpenFolderAndSelectItems function to do this, rather than forcibly running Explorer yourself (what if the user has replaced Explorer as their default file manager, for example?).
LPCWSTR pszPathToOpen = L"C:\\Windows";
PIDLIST_ABSOLUTE pidl;
if (SUCCEEDED(SHParseDisplayName(pszPathToOpen, 0, &pidl, 0, 0)))
{
// we don't want to actually select anything in the folder, so we pass an empty
// PIDL in the array. if you want to select one or more items in the opened
// folder you'd need to build the PIDL array appropriately
ITEMIDLIST idNull = { 0 };
LPCITEMIDLIST pidlNull[1] = { &idNull };
SHOpenFolderAndSelectItems(pidl, 1, pidlNull, 0);
ILFree(pidl);
}
Alternatively, you can call ShellExecute on the folder directly to run its default action (which is normally to open in a browser window):
ShellExecute(NULL, NULL, L"C:\\Windows", NULL, NULL, SW_SHOWNORMAL);
An hour ago I just wrote similar function.
This function doesn't do 100% as you want, but you can use it to get that you want.
It opens explorer window and marks file you are pointing to. Lets say you specified "C:\Windows\System32" in this case you will have "C:\Windows" opened and System32 marked. If you want to go inside you need to use something like FindFirstFile. If directory is empty, my offered solution wouldn't work...
bool ExplorerGoTo (const String &Path)
{
TCHAR tcBuff[8] = {0};
lstrcpyn(tcBuff, Path.c_str(), 5);
String stParams = _T("/n, /select, ");
if( lstrcmpi(_T("\\??\\"), tcBuff) == 0 )
{
stParams += (Path[4]);
}
else
{
stParams += Path;
}
String stExplorer = _T("C:\\Windows\\explorer.exe");
//ExpandPath(stExplorer);
if (stExplorer.empty ()) stExplorer = _T("explorer.exe");
SHELLEXECUTEINFO shi = { 0 };
shi.cbSize = sizeof (SHELLEXECUTEINFO);
shi.lpVerb = _T("open");
shi.lpFile = stExplorer.c_str ();
shi.lpParameters = stParams.c_str ();
shi.nShow = SW_SHOW;
bool bRes = ShellExecuteEx( &shi );
if( bRes == FALSE && GetLastError() != 0 )
{
Sleep(200);
return ShellExecuteEx( &shi );
}
return bRes;
}
And never use system()