|
Hi,
thnx for quick help....I don't have its code and even ProcessID...how to get the process ID for any EXE??
thnx and regards
Bose Dayala.
ThomasKennedyBose
|
|
|
|
|
Task Manager is an example of a program that enumerates all running processes. It is implemented using data from the performance registry. The following sample code uses the EnumProcesses function to enumerate the current processes in the system. This method is easier than using the performance registry.
#include <windows.h>
#include <stdio.h>
#include "psapi.h"
void PrintProcessNameAndID( DWORD processID )
{
char szProcessName[MAX_PATH] = "unknown";
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process name.
if ( hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
}
}
// Print the process name and identifier.
printf( "%s (Process ID: %u)\n", szProcessName, processID );
CloseHandle( hProcess );
}
void main( )
{
// Get the list of process identifiers.
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Print the name and process identifier for each process.
for ( i = 0; i < cProcesses; i++ )
PrintProcessNameAndID( aProcesses[i] );
}
The main function obtains a list of processes by using the EnumProcesses function. For each process, main calls the PrintProcessNameAndID function, passing it the process identifier. PrintProcessNameAndID in turn calls the OpenProcess function to obtain the process handle. If OpenProcess fails, the output shows only the process identifier. For example, OpenProcess fails for the Idle and CSRSS processes because their access restrictions prevent user-level code from opening them. Next, PrintProcessNameAndID calls the EnumProcessModules function to obtain the module handles. Finally, PrintProcessNameAndID calls the GetModuleBaseName function to obtain the name of the executable file.
This may help u.
/jitendra
Jitendra Pal Singh Gangwar
E-mail: jitendra_gangwar@hotmail.com
Mobile No: 09831352305
|
|
|
|
|
Task Manager is an example of a program that enumerates all running processes. It is implemented using data from the performance registry. The following sample code uses the EnumProcesses function to enumerate the current processes in the system. This method is easier than using the performance registry.
#include <windows.h>
#include <stdio.h>
#include "psapi.h"
void PrintProcessNameAndID( DWORD processID )
{
char szProcessName[MAX_PATH] = "unknown";
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process name.
if ( hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
}
}
// Print the process name and identifier.
printf( "%s (Process ID: %u)\n", szProcessName, processID );
CloseHandle( hProcess );
}
void main( )
{
// Get the list of process identifiers.
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Print the name and process identifier for each process.
for ( i = 0; i < cProcesses; i++ )
PrintProcessNameAndID( aProcesses[i] );
}
The main function obtains a list of processes by using the EnumProcesses function. For each process, main calls the PrintProcessNameAndID function, passing it the process identifier. PrintProcessNameAndID in turn calls the OpenProcess function to obtain the process handle. If OpenProcess fails, the output shows only the process identifier. For example, OpenProcess fails for the Idle and CSRSS processes because their access restrictions prevent user-level code from opening them. Next, PrintProcessNameAndID calls the EnumProcessModules function to obtain the module handles. Finally, PrintProcessNameAndID calls the GetModuleBaseName function to obtain the name of the executable file.
This may help u.
/jitendra
|
|
|
|
|
I am doing a search for a particular directory (1).
If the directory is found then I am going to the last sub directory of 1.
Then I am listing all the files in these directory.
Pls kindly help me in this respect.
CFileFind l_fileFind;
//Find the root directory
bool l_bool = l_fileFind.FindFile(_T("D:\\Epson\\CPS"));
while(l_bool)
{
l_bool = l_fileFind.FindNextFile();
if (l_fileFind.IsDirectory())
{
//List all the files
}
}
|
|
|
|
|
Just do the whole thing again, a filefind in the new directory with \*.* at the end.
|
|
|
|
|
Anyone knows how to detect whether or not the current window is console window.
Thanx in advance...
|
|
|
|
|
HWND hwnd = ::GetForegroundWindow();
ASSERT(hwnd != NULL);
TCHAR szClass[256] = _T("");
::GetClassName(hwnd, szClass, 255);
if (_tcsicmp(szClass, _T("ConsoleWindowClass")) == 0)
{
}
else
{
}
I did not compile above code, but you should have got the main idea.
|
|
|
|
|
how do i automatically highlight a row in CListCtrl ?
(i have enabled full row select)
SetSelectionMark doesn't seem to work
|
|
|
|
|
Check out CListCtrl::SetItemState in MSDN.
|
|
|
|
|
I am really new to C++ and I dont have a clue what Im doing yet. I keep reciving the following compiler error
c:\Documents and Settings\Owner\My Documents\Visual Studio Projects\Windows Forms\Form1.h(144): error C2065: 'hInstance' : undeclared identifier The code itself is listed below. If anyone can help me I would apprecaite it very much
<code>
#pragma once
HWND hw;
MSG msg;
int status;
namespace WindowsForms
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::Button * button1;
private: System::Windows::Forms::Button * button3;
private: System::Windows::Forms::Button * button4;
private: System::Windows::Forms::TextBox * textBox1;
private:
System::ComponentModel::Container * components;
void InitializeComponent(void)
{
this->button1 = new System::Windows::Forms::Button();
this->button3 = new System::Windows::Forms::Button();
this->button4 = new System::Windows::Forms::Button();
this->textBox1 = new System::Windows::Forms::TextBox();
this->SuspendLayout();
this->button1->Cursor = System::Windows::Forms::Cursors::Hand;
this->button1->ForeColor = System::Drawing::Color::Black;
this->button1->ImageAlign =
System::Drawing::ContentAlignment::TopCenter;
this->button1->Location = System::Drawing::Point(1, 0);
this->button1->Name = S"button1";
this->button1->Size = System::Drawing::Size(208, 38);
this->button1->TabIndex = 0;
this->button1->Text = S"Set Desktop Wallpaper";
this->button1->Click += new System::EventHandler(this, button1_Click);
this->button3->Cursor = System::Windows::Forms::Cursors::Hand;
this->button3->ForeColor = System::Drawing::Color::Black;
this->button3->Location = System::Drawing::Point(1, 38);
this->button3->Name = S"button3";
this->button3->Size = System::Drawing::Size(208, 38);
this->button3->TabIndex = 3;
this->button3->Text = S"Grand Finale";
this->button3->Click += new System::EventHandler(this,
button3_Click_1);
this->button4->ForeColor = System::Drawing::Color::Black;
this->button4->ImageAlign =
System::Drawing::ContentAlignment::BottomCenter;
this->button4->Location = System::Drawing::Point(1, 76);
this->button4->Name = S"button4";
this->button4->Size = System::Drawing::Size(208, 38);
this->button4->TabIndex = 4;
this->button4->Text = S"Exit";
this->button4->Click += new System::EventHandler(this, button4_Click);
this->textBox1->ForeColor = System::Drawing::SystemColors::HotTrack;
this->textBox1->Location = System::Drawing::Point(1, 112);
this->textBox1->Name = S"textBox1";
this->textBox1->ReadOnly = true;
this->textBox1->Size = System::Drawing::Size(208, 20);
this->textBox1->TabIndex = 5;
this->textBox1->Text = S"";
this->textBox1->TextAlign =
System::Windows::Forms::HorizontalAlignment::Center;
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(210, 136);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->button4);
this->Controls->Add(this->button3);
this->Controls->Add(this->button1);
this->Cursor = System::Windows::Forms::Cursors::No;
this->FormBorderStyle =
System::Windows::Forms::FormBorderStyle::FixedToolWindow;
this->Name = S"Form1";
this->Text = S"A Little Something Just For You";
this->TransparencyKey = System::Drawing::Color::Crimson;
this->Load += new System::EventHandler(this, Form1_Load);
this->ResumeLayout(false);
}
private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{
}
private: System::Void button4_Click(System::Object * sender, System::EventArgs * e)
{
textBox1->Text = S"Your not getting away that easy";
}
private: System::Void button3_Click(System::Object * sender, System::EventArgs * e)
{
BOOL CALLBACK DialogProc (HWND hWnd, UINT uMsg, WPARAM
wParam, LPARAM
lParam);
hw = CreateDialog( hInstance , MAKEINTRESOURCE ( 102 ) ,NULL,
reinterpret_cast<DLGPROC>(DialogProc ));
}
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)"wallpaper.bmp", SPIF_UPDATEINIFILE |
SPIF_SENDWININICHANGE);
}
private: System::Void button3_Click_1(System::Object * sender, System::EventArgs * e)
{
}
};
}
#include <WinUser.h>
#include "stdafx.h"
#include <windows.h>
#include <stdlib.h>
#include "Form1.h"
using namespace WindowsForms;
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(new Form1());
return 0;
}
</code>
Thanks for any and all help
Draco
|
|
|
|
|
Draco0283 wrote:
#include "Form1.h" // <--- You use hInstance at here in this file.
using namespace WindowsForms;
int APIENTRY _tWinMain(HINSTANCE hInstance, // But hInstance actually is known by the compiler at this line...
HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){ /* */ }
Maxwell Chen
|
|
|
|
|
Ok in reference to Maxwell Chen I tried several things. I moved the #include "form.h" statement and I tried to move where it calls hInstance. Everything I did brought up more problems than before. Where should it go? Thanks for your help
Draco
|
|
|
|
|
in form1.h you define in the class Form 1 the button3_Click method
System::Void button3_Click(System::Object * sender, System::EventArgs * e) {
BOOL CALLBACK DialogProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
hw = CreateDialog( hInstance , MAKEINTRESOURCE ( 102 ) ,NULL,reinterpret_cast(DialogProc ));
}
This has the parameter sender and e.
Because no parameter hInstance is given as parameter into the method and also there is no class parameter with the name hInstance the parameter hInstance cannot be known to the compiler. Where shall it come from?
In traditional Win32 SDK development this is given to the main function by windows when the application is started and normally will be kept as global variable in the ugly Win32 SDK style. Here you are in the object oriented world of .NET. Possible there are some method in the Form class allowing access to the application object, where one would typically search for the Win32 style instance handle. (I dont know where exactly). It should also work for this case to set NULL instead of the concrete hInstance value of the application.
|
|
|
|
|
Can you give me a suggestion on how to make a amplitude demodulation programming used Visual C++?
Thank you very much!
langzi54
|
|
|
|
|
We're going to need a lot more information to give you a meaningful answer. AM demodulation is trivial - take the absolute value of the sample, or square it and use the positive square root. But what you're trying to accomplish is not at all clear. If you're trying to sample an AM signal directly with a PC, forget it - a PC isn't equipped with anything capable of digitizing and analog signal. If you're dealing with an array or file of sampled, digitized values, there are lots of ways to deal with it. More details about what you are trying to do will result in a far better answer...
Some people think of it as a six-pack; I consider it more of a support group.
|
|
|
|
|
...and it depends the way the samples have been coded (see the codecs)...
|
|
|
|
|
No, it doesn't. Codec operations are performed on baseband signals, before and after modulation/demodulation.
Some people think of it as a six-pack; I consider it more of a support group.
|
|
|
|
|
Hi,
I got a problem in my programmming project.
I need to develop an agent program that connect between server and client.
The matter is I need to develop it in Win 3.1 and MSVC++ 1.52.
So, I chagned some api functions and I could connect sockets between win 2000 server and win 3.1 client.
However, whenever I try to run some functions after accepting socket and checking the IP, agent program makes "Stack Overflow" error.
But no variable initiation is exeist after that.
So, I wanna use Handle for sockets as I did in Win 2000.
Is this the right way?
If so,
Could you please let me know the api function that close handle like CloseHandle in MSVC++ 6.0?
Thanks in advance.
|
|
|
|
|
Why not try to install platform SDK? Probably it could solve the API not exist problem.
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
Life is about reading
This person is trying to use Win3.x, not a Win32 version, so Platform SDK won't help...
Steve S
|
|
|
|
|
When developing socket programs under Win16 the WinSock API (Version 1.1) must be used. (See http://www.sockets.com/winsock.htm[^]).
In short...
You create a socket with the socket() function.
You connect a client socket with the connect(..) function.
You read data from a socket with the recv() function (or if asychron what it a must under Win16 via WSAAsyncSelect and windows messaging on FD_READ)
You close a connected socket with the closesocket() function.
For using this function you must include the winsock.h header. (In the latest MSVC 1.52c version this is included).
A very good book for WinSock Programming under Win16 is named book on the website of the above link: Bob Quinn "Windows Sockets Network Programming"
A pendant for CloseHandle() in Win32 is not known under Win16.
Here you have to handle all socket specific functions with the WinSock API.
|
|
|
|
|
Is it possible for you to post a snippet of code where you get the Stack Overflow?
I don't envy you still developing 16-bit on 1.52. I am glad I no longer need to use this compiler!;)
Ant.
|
|
|
|
|
Please tell me...
How to start another application in my application..
In my application I need to call another application to open. And I am not use the MFC.
Can someone tell me how to open another application.
Thanks..
|
|
|
|
|
ShellExecute would do the trick!
ShellExecute(handle, "open","calc.exe", NULL, NULL,SW_SHOWNORMAL);
/Jarek
As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality.
Albert Einstein
|
|
|
|
|
Also check out CreateProcess() .
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|