|
Nelek wrote: I am not asking for code, just for opinions, tips or a bit orientation. I am still searching for info and making tiny tests, but if you know a good place with documentation any link will be wellcome.
Find a copy of this book[^]. It can save you a lot of headaches down the road
|
|
|
|
|
i was trying to figure out why my code tried to open the wrong files and after some debugging it turned out to be because of these two lines:
...
::strncpy(buffer, folder, sizeof(buffer));
::PathRemoveFileSpec(buffer);
...
buffer here was "C:\Documents and Settings\Administrator\My Documents" before and "C:\Documents and Settings\Administrator" after, even though it should remove the trailing file name only if it really is a file.
the msdn documentation for the function (at http://msdn.microsoft.com/en-us/library/bb773748(VS.85).aspx[^]) doesn't mention that as far as i could see
|
|
|
|
|
That kinda makes sense, if you think about it. If the function does not actually check to see if the filepath is valid, it has no idea if the path:
C:\Documents and Settings\Administrator\My Documents - refers to a directory, or to a file called "My Documents".
Not that I would expect it to work that way, but it makes sense if the function is "dumb".
Also, using sizeof(buffer) in that manner is unsafe - it will not work as expected on Unicode builds (although neither would strncpy as opposed to _tcsncpy ), and it may leave the resulting string in buffer without a NUL -terminator if the contents of folder are too long.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
sashoalm wrote: ...even though it should remove the trailing file name only if it really is a file.
Says who?
Why not call PathIsDirectory() before calling PathRemoveFileSpec() ?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am sure this behaviour is "by design". Finding out if a path refers to a file or a directory is "very" expensive as it requires at least one and probably multiple disk reads. Simply scanning the string and stripping off the text after the final directory separator is likely to be 100's of times faster.
|
|
|
|
|
Hi All,
I have an old vc++ application which was running perfectly fine on Win NT and Win XP. (I use VC++ 7 to build it)
Now i am running it on Vista.
While opening one perticular view it throws an unhandelled exception and simply dies.
After debugging I found that the exception is being thrown when i try to add buttons to my dynamic tool bar.
The code structure is :
There is a CDynamicToolBar derived from CToolBar
class CDynamicToolBar : public CToolBar
When I need to instantiates the dynamic tool bar i do something like this
m_wndToolBar = new CDynamicToolBar ()
if (!m_wndToolBar->CreateEx(this))
{
m_wndToolBar->Load();
Its in the Load() ,where I add the buttons array
I am getting the exception in Vista while there is no problem in XP
GetToolBarCtrl().AddButtons(iButtonCount+iSeptratorCount, pAToolBarButton);
I have tried removing the code related to the tool bar and running the view without it on Vista.
It gives no problem at all (except,i don't get the toolbar of course)
I am completely at loss here...
Anyone with ideas /suggestion/ solutions
only dead fish swim with the stream
|
|
|
|
|
what! no replies!
Anyway the problem is solved.
in the line
GetToolBarCtrl().AddButtons(iButtonCount+iSeptratorCount, pAToolBarButton);
pAToolBarButton is an array of TBBUTTON structure where each structure represents a button on the tool bar.
It seems that each field in TBBUTTON structure must be properly initialized in Vista. Well this is a good programming practice anyway.
But in case you have left the less used fields like TBBUTTON.dwValue uninitialized, it would ignored when you application runs on XP.
Where as in Vista you get an exception when you try to add the buttons to your toolbar control.
only dead fish swim with the stream
|
|
|
|
|
Can any one of you help me how to implement a MD5 algorithm in C++
Thanks
Nandu
|
|
|
|
|
Surely you jest:
I could do this if I only had a search engine
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
RFC-1321 describes the MD5 steps and includes the original reference implmentation.
http://www.rfc.net/rfc1321.html[^]
I assume you want to do this for educational purposes. Otherwise it would be better to use Microsoft cryptographic service providers.
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks for your prompt reply.
-Nandu
|
|
|
|
|
|
With the above link i am able to ecoding, but can any help me to decoding it.
Thanks
-Nandu
|
|
|
|
|
Nandu_77b wrote: any help me to decoding it
MD5 is a hash, it only goes from plain-text to hashed data. It does not go the other way. If you want to go back and forth, you need to look at cryptography, not hashing.
Judy
|
|
|
|
|
HI
Any can help me, to get the users home directory in windows. Is there any win32 API avilable for it?
Home directory means ::C:\Documents and Settings\<userid>
Please help with possible ways to get this thro program.
Thanks,
Nandu
|
|
|
|
|
Home dir:C:\Documents and Settings\userid
|
|
|
|
|
|
You could also use GetEnvironmentVariable:
TCHAR tcDirName[_MAX_PATH];
GetEnvironmentVariable(_T("userprofile"), tcDirName, _MAX_PATH);
This environment variable is set when the user logs on.
Note that it is not always on the same drive as the system (C .
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Thanks for your reply, is there any specific win32 API who will do this job. As i need to use this in win32 API programming, not in MFC or higher framwork.
-Nandu
|
|
|
|
|
That is Win32 API call.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Nandu_77b wrote: is there any specific win32 API who will do this job
Yes, use
GetUserProfileDirectory - retrieves the path to the root directory of the specified user's profile.
For e.g. C:\Documents and Settings\Nibu
A function which uses ths API to return current process user home dir...
#include "Userenv.h"
#pragma comment(lib, "userenv.lib")
CString GetUserHomeDir()
{
TCHAR szHomeDirBuf[MAX_PATH] = { 0 };
HANDLE hToken = 0;
VERIFY( OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &hToken ));
DWORD BufSize = MAX_PATH;
VERIFY( GetUserProfileDirectory( hToken, szHomeDirBuf, &BufSize ));
CloseHandle( hToken );
return CString( szHomeDirBuf );
}
Then there are other functions too which might interest you, like...
GetAllUsersProfileDirectory
GetDefaultUserProfileDirectory
GetProfilesDirectory
Look up these in MSDN for more information.
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
modified on Wednesday, June 4, 2008 11:55 PM
|
|
|
|
|
Is the given code correct?
I am wondering about the return instruction, in which a CString object is created:
return CString( szHomeDirBuf );
In my opinion this object will be already destroyed while the function returns.
When accessing from caller, the object is already invalid.
CString res = GetUserHomeDir();
Am I wrong?
|
|
|
|
|
Hi
How to get User's gateway IP using VC++ ?.
Is there any VC++ API to find the IE Version ?.
Thanks in advance.
Prabhat Singh
|
|
|
|
|
Use GetAdaptersInfo() .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can somebody tell me the best book to start with COM&ATL Stuff?
|
|
|
|