|
Glad to hear that. You're welcome.
|
|
|
|
|
Just reviewing some code...
In it, there is a line like this :
CString s;
//... do something with s.
if ( s.GetLength() > 0 )
{
}
my first reaction was to note that and propose change the GetLength with IsEmpty()
if ( !s.IsEmpty() )
{
}
Looking at the code CString code (VS2008 and VS2010) for IsEmpty() , it calls GetLength() . The generated code will probably be optimized to the same assembly.
Was there a time (I don't have VS2003 or VC6 installed to check) when GetLength and IsEmpty were "really" different ? or they are there for code readbility issue ?
Thanks.
Max.
Watched code never compiles.
|
|
|
|
|
Back when I used MFC in the early 90s IsEmpty was defined in terms ot GetLength .
if( str.IsEmpty() )
{
....
}
can almost be read as english text: "If str is empty..." Compare that with:
if( str.GetLength() == 0 )
{
}
which has to be read as "if str's length is zero" and then translated. There's less of a semantic gap between what's written and it's meaning.
Anyway, sorry about the verbose answer, overly complicated logical expressions are one of my hobby horses - change the code in your review, future generations will thank you for it.
Cheers,
Ash
|
|
|
|
|
Since they both reference the nDataLength member variable, it likely does not matter.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Saying if a text is empty and say how long a text is are two different concepts: the first is simpler (requires an immediate check) than the second (requires to count somehow the data).
So they have two distinct functions.
The fact that the actual implementation keeps track of the length as long as it changes, so that both methods take advantage by a same computation is an "implementation detail" that may vary in future releases.
!GetLength() is semantically the same as IsEmpty() but don't expect they will always do the same computation and result in the same performance.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
emilio_grv wrote: Saying if a text is empty and say how long a text is are two different concepts...
True, but saying if a text is empty and if the text's length is 0 are identical.
emilio_grv wrote: The fact that the actual implementation keeps track of the length as long as it changes, so that both methods take advantage by a same computation is an "implementation detail" that may vary in future releases.
It hasn't since day one and likely won't for the foreseeable future.
emilio_grv wrote: !GetLength() is semantically...
...wrong since GetLength() is not a boolean function and thus should not be treated as such.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
It seems you are misunderstanding some of my points. Let me try to clarify.
DavidCrow wrote: True, but saying if a text is empty and if the text's length is 0 are identical.
Yes ... but what about the opostite? (saying it is not empty doesn't say the length. Moral: the concepts are not "identical" - in math sense- since the symmetrical property is not valid. But is is true that the length concept includes the empty concept in it. It not the same: it is more general, and requires more informations, in general terms)
DavidCrow wrote: It hasn't since day one and likely won't for the foreseeable future.
As far everybody can know(in technical sense) this fact gives to your assumption a very high probability to remain always true.
But this fact does not depend on you, so it is not something you should rely on. The CString documentation doesn't say that IsEmpty() will always be implemented the same as GetLength() . You are -in fact- reverse-engineering the current implementation. Good to learn how it works, but no more than this. You have to discover why the designers did it that way. But code tells you only how it is done.
DavidCrow wrote: ...wrong since GetLength() is not a boolean function
C++ operators are overridable, and C++ itself defines operator! for all integral types, with a precise definition.
I'm not "treating it as boolean". I'm evaluating an integer expression.
C++ is not C. Certain "good C practice" are not valid for C++, especially if you're thinking to generic code (where !!a is often used as a "pseudo operator" to convert whatever A supporting ! into a bool ean)
In any case, the most of all these things are much more matter of taste, than substance. I agree.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Hi All,
I have been asked these question in a telephonic interview:
1) Why some header files have there definitions in itslef and don't have a '.cpp' for definition? Classic examples are vector.h and other STL files. What will be the impact of having definitions in a separate cpp file/
2) What is the disadvantage if I make all my functions inline and inline request is always acknowledged by the compiler?
I told him that recursion is not possible, load time will be more, page faults will be more, binary size will increase. But he was looking for some other things as well.
It will be very much helpful if someone can fulfill these queries with explanatory notes.
BR,
Akash
|
|
|
|
|
1. Most compilers don't support the export so you really need the definition of a template class in with it's declaration of you can't use the template class with arbitrary type parameters. The main impact of having everything in an h file is that it couples the class in the h file more tightly with your code. FREX if the implementation of std::vector changes everything that includes vector has to be recompiled. If export was supported you'd just need to compile vector.cpp and relink (and maybe do that intermediate step thing that EDG does when using exported templates) which would be a lot faster.
2. In addition to your comments the main problem is again dependencies. When you modify your class implementation (if it's all in an h file) you have to recompile ALL the source files that use that class. This can increase build times through the roof for a simple change.
Incidentally recursion would still be possible - a clever compiler could convert your inlined recursion into iteration.
Cheers,
Ash
|
|
|
|
|
thanks Aescleal
|
|
|
|
|
Hello,
I was devolopping a simple COM ATL Server project and when i tried to register the dll it shows me an error with 0x8007007e and telling me the file was found but can't register it.
How could i fix this prob ? All my attempts creating and recrating the projects seems to fail due to that error.
Thank you
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
check that all needed dlls are reachable for the dll. Often it is an debug dll.
Dependency Walker takes that job for me.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Ok i opened my dll with that tool, it told me that i have 2 dlls module hnot found which are ieframe.dll and shlwapi.dll but when i opened the windows\system32 i found those dlls existing so i think that there's sth going wrong and related to Dll Hell
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
Re,
i do install IE8 and all seem going well on Dependency walker but my project still refuse to register the COM's Dll
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
i got no clue, other than Dep Walker, or you mus try an fresh installed Windows to proof that your PC hasnt an defect.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
I'm using Visual Studio 6.0 under Windows Server 2008 besides i have MSV2005 installed too. so maybe it's due to multiple IDE Framework.
But when i create a new blank ATL COM project and i compile it then Try to register the DLL some times it works but when i add a new ATL Object it don't wanna go.
As u said may be i have to reinstall my OS and use one MVS.
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
"s but when i add a new ATL Object it don't wanna go. " looks like dll hell.
You better get rid of the good old VS 6
Deinstall both VS and reinstall only VS2005.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Maybe ask on the COM[^] message board too, in case you haven't yet.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers are evil, EVIL i tell you!! <
|
|
|
|
|
i'm trying to make a new one under the MVS6.0 on another computer (Win 2003 + MVS 6.0) i hope that it ll work.
I posted a message on the COM Board..; ... please wait
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
Ok here some news,
i compiled my project under wind2003 with MVS6.0 only installed and it works, no error message like Error DllServer. All is green and i'm happy .
But may be the question how could we fix the prob of DllRegister under a PC with more than 1 MVS installed.
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
hi,
i am having a service running in vista. it captures the information of the USB devices that are being used in the system.
i am registering for device notification when starting the service using the RegisterDeviceNotification API, however the service is crashing when i am calling UnregisterDeviceNotification API
Pasting the piece of code below....if needed i would also give the values out of debugging.
please could i get some help or hints as to why my service is crashing when i am calling UnregisterDeviceNotification ?
DWORD WINAPI service_ctrl(DWORD dwCtrlCode,DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
{
PDEV_BROADCAST_HDR head = (PDEV_BROADCAST_HDR )lpEventData;
switch (dwCtrlCode)
{
case SERVICE_CONTROL_DEVICEEVENT:
if (dwEventType == DBT_DEVICEQUERYREMOVE)
{
if(head->dbch_devicetype == DBT_DEVTYP_HANDLE)
{
PDEV_BROADCAST_HANDLE db = (PDEV_BROADCAST_HANDLE) head;
DebugLog("Remove Query");
ht_pIter = handleThread.find(db->dbch_handle);
if ( ht_pIter == handleThread.end( ) )
DebugLog("cannot find Thread ID using Handle Value ");
else
{
killThreadFunc(ht_pIter->second.threadHandle,ht_pIter->second.threadID);
DebugLog("after killThreadFunc");
if(!CloseHandle(db->dbch_handle))
{
DebugLog("Problem in Closing Directory Handle.");
}
char error[50] = {0};
if(!UnregisterDeviceNotification(*ht_pIter->second.devNotify))
{
DebugLog("Problem in Unregistering Device notification.");
sprintf(error,"Error Code returned is %d",GetLastError());
DebugLog(error);
}
handleThread.erase(db->dbch_handle);
DebugLog("Thread Terminate Successful");
}
}
return NO_ERROR;
}
break;
}
}
|
|
|
|
|
Why the dereference of the structure field? *ht_pIter->second.devNotify looks a bit suspect - generally you deal with handles not pointers to handles.
Cheers,
Ash
|
|
|
|
|
...and the errors are not in my code
C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\afxwin2.inl(362): error C2039: 'NotifyWinEvent' : is not a member of '`global namespace''
C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\afxwin2.inl(362): error C2660: 'CWnd::NotifyWinEvent' : function does not take 4 arguments
I do not call NotifyWinEvent directly. I have tried to #ifdef out most of the code but still get this error. Module compiles fine in VC++6.0 release/debug, VS2005 release/debug win32/x64, VS2010 debug win32/x64, but fails as above in VS2010 release win32/x64.
I am using default settings to build everything.
ES
|
|
|
|
|
Check the MFC and ATL settings in your Project.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
I have the same problem.
What can be wrong with MFC and ATL settings?
|
|
|
|