|
Hi, .S.Rod. buddies!
In your reply, you mentioned,
--------
The side effect of this is that MS changed APIs in MFC7/ATL7 and added const in some places, causing older code to either warn or not compile anymore.
--------
when you are talking about the side effect, do you mean older functions without const keyword will not compile? If I am not correct, please show
me the correct explanation.
Thanks in advance,
George
|
|
|
|
|
George2 wrote:
when you are talking about the side effect, do you mean older functions without const keyword will not compile? If I am not correct, please show
me the correct explanation
It depends if you are talking about your functions, or functions from the MFC that you use.
If that's about your functions, then I don't know : of course I don't know your code so it's not possible to tell if there is anything wrong.
If that's functions from the MFC that you use, then yes, the MFC7 collections (CStringArray, CPtrArray, ...) have now const & everywhere (as a result of the integration of STL), which was not the case with MFC6. If you intend to upgrade to MFC7 someday, be prepared to have tons of problems.
|
|
|
|
|
Thanks, .S.Rod. buddies!
Your reply have made me clear!
Best regards,
George
|
|
|
|
|
const and & are two different things
const = "can not be modified" - no problem
& is a must here:
1. "value" is real object passed, not a copy of real object.
2. as template params, reference is a must because we don't know what kind of objects will be used as template params. in other words, we don't know if operator= and copy constructor have been defined in these objects.
for all of MFC collection, operator= and copy constructor are not defined (actually they are defined as "private" to protect to be used.) so if no &, don't hope any MFC collection can be passed as template params.
includeh10
|
|
|
|
|
Thanks, includeh10 buddies!
Your reply helps a lot.
Best regards,
George
|
|
|
|
|
The keyword const indicates that the function may not change the value. The "&" indicates that the value is passed by reference (e.g. the address of the value is passed, not a copy of the value). Without the const keyword, the function would be free to modify the caller's copy of value , which is not desired. If the "&" is left out, value is passed by value, and any changes the function makes to it does not affect the caller's copy.
Software Zen: delete this;
|
|
|
|
|
Ahhh, the beauty of const & parameters! I use these two conventions:
1. If a parameter is passed as a reference, it must always be a const reference.
In the following code, does foo change the value of bar or not?
foo( bar );
Most people would say no, but foo could be defined like this:
void foo( int & x ) { ++x; }
Since people are suprised when something like that happens, it is a source of bugs, so it is a bad idea. Don't change the value of parameters passed by reference. And since the reference is never going to change, you might as well make it const .
If the code looks like this...
foo( &bar );
...then people are not be surpised if the value of bar is changed by foo. So, if the value is changed, use * , If it isn't, use const & .
2. Prefer const & to const * .
So, why use const & when you can use const * ? There are other reasons, but here is mine: A function call that doesn't change the value of a parameter should look like it doesn't change the value and vice versa.
void foo( int const & x ) { ... }
void foo( int const * x ) { ... }
...
foo( bar );
foo( &bar );
|
|
|
|
|
How can I prevent ESC(or any other special key) from closing a dialog?
|
|
|
|
|
If you use MFC you should overwrite OnCancel function in your dialog message map.
In W32API remove case IDCANCEL from your dialog callback function.
|
|
|
|
|
Thanks!
|
|
|
|
|
Hi
i am starting to learn DirectX 8 and i am searching about 3 days for Books and Sites and articles about DirectX 8 (or even 9) but i find nothing Special to be helpful for the Basics of DX.
i have searched Kazaa too and i found Teach yourself DirectX 7 in 21 days(Sams publishing). but it seems that the structure of DirectX has completely changed and for example DirectDraw dose not exist in DirectX 8. (if you thing that this book is still helpful tell me plz. i dunno how much DirectX changed from Ver7 to ver8)
So if u know and Resources for learning DirectX Basics plz tell me.
thanks for your suggestion
-=Ehsan-de-Burge=-
|
|
|
|
|
try gamedev.net they have some directx tutorials
there are many parts to directx 2d, 3d, audio, video, input etc
|
|
|
|
|
Hi, everyone!
What means cout.precision (4)? Who can give me
a sample to show the usage?
Thanks in advance,
George
|
|
|
|
|
George2 wrote:
What means cout.precision (4)?
It means you're calling the member function precision , inherited from ios_base , for the cout object with the argument 4 . It changes the output precision for floating point numbers.
This is all in the documentation. In case you (for some reason) don't have the documentation, perhaps a little Googling could be a source of information?
|
|
|
|
|
Hello,
Can anyone tell me how to replace the standard Windows clock in the system tray with my own text or icon/text combination?
Thanks!
MCP, MCSD
|
|
|
|
|
dennisV wrote:
Can anyone tell me how to replace the standard Windows clock in the system tray with my own text or icon/text combination?
Wouldn't turning off the clock from Taskbar Properties and add some huge tray-icon/text/whatever tray program work (or at least be a starters). If that fails, replace Explorer.exe.
++luck;
|
|
|
|
|
http://www.bmx3r.com/tclock/
its great example
|
|
|
|
|
Thank you - I'll check it out.
// MCP, MCSD
// Software for animal shelters
// http://www.smartpethealth.com
|
|
|
|
|
hi guys, I'm trying to get a global mouse hook and listen to mouse clicks clicked on the windows desktop, however, I only succeeded in getting mouse clicks on a client window, but can't getting mouse clicks on the desktop, the following is my code(in trying to hook the desktop): any help and pointers are appreciated
#include <iostream.h>
#include<fstream.h>
#include <windows.h>
#include <stdlib.h>
#include<stdio.h>
#define WIN32_LEAN_AND_MEAN // Quicker build times;
#define WINDOWNAME "Simple Sample Application"
/*----------------------------------------------------------------*\
Global Variables - to vanish in the C++ version;
\*----------------------------------------------------------------*/
HWND hWnd; // Main window handle;
int screenHeight,screenWidth;
ofstream errstream("mouseLog.txt");
#pragma data_seg(".shared") // you must define as SHARED in .def
HHOOK mouseHook,keyboardHook;
HINSTANCE g_hinstance;
//DWORD g_dwLastTick = 0; // tick time of last input event
//LONG g_mouseLocX = -1; // x-location of mouse position
//LONG g_mouseLocY = -1; // y-location of mouse position
#pragma data_seg()
//#pragma comment(linker, "/section:.IdleTrac,rws")
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lparam){
switch(wParam){
case 27:
UnhookWindowsHookEx(mouseHook);
UnhookWindowsHookEx(keyboardHook);
errstream.close();
PostQuitMessage(0);
}
return 0;
}
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lparam){
MessageBox(hWnd,"in mouse proc ","",MB_OK);
MOUSEHOOKSTRUCT* mousehook=(MOUSEHOOKSTRUCT*)lparam;
POINT p=mousehook->pt;
switch(wParam){
case WM_RBUTTONDOWN:
MessageBox(hWnd,"right button down","",MB_OK);
// errstream<<"mouse position is "<
|
|
|
|
|
You need to put your hook code in a DLL. That is the only way that you can get your code installed into another applications process space.
Then you will need to use either a shared data segment in the DLL to communication the information back to you, or some other form of Interprocess Communucation (IPC).
Good luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
thanks a lot, but I'm kind of new to windows programming and this all seem a bit abstract. So after I put my hooking procedures in a dll, am I able to call those procedures from another piece of code?
would you give me some explanation/code snipets in details?
thanks
|
|
|
|
|
I am trying to recursively list all the files on a FTP server. Right now, all it does is list the files in root. The function appears to be called for each directory it encounters, but it never finds any files on it. The server log never shows a list command being issued, but a printf shows that the function is entered. Any suggestions?
CInternetSession sess(_T("SomeApp/1.0"));
CFtpConnection* pConnect = NULL;
void Search(CString sPath)
{
CFtpFileFind finder(pConnect);
CString sSearch;
sSearch.Format("%s/*",sPath);
try
{
BOOL bWorking = finder.FindFile(sSearch);
while (bWorking)
{
bWorking = finder.FindNextFile();
printf("%s\n", (LPCTSTR)finder.GetFilePath());
if(finder.IsDirectory() && !finder.IsDots())
Search(finder.GetFilePath());
}
finder.Close();
}
catch (CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz,1024);
printf("ERROR: %s\n",sz);
pEx->Delete();
}
}
pConnect = sess.GetFtpConnection(_T("server"),"Username","password");
Search("");
Thanks,
Aaron Stubbendieck
modified 12-Jul-20 21:01pm.
|
|
|
|
|
hi guys I have a windowns application that tries to reboot window, but according the error code, A required privilege is not held by the client application. how do I resolve this problem? the following is my code:
thanks!!
#include <windows.h>
#include <stdio.h>
#include <iostream.h>
void main(){
int res=ExitWindowsEx(EWX_REBOOT,0);
printf("%d",res);
DWORD d=GetLastError();
cout<
|
|
|
|
|
Try this code:
void ShutDownMe()
{
OS_VERSION_INFO osvi;
BOOL bNeedPrivileges;
ZeroMemory(&osvi,sizeof(OS_VERSION_INFO));
GetOSVersion(&osvi);
if (IsWindows95(&osvi) || IsWindows95OSR2(&osvi) || IsWindows95SP1(&osvi) ||
IsWindows98(&osvi) || IsWindows98SE(&osvi) || IsWindows98SP1(&osvi))
bNeedPrivileges=FALSE;
else
bNeedPrivileges=TRUE;
if (bNeedPrivileges)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
return;
}
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
{
return;
}
}
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0);
}
A. Riazi
|
|
|
|
|
thanks Riazi,
but what headers do I need to include to make this work? OS_VERSION_INFO does not exist in windows.h
thanks
|
|
|
|
|