|
In either case, the wMilliseconds member of the SYSTEMTIME structure is the same. Since the GetSystemTimeAsFileTime() function does not need granularitry beyond milliseconds, the extra value can be ignored.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Is that considered good or bad?
I just read a paper by Bjarne, where he used
Vector::Vector(int i) : sz(i), v(new int[i]) { } which I never do myself.
If heap allocation is needed, then I initialize the pointer with NULL in the member initialization list (MIL) and allocate the memory with new in the ctor body. But if you're using standard compliant tools that throws correctly if new fails, then it's perhaps OK to do it in the MIL.
Any thoughts on this?
--
The Blog: Bits and Pieces
|
|
|
|
|
i write a global CBT_HOOK function in a win32 DLL ,and i want to send a message to the DLL's calling windows.But it doesnt work. Here is my code:
HWND hCallWnd = NULL;
LRESULT CALLBACK CbtProc(int nCode,WPARAM wParam,LPARAM lParam)<br />
{<br />
switch(nCode)<br />
{<br />
case HCBT_CREATEWND: SendMessage(hCallWnd,MyMsgID,0,0);
break;<br />
}<br />
return CallNextProc(nCode,...);<br />
}<br />
void InstallHook(HWND hcallwnd)<br />
{<br />
SetWindowsHookEx(WH_CBT,CbtProc,DllHandle,0);
hCallWnd = hcallwnd;
}
the Error is : in InstallHook() function,the hCallWnd's value is correct. But in CALLBACK CbtProc() function, the hCallWnd's value is always ZERO! so my SendMessage() doesnt work at all.
Who can point out reason ?
|
|
|
|
|
The DLL is loaded into the address space of each process and each process gets a separate copy of the global variable. You need to put hCallWnd into a shared partition.
See this article[^].
|
|
|
|
|
Is there any function to know that the current logon user is Administrator or Limited user?
Jesa
|
|
|
|
|
Hi
I think this will help you...Buffer in this function will be having all informatin that you want...
1. NetUserGetInfo()
2. GetUserName (Win API)
"Most of the failures in their life are the people are those who don't how near they were from the solution"
- Mahesh Amarelia
Gujarat
India
|
|
|
|
|
I survey the MSDN for the two function,
I think the problem will be solved by the two function.
But I need more time to realize the usage for the two function.
Anyway, you really help me a lot! Thanks
Jesa
|
|
|
|
|
Years ago I had the same problem, how to know user has admin rights if admin's user name is e.g "john" or if the user name is admin, does s/he really have those privileges ? I solved the problem by opening ServiceControlManager's database requesting SC_MANAGER_ALL_ACCESS rights. If it won't open, user is not an admin, if it opens user is really an admin.
I don't know how correct way this is to solve the problem, but it worked fine, and I think it is also rather simple way to detectuser's admin-level rights.
BOOL XYZ::IsUserAdmin(){
SC_HANDLE hSC;
ENUM_SERVICE_STATUS enumsstat;
hSC=::OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if(hSC==NULL){
DWORD dwErr;
dwErr=GetLastError();
char szMsg[300]="";
switch(dwErr){
case ERROR_ACCESS_DENIED:
return FALSE;
break;
case ERROR_DATABASE_DOES_NOT_EXIST:
wsprintf(szMsg,"ServiceControlManager Database doesn't exist");
break;
case ERROR_INVALID_PARAMETER:
wsprintf(szMsg,"Invalid parameter while executing OpenSCManager()");
break;
default:
wsprintf(szMsg,"Error when executing OpenSCManager(), Error code is %ld",(long) dwErr);
break;
}
AfxMessageBox(szMsg);
return FALSE;
}
::CloseServiceHandle(hSC);
return TRUE;
}
|
|
|
|
|
Thanks for your answer!
This way works fine
Jesa
|
|
|
|
|
hi all!!
i want to develop an application which first checks whether the user is Administrator or any other user.
If the user is not administrator, i want to find the name of the user
how do i proceed?
|
|
|
|
|
1. GetUserName (Win API)
2. Env Variable USERNAME
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
"Philosophy is a study that lets us be unhappy more intelligently."
-Anon.
|
|
|
|
|
i tried to search gamma value for printer, but i only found one for CRT, NTSC, PAL and stuff, not printer.
and i guess win32 api has "Getting printer's gamma correction factor" func or something similar...
does anyone know?
thanks in advance~
|
|
|
|
|
HI,
How can i read n write uing parallel Port
can any body tell me. with sample plz
thanx
Regards.
|
|
|
|
|
There are numerous examples here on Code Project about the programming of serial and/or parellel port.
Here's one of them, showing you how to control LED's with parellel port. The article is written by Jaygiri. The article[^].
Read the article through, and you will understand more of how the parellel port works. For even more detailed information, see this article[^]. It's written for C#, but the technical reference at the start is essential.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
thay all show how to write data there ,
but i also read data from there send by device
tll me abut read
thanx
Regards.
|
|
|
|
|
First, point your browser to this location: http://www.logix4u.net/inpout32.htm
In there, download the Inpout32 binaries and sources. From this zipfile, extract the files inpout32.dll and inpout32.lib. Place these into your project directory.
Open up your project, and go to project settings. Link with "inpout32.lib" to gain access to two functions: Inp32 and Out32 . You also need the definitions of the functions. They are as follows (add them to the start of the code module where you wish to use them, or create a header file):
extern short _stdcall Inp32(short PortAddress);
extern void _stdcall Out32(short PortAddress, short data); Now, use the articles' instructions to determine the address of your computer's parellel port. Then use the Inp32 function to read from this address. The returned value is a short integer.
If you need to determine if a certain pin on the port is set to logic-1 (high), use the articles' instructions, or Google for 'binary operations'. The idea is to mask the returned value against a certain value. The result of the mask operation is either TRUE or FALSE, depending if the pin is set or not. There are so many examples of masking operations on the Net that I don't want to repeat them here.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
i got it ,,
i have little confusion now.
I m writing data on 0x378 address (data register)that goes to attached device
can i read data from it ,, mean to say that my
device can write data on data register pin that i want to register.
or it should write on status pins (10-15)
or only pins 2 to 9 can do both read and write
thax
Regards.
|
|
|
|
|
The pins of a MODERN (at least a Pentium III -grade computer/MB) parellel port are indifferent whether you are reading or writing. You can both read and write to the data port. This is called a bi-directional LPT port.
You can use the data port (0x378) to send data (write values from 0 to 255). The data is represented in binary format, with the D0 being the least significant bit and D7 the most significant.
You can also use the data port to receive data. If you use the D0-D7 pins, you can read from address 0x378. If you input the voltages to pins S3-S6, you use the address 0x379 to read the value. Remember that the input values on S3-S6 range from 0, 8 - 248, because pins S0-S2 are not physically there, although they exist for the computer. This means that if you read from the address 0x379, and only the S3 has voltage, the received integer is 8. If all S3-S6 have voltage, the value is 248. If none have voltage, the value is 0. Note that I am not 100% sure of these values. The easiest way is to physically put a suitable voltage there and see what the function returns.
Remember to use big enough resistors in your connections. The parellel port cannot handle big currents (output or input). It will break, and most likely also damage your motherboard. The maximum current running through a pin should be around 2-3 mA. This "should" be safe, however I cannot guarantee, and will not take responsibility. The best way is to use a TTL optocoupler that will physically disconnect the actual device from the parellel port. In this way, the data is transfered in TTL logic levels, but the currents will never go over the limits.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
thanx but a little problm again.
i m writing to data register a value assume 18.
in response my device should return me 33;
when i read it from data register ( the reply of device) it gives me the same value as i sended. 20.
wts the problm ,, my device is not properly updating(writng on ) data register .
is it .. or some other isssue
thanx
Regards.
|
|
|
|
|
This happens because both your application and the device are writing to the port at the same time.
The Inpout32 library, when you call Out32() , will set the port's pins to represent the value you specify. This means that the pins will stay powered even after the call is completed.
To initiate succesfull communication with your device through the same port, first use Out32(888, 0) to clear any previous outputs. Then write Out32(888, 18) . Now make your device read the value in some way (press a button, for example). When done, write Out32(888, 0) again. Put your device to send data, and use Inp32 to read the value.
The problem itself is simple: both you and the device are issuing voltage to the port's pins. This means that if you write 00000001 and your device answers to this by putting 10000000, the port will end up with 10000001, unless you clear your own output first. So, the trick is to call Out32(888, 0) before reading the input.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I also set the Control pin-5 to TRUE(1)
as for Bi Directional
but .....no
Regards.
|
|
|
|
|
|
I have used one function called "LogonUser" to log into given server with given user name. This function returns the handle which you can use to impersonate the current user. The function to do that is
BOOL ImpersonateLoggedOnUser(HANDLE hToken);
Now after doing this I want to use function "FindFirstFile()" and "FindNextFile" to get the list directory/files in given path.
Here I want to list only those directory/files which a user has rights to access ? so how to do it exactly after using LogonUser function.
Can any one help me ?...I m writing my structure here..
----------------------------------------
void main()
{
RetVal = LogonUser(pszUserName,pszDomainName,pszPassword,dwLogonType,dwLogonProvider,&hToken);
if (RetVal != 0)
{
ResImp = ImpersonateLoggedOnUser(hToken);
if (ResImp != 0)
{
hHandle = FindFirstFile(....) // Here I want to find only those files which have right so that user "pszUserName" can access it..."
if( all files found)
{
list all files here....
}
else
{
You don't have rights to access this files/directories...
}
}
}
}
------------------------------------
Can you plz help me ? It's really urgent....
Thanking You...
Amarelia
|
|
|
|
|
I want to change the position of mouse pointer in my Internet Explorer.For this i have written the code below.But the createEventObject method fails.Please if someone could tell me what is the reason for this failure and what should be done so that createEventObject returns success.Thanks in advance.
IHTMLEventObj *pEvtObj = NULL;
IHTMLDocument4 *pDoc4 = NULL;
hr = m_pHTMLDoc->QueryInterface( IID_IHTMLDocument4,(void**)&pDoc4);
//m_pHTMLDoc is a valid document pointer
if(SUCCEEDED(hr))
{
hr = pDoc4->createEventObject(NULL,&pEvtObj);
if(SUCCEEDED(hr))
{
CComQIPtr<ihtmleventobj2, &iid_ihtmleventobj2=""> pEvtObj2;
pEvtObj2 = pEvtObj;
g_Xpos = g_lastXpos = Xpos;
g_Ypos = g_lastYpos = Ypos;
hr = pEvtObj2->put_clientX(Xpos);
if(hr == 0)
{
AfxMessageBox("put_clientX successful");
}
else
{
AfxMessageBox("put_clientX failed");
}
hr = pEvtObj2->put_clientY(Ypos);
pEvtObj2->Release();
}
pDoc4->Release();
}
|
|
|
|
|
HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_EDIT2)
{
pDC->SetTextColor(RGB(255, 0, 0));
hbr = m_brush;
}
return hbr;
}
this code works beautifully when changing an edit box (IDC_EDIT2), but if i put a static name instead like IDC_STATIC1, the static stays the same color (it doesnt change colors), anyone know how this can be solved? im just trinyg to change 1 static and leave the rest alone
|
|
|
|
|