|
You might want to read this. Without more information, we couldn't tell you anything more helpful than what's at that link.
|
|
|
|
|
hi i have to run a command in command window as administrator. how to do this using mfc. pls help me
|
|
|
|
|
One way would be to make sure your MFC app has a manifest file with a "trustInfo" section and the requestedExecutionLevel level="asAdministrator"
That will make any process spawned by the MFC app run at the security level of "Administrator".
There may be more elegant solutions to this but this seems to work ok.
|
|
|
|
|
Hello.
I'm trying to figure out how to determine on which disk is Windows installed. I need to do this so that I can get additional infos afterwards about it, like Model Number, Serial Number, etc.
I don't need the partition letter (C:, etc), that's easy to get, but on which disk that partition is located (Primary Master (\\.\PhysicalDrive0), Primary Slave (\\.\PhysicalDrive1), etc).
Also, I don't want to use WMI.
Any help is greatly appreciated. Thanks alot.
|
|
|
|
|
Heres what I would do:
Step 1.) Read the %WINDIR% environment variable and parse what it returns. Lets say it returns C:\Windows\...
Step 2.) Save the drive letter "C:" into a buffer lets say szDrive[3].
Step 3.) Use the QueryDOSDevice() function to see which physical drive.
char szBuf[256];<br />
BOOL bResult = QueryDosDevice(szDrive,szBuf,sizeof(szBuf));
Step 4.) If we also wanted to know partition information we could do something like:
sprintf(szPhysical,"%s%s","\\\\.\\",szDrive);<br />
hDevice = CreateFile(szPhysical,GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,NULL);<br />
if (INVALID_HANDLE_VALUE != hDevice)<br />
{<br />
DWORD dwRet =0;<br />
bResult = DeviceIoControl(hDevice,IOCTL_DISK_GET_PARTITION_INFO,NULL,0,&p,sizeof(p),&dwRet,NULL);<br />
printf("PartitionNumber: 0x%x %d",p.PartitionNumber,p.PartitionNumber);<br />
}
There are plenty of other IoCtl calls you can do to get extended information such as disk geometry.
Best Wishes,
Randor (David Delaune)
|
|
|
|
|
Thanks alot for your help!
For Win2k or later QueryDosDevice doesn't return the actual disk index, but the path to the volume object, so in that case we need to call DeviceIoControl with IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS.
Here's the code to accomplish that (used code from Sysinternals's DiskExt):
DWORD GetDiskIndex(TCHAR DriveLetter) {
TCHAR volumePath[MAX_PATH];
HANDLE hVolume;
ULONG bytesWritten;
UCHAR DiskExtentsBuffer[0x400];
PVOLUME_DISK_EXTENTS DiskExtents = (PVOLUME_DISK_EXTENTS)DiskExtentsBuffer;
_stprintf( volumePath, _T("\\\\.\\%c:"), DriveLetter);
hVolume = CreateFile( volumePath,
GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL );
if( hVolume == INVALID_HANDLE_VALUE ) {
return -1;
}
DWORD dn = -1;
if (DeviceIoControl( hVolume, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
NULL, 0, DiskExtents, sizeof(DiskExtentsBuffer), &bytesWritten, NULL )) {
dn = DiskExtents->Extents[0].DiskNumber;
}
CloseHandle(hVolume);
return dn;
}
|
|
|
|
|
Dear all
How to use webcam in VC++? thanks a lot.
Li Zhiyuan
30/06/2007
|
|
|
|
|
|
I try to use RegLoadKey with HKEY_LOCAL_MACHINE hive, but it returns ERROR_ACCESS_DENIED ,
the code below works for HKEY_CURRENT_USER hive , i couldnt figure out why it didnt for also HKEY_LOCAL_MACHINE
although i am setting privilige defined as msdn ( http://msdn2.microsoft.com/en-us/library/ms724889.aspx )
Can you help me ?
HKEY hive ;
LONG lReturn ;
char sFileName[12] = "c:\\test.dat";
SetPrivilege(SE_BACKUP_NAME,TRUE);
SetPrivilege(SE_RESTORE_NAME,TRUE);
RegOpenKeyEx(HKEY_LOCAL_MACHINE, "",0,KEY_READ, &hHive);
RegSaveKey(hHive,sFileName,NULL);
lReturn = RegLoadKey(HKEY_LOCAL_MACHINE,"newhklm\\",sFileName);
// lReturn becomes 5L which means ERROR_ACCESS_DENIED
My privilige function :
BOOL SetPrivilege(LPCTSTR lpszPrivilege, BOOL bEnablePrivilege)
{
TOKEN_PRIVILEGES tp;
LUID luid;
HANDLE hToken;
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
if ( !LookupPrivilegeValue(NULL, lpszPrivilege, &luid) )
return FALSE;
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
return ( (GetLastError()!=ERROR_SUCCESS)?FALSE:TRUE);
}
|
|
|
|
|
Akin Ocal wrote: lReturn = RegLoadKey(HKEY_LOCAL_MACHINE,"newhklm\\",sFileName);
Shouldn't this be:
lReturn = RegLoadKey(hHive, "newhklm\\", sFileName);
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
i have used CString in many places of my code. is anything harm on using this? will it leads to memory leak? pls help me
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
The whole point of a string class is to control memory leaks, by controlling assignment and deletion of character arrays.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I try to remote control my computer use my cell phone which has bluetooth function. So the simplest method may be enough.
Thanks.
|
|
|
|
|
I think I'm able to provide you a starting point in your searches. You can use BT (Bluetooth) by WinSocket or OBEX - Object Exchange.
OBEX is some protocol like HTTP but much simpler, designed for devices with limited performances (like handheld and mobile devices). It's useful especially for Object Pull and Object Push (download/upload) but you will need a server on you PC (if you want to connect your mobile to your PC). I think that this is not what you`re interested in, but just in case.
Winsock will allow you to start searching BT devices,set security settings, connect to the selected device and eventually start remotely control your device. I'm sorry I cannot provide more help for you, I've just started documenting on this topic myself, too.
|
|
|
|
|
Why No default constructor is implicitly created for a class that has any constant or reference type members?
Why copy constructor is not created for a class if any of its members or base classes have an inaccessible copy constructor?
|
|
|
|
|
If you are having constant or reference type data member than they need to be initialised. Initialisation can happen only through constructor initialisation list.
class A
{
int g&;
int s;
const int h;
public :
A():g(s), h(10) // constructor initialisation list.
{
}
};
This constructor can be default one or overloaded.
A(int k):g(s), h(10)
{
}
--------------------------------------------------------
One more General Rule :
If you are providing only overloaded constructor then default constructor
will not be provided automatically. You need to give deinition for default constructor.
--------------------------------------------------------
|
|
|
|
|
Constant members must be initialized, and reference members bound, *explicitly* in the member initializing list of the constructor.
And the behavior of the default copy constructor is to perform a memberwise copy to its sub-objects, which would become impossible is any of the sub-objects have an inaccessible copy constructor.
|
|
|
|
|
Is there an easy way to cycle through all the controls on a form. I want to be able to determine if an entry has been made in a certain control (edit box) that is a required field. These required fields can change by user.
Eric
|
|
|
|
|
Do you want this cycle for controls on your program or other programs?
|
|
|
|
|
I want to cycle through the edit boxes on my screen, without have to put in all the IDC_??? names.
Here is a sample of what I am doing:
if ((sLabelName[i]=="IDC_STATIC_COMPANY")&&(iLabelRequired[i]==1))
{
GetDlgItemText(IDC_COMPANY, sTemp);
if (sTemp.GetLength()
|
|
|
|
|
I suppose you can enumerate the child windows looking for edit controls, something like this
(I'm assuming you're using MFC, based on the code you posted):
BOOL CALLBACK MyDialogEnumChildProc(HWND hwnd, LPARAM lParam)
{
TCHAR szClassName[32];
if (::GetClassName(hwnd, szClassName, 32))
{
if (!_tcsicmp(szClassName, _T("EDIT")))
{
CMyDialog *pMyDialog = (CMyDialog *)lParam;
}
}
return TRUE;
}
...
void CMyDialog::SomeFunc()
{
::EnumChildWindows(*this, MyDialogEnumChildProc, (LPARAM)this);
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
braune wrote: I want to be able to determine if an entry has been made...
At what point are you doing this check?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I want to do the check when the user clcks a button to perform an operation. The first item of business for this operation would be to field validation, ie. make sure the required fields have entries and they are of a minimum length.
Eric
|
|
|
|
|
braune wrote: I want to do the check when the user clcks a button to perform an operation.
Do not enable the button until all conditions have been met. Otherwise, this just leads to confusion.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Its not quite that simply. I have multiple customers who have different requirements. Here is what I am doing: I have created an external file that I read in when the program starts. The external file contains a list of the fields that are required and the minimum length of each. When I read the file in I set all the labels for these fields to RED, so the user knows they are required fields. I set the labels using the following:
if ((sLabelName[i]=="IDC_STATIC_COMPANY")&&(iLabelRequired[i]==1))
m_stCOMPANY.SetTextColor(LIGHTRED);
if ((sLabelName[i]=="IDC_STATIC_WELLNAME")&&(iLabelRequired[i]==1))
m_stWELLNAME.SetTextColor(LIGHTRED);
I would rather cycle through all the labels on the form, rather than putting them in statically. When the user selects a button I do much the same to test, except using the editbox controls to correct if required and the minimum length.
Hope this info helps.
Eric
|
|
|
|
|