|
Hi toxcct,
I agree and understand your analysis. For the below comments from you,
toxcct wrote: when you insert of delete elements in the middle of the container
It should be "when you insert or delete elements in the middle of the container"? A typo?
regards,
George
|
|
|
|
|
George_George wrote: It should be "when you insert or delete elements in the middle of the container"? A typo?
yes
|
|
|
|
|
Thanks toxcct,
Question answered.
regards,
George
|
|
|
|
|
There goes an easy one:
How do I truncate a double number (I've been looking about but haven't find a way) but leaving some decimal digits. For example:
double x = 345.2214455; to x = 345.2214;
Thanks a lot
|
|
|
|
|
For which purpose do you want to truncate it ? Do you want to convert it to a string and display it somewhere ? If that's the case, you can use sprintf and specify the precision:
double x = 345.2214455;<br />
char szBuffer[255];<br />
sprintf(szBuffer,"%.4f",x);
|
|
|
|
|
I want to compare to numbers, for example:
2.0024334 and 2.0024992 should be seen as equal because the first 4 decimals are the same.
And I want to be able to select the number of decimals that are taken into account
|
|
|
|
|
piul wrote: 2.0024334 and 2.0024992 should be seen as equal because the first 4 decimals are the same.
Then the best way is
double x = 2.0024334;
double y = 2.0024992;
const double EPS = .0001;
if ( fabs(x-y) < EPS )
{
}
else
{
}
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
double x = 345.2214455;
x = floor(x * 10000)/10000;
or
double x = 345.2214455;
x = ((int)( x * 10000)) / 10000.0;
Please note:
(1) Care should be taken with negative values.
(2) The truncation is not exact (due to double numbers nature)
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
|
That don't work for you, see http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=2452741[^].
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
The easiest way is certainly doing something like
double x = 345.2214455;
long tmp = static_cast<long>(x*10000);
x = tmp/10000.0;
|
|
|
|
|
Hello friends.
The exe of my project works well in Debug mode and has some problem in
Release mode and it shows the messagebox to tell the microsoft about this
problem with send and don't send buttons.
Could you tell me the problems that could be arrived if I want to distribute the debug version of my application what care should be taken?
ritz1234
|
|
|
|
|
ritz1234 wrote: Could you tell me the problems that could be arrived if I want to distribute the debug version of my application what care should be taken?
Legally you can't distribute a debug version of your program. Anyway, if the release version crashes, it means that something is wrong and that your code is not totally stable. You should try to fix that instead.
Here is a great link about surviving the release version.[^]
|
|
|
|
|
Don't distribute the Debug version, fix the Release one, it shouldn't be so difficult.
See [^] and [^].
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
See Here[^]
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
In my project (i am using visual studio 2005 ) i need to simulate the task manager model. i can able to extract all the informations using
CreateToolhelp32Snapshot .But i was unable to identify the username assoicated with the processes .Is any APIs are there for it? or any other way to achieve this ?
vineesh
|
|
|
|
|
May be the following useful,
PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
PSID psidOwner = NULL;
TCHAR lpName[256];
TCHAR lpReferencedDomainName[256];
SID_NAME_USE eUse;
if (ERROR_SUCCESS == GetSecurityInfo(
GetCurrentProcess(),
SE_KERNEL_OBJECT,
OWNER_SECURITY_INFORMATION,
&psidOwner,
NULL,
NULL,
NULL,
&pSecurityDescriptor
))
{
DWORD cchName = 256;
DWORD cchReferencedDomainName = 256;
if (LookupAccountSid(
NULL,
psidOwner,
lpName,
&cchName,
lpReferencedDomainName,
&cchReferencedDomainName,
&eUse
))
{
CString Msg;
Msg.Append(_T("User Name : "));
Msg.Append(lpName);
Msg.Append(_T(" Domain Name : "));
Msg.Append(lpReferencedDomainName);
MessageBox(Msg);
}
LocalFree(pSecurityDescriptor);
}
|
|
|
|
|
Thanks rajakumar ,
But the above gives me the username associated with the current process . My program should capture all the process ,their process id and the user name associated with them . Can you suggest any thing of the sort ?..
vineesh
|
|
|
|
|
Your question was to get the username associated with a process,
GetSecurityInfo(
GetCurrentProcess(),// HANDLE handle,
what is restricting you to change the process handle used here. Does the code snippet i given is readonly?
vineeshV wrote: My program should capture all the process ,their process id and the user name associated with them .
if you have handle to process (as you said in your original post), getting process id (DWORD GetProcessId(HANDLE Process)), getting user name as above.
if you are not having handles to all process, use EnumProcesses() API.
|
|
|
|
|
Here is my code snippets ... it will works for the process having the username and domain attached to them having the same value for the user from the exe is called ...
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
#include <stdio.h>
#include <Aclapi.h>
// Forward declarations:
BOOL GetProcessList();
BOOL ListProcessModules( DWORD dwPID );
BOOL ListProcessThreads( DWORD dwOwnerPID );
void printError( TCHAR* msg );
void getuserProcess(HANDLE);
char filename[250];
DWORD pid = 0;
int isAlive = 0;
void main( )
{
GetProcessList();
getchar();
}
BOOL GetProcessList()
{
HANDLE hProcessSnap;
HANDLE hProcess;
PROCESSENTRY32 pe32;
DWORD dwPriorityClass;
HANDLE userhp;
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
printError( TEXT("CreateToolhelp32Snapshot (of processes)") );
return( FALSE );
}
// Set the size of the structure before using it.
pe32.dwSize = sizeof( PROCESSENTRY32 );
// Retrieve information about the first process,
// and exit if unsuccessful
if( !Process32First( hProcessSnap, &pe32 ) )
{
printError( TEXT("Process32First") ); // show cause of failure
CloseHandle( hProcessSnap ); // clean the snapshot object
return( FALSE );
}
// Now walk the snapshot of processes, and
// display information about each process in turn
do
{
isAlive =1 ;
dwPriorityClass = 0;
printf("\n-----------ProcessName [%s]\n ",pe32.szExeFile);
printf( "\n Process ID = %04d", pe32.th32ProcessID );
pid = pe32.th32ProcessID;
printf( "\n Thread count = %d", pe32.cntThreads );
printf( "\n Parent process ID = %d", pe32.th32ParentProcessID );
printf( "\n Priority base = %d", pe32.pcPriClassBase );
if( dwPriorityClass )
printf( "\n Priority class = %d", dwPriorityClass );
userhp = OpenProcess( PROCESS_ALL_ACCESS, TRUE, pe32.th32ProcessID );
getuserProcess(userhp);
} while( Process32Next( hProcessSnap, &pe32 ) );
CloseHandle( hProcessSnap );
return 0;
}
void getuserProcess( HANDLE pid)
{
PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
PSID psidOwner = NULL; TCHAR lpName[256];
TCHAR lpReferencedDomainName[256];
SID_NAME_USE eUse;
if (ERROR_SUCCESS == GetSecurityInfo(pid,//GetCurrentProcess(),// HANDLE handle,
SE_KERNEL_OBJECT, //SE_OBJECT_TYPE ObjectType,
OWNER_SECURITY_INFORMATION, //SECURITY_INFORMATION SecurityInfo,
&psidOwner, //PSID* ppsidOwner,
NULL, //PSID* ppsidGroup,
NULL, //PACL* ppDacl,
NULL, //PACL* ppSacl,
&pSecurityDescriptor // PSECURITY_DESCRIPTOR* ppSecurityDescriptor
))
{ DWORD cchName = 256;
DWORD cchReferencedDomainName = 256;
if (LookupAccountSid( NULL, // LPCTSTR lpSystemName,
psidOwner, //PSID lpSid,
lpName, //LPTSTR lpName,
&cchName, //LPDWORD cchName,
lpReferencedDomainName, //LPTSTR lpReferencedDomainName,
&cchReferencedDomainName, //LPDWORD cchReferencedDomainName,
&eUse //PSID_NAME_USE peUse
))
{
printf("UserName is [%s]",lpName);
printf("UserDomain is [%s]",lpReferencedDomainName);
LocalFree(pSecurityDescriptor);
}
}
}
void printError( TCHAR* msg )
{
DWORD eNum;
TCHAR sysMsg[256];
TCHAR* p;
eNum = GetLastError( );
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, eNum,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
sysMsg, 256, NULL );
// Trim the end of the line and terminate it with a null
p = sysMsg;
while( ( *p > 31 ) || ( *p == 9 ) )
++p;
do { *p-- = 0; } while( ( p >= sysMsg ) &&
( ( *p == '.' ) || ( *p < 33 ) ) );
// Display the message
_tprintf( TEXT("\n WARNING: %s failed with error %d (%s)"), msg, eNum, sysMsg );
}
and a sample output
-----------------------
Process ID = 1604
Thread count = 9
Parent process ID = 268
Priority base = 8
-----------ProcessName [UMCSTUB.EXE]
Process ID = 1632
Thread count = 5
Parent process ID = 268
Priority base = 8
-----------ProcessName [dfssvc.exe]
Process ID = 1760
Thread count = 3
Parent process ID = 268
Priority base = 8
-----------ProcessName [msdtc.exe]
Process ID = 1780
Thread count = 23
Parent process ID = 268
Priority base = 8
-----------ProcessName [rcHost.exe]
Process ID = 1844
Thread count = 9
Parent process ID = 268
Priority base = 10
-----------ProcessName [svchost.exe]
Process ID = 1812
Thread count = 10
Parent process ID = 268
Priority base = 8
-----------ProcessName [DLLHOST.EXE]
Process ID = 3056
Thread count = 8
Parent process ID = 500
Priority base = 8
-----------ProcessName [CAF.exe]
Process ID = 3052
Thread count = 33
Parent process ID = 268
Priority base = 8
-----------ProcessName [cfsmsmd.exe]
Process ID = 1708
Thread count = 15
Parent process ID = 3052
Priority base = 8
-----------ProcessName [ccnfAgent.exe]
Process ID = 3044
Thread count = 5
Parent process ID = 3052
Priority base = 8
-----------ProcessName [cfnotsrvd.exe]
Process ID = 2284
Thread count = 17
Parent process ID = 3052
Priority base = 8
-----------ProcessName [ccsmagtd.exe]
Process ID = 2952
Thread count = 7
Parent process ID = 3052
Priority base = 8
-----------ProcessName [rcHost.exe]
Process ID = 2376
Thread count = 8
Parent process ID = 3052
Priority base = 13
-----------ProcessName [amswmagt.exe]
Process ID = 2408
Thread count = 7
Parent process ID = 3052
Priority base = 8
-----------ProcessName [capmuamagt.exe]
Process ID = 2468
Thread count = 4
Parent process ID = 3052
Priority base = 8
-----------ProcessName [cfFTPlugin.exe]
Process ID = 1644
Thread count = 7
Parent process ID = 3052
Priority base = 8
-----------ProcessName [dm_primer.exe]
Process ID = 2720
Thread count = 4
Parent process ID = 780
Priority base = 8
-----------ProcessName [CMD.EXE]
Process ID = 0572
Thread count = 1
Parent process ID = 3308
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [nlnotes.exe]
Process ID = 3352
Thread count = 24
Parent process ID = 3672
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [ntaskldr.exe]
Process ID = 3724
Thread count = 8
Parent process ID = 3352
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [explorer.exe]
Process ID = 3376
Thread count = 14
Parent process ID = 212
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [MSDEV.EXE]
Process ID = 1700
Thread count = 10
Parent process ID = 3376
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [editplus.exe]
Process ID = 3176
Thread count = 4
Parent process ID = 3376
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [IEXPLORE.EXE]
Process ID = 3636
Thread count = 16
Parent process ID = 3376
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [abc.exe]
Process ID = 3480
Thread count = 4
Parent process ID = 3376
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [VCSPAWN.EXE]
Process ID = 3356
Thread count = 1
Parent process ID = 1700
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [filops.exe]
Process ID = 1088
Thread count = 1
Parent process ID = 3356
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
---------------------------------------------------------------------
The process having user as system are failed ...
vineesh
|
|
|
|
|
Try the following which adjust the current process priviledge to get remote process info.
HANDLE hToken = NULL;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES,
&hToken))
{
if (SetPrivilege(hToken, SE_DEBUG_NAME, TRUE))
{
HANDLE hProcess = OpenProcess( READ_CONTROL | ACCESS_SYSTEM_SECURITY ,
TRUE, dwprocessID);
if (hProcess)
{
getuserProcess(hProcess);
CloseHandle(hProcess);
}
SetPrivilege(hToken, SE_DEBUG_NAME, FALSE);
}
CloseHandle(hToken);
}
SetPrivilege function is here[^]
|
|
|
|
|
|
Hi all
Could anyone please let me know whats the equivalent API for "cacls command" ?
(cacls is used to modify the user rights settings on a file)
As of now I use ShellExecute to run the batch file which contains this cmd . I would like to avoid using batch file .
Thanks in advance .
redindian
|
|
|
|
|
Haven't you searched msdn Access Control Lists[^]
dharani wrote: As of now I use ShellExecute to run the batch file which contains this cmd . I would like to avoid using batch file .
If so, why don't you execute the command directly using ShellExecute without a batch file.
|
|
|
|
|
|