|
Haha...okay, I like your style (both of writing and of coding), and thanks for your help. Now 3 questions:
1. Why malloc sucks, I don't see any problems with it. New and delete is better when you are creating some objects that have a constructor and a destructor, as they get called automatically, but not if you use malloc. But here I only use strings and string pointers, so why?
2. I already rewrite the code, to use something like:
lpwFolder = (LPWSTR) malloc( (len + 1) * 2 );
Is it wrong? (Apart from not being elegant :=) ).
3. I use _tcslen instead of wcslen, is it better suited here?
Thanks for your help again.
|
|
|
|
|
damir_tk wrote: 1. Why malloc sucks, I don't see any problems with it. New and delete is better when you are creating some objects that have a constructor and a destructor, as they get called automatically, but not if you use malloc. But here I only use strings and string pointers, so why?
I didn't say it sucks You're using C++ so why not take advantage of the much stronger type
safety provided by the language? Using "new", you create a typed pointer so the compiler can
help point out mistakes during development because it knows the pointers type without having
to use the old C-style cast. Use what you want, of course, but I bet you'll find new and delete
much more pleasing to use.
damir_tk wrote: 2. I already rewrite the code, to use something like:
lpwFolder = (LPWSTR) malloc( (len + 1) * 2 );
Is it wrong? (Apart from not being elegant :=) ).
3. I use _tcslen instead of wcslen, is it better suited here?
The only thing I see that's not elegant is mixing the generic "T" types with the hard-coded "W"
types. By using the "T" types you have the advantage of your code working for both UNICODE and
non-UNICODE builds. It also fits the way the Windows APIs are declared.
If you know you are only ever going to use UNICODE then you could just use the "W" string types.
It's just easier to read the code if you stick to one set of types and functions.
This is all just my opinions of course.
Here's another version of your code using all "T" char types and new/delete...
LPTSTR FileHelper::GetFileFullPath( LPCTSTR lpwName )
{
LPTSTR lptFileFullPath;
DWORD LenInChars = ::GetCurrentDirectory( 0, NULL );
++LenInChars;
LPTSTR lpwFolder = new TCHAR[ LenInChars ];
if ( lpwFolder == NULL )
{
return NULL;
}
if ( ::GetCurrentDirectory( LenInChars, lpwFolder ) != 0 )
{
LenInChars = (DWORD)( _tcslen( lpwFolder ) + _tcslen( lpwName ) + 6 );
lptFileFullPath = new TCHAR[ LenInChars ];
if ( lptFileFullPath == NULL )
{
delete[] lpwFolder;
return NULL;
}
}
delete[] lpwFolder;
return lptFileFullPath;
}
|
|
|
|
|
Thank a lot. Point taken.
|
|
|
|
|
I have a property page which is derived from a class (CXYzproperty)
it has 5 TABS . One of the tab page is also derived from (CXYzproperty)
I want to colour the radio & check box in the tab page i tried to use the
OnCtlColor but it dont work . Actully i dont think the message is pumped
to the tab page .
Do anyone know how to do this .??
I found out that the Message WM_CTLCOLOR is not been passed to the Page inside the
Properth sheet . As shown below I have 5 tabs on the property sheet , when i open the
Tab 1 , In the constructor i create a page .The place were Vikas is written , i want
to change color of it ( ther are some radio & check box on that page );
------------------------------
| |
---- ---- ---- ---- --- |
| 1 | 2 | 3 | 4 | 5 | |
|--- ------------------------|
| |
| |
| Vikas |
| |
| |
| |
------------------------------
thanks in advance
-- modified at 7:07 Sunday 12th November, 2006
Vikas Amin
EATON
PUNE
|
|
|
|
|
vikas amin wrote: Vikas Amin
EATON
PUNE
So left Embin?
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
Yes Sir
i have left embin & bombay
Can i know u ?
enjoy
Vikas Amin
EATON
PUNE
|
|
|
|
|
vikas amin wrote: Can i know u ?
We've met on CP before I think. I just remembered your previous signature when I read your name.. Vikas Amin, Embin Technologies, Bombay. Since it was different just asked you if you've shifted to a new location
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
I should admit that u have a good memory
Have a nice day
Vikas Amin
EATON
PUNE
|
|
|
|
|
Hi everyone,
I have a project in VC++ ,it is ClassLibrary project and it has a function that return jbyte *.
I would like to call this function in VB project ,how can I convert jbyte * to byte array ?
I would appreciated for any help .
If there is any document,sampe code or link for "type conversion between VC++ and VB.net "please inform me.
yours sincerely,
Orchid
|
|
|
|
|
ive been working in win32 console apps (c++) and mfc (c++) based stuff, and both of them have a type of dialog, but now how do i create a project that has no dialog interface what so ever, so like when i run it its only visible in the taskman?
i know i could set the console size or dialog size small etc, but none of that stuff.
any simple ways to do this?
/Johannes
|
|
|
|
|
|
Only try Windows Services if you want your program to run under a different session so it continues to run even when the user logs off. If that is what you want, services are the only way to go.
Otherwise, what about ditching MFC and creating a raw Win32 Project as a GUI application, and just declaring your own WinMain function. If you aren't displaying any windows whatsoever, you probably don't need a message loop.
I'm sure there's a way to do it with MFC, so you could keep using CString, etc., but since I have never used MFC I don't know.
Mike
|
|
|
|
|
I dont need it to run when logged off, just have no interface, and it doesnt have to be mfc either as im ok without it.
so from WinMain i clould make it seem like its creating a dialog, but it actualy doesnt, just runs without console or dialog in background?
sounds nice, how would i trick WinMain to have no dialogs?
/Johannes
|
|
|
|
|
You don't have to do anything special; just treat it like a main() function from a console application. It won't create any dialogs unless you tell it to via CreateDialog, CreateWindow, or the MFC equivalent.
So a simple program: (no guarantees this actually works; it is untested)
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
{
FILE *fp = fopen("C:\\test.txt", "wt");
fprintf(fp, "Hello, world!\n");
fclose(fp);
MessageBox(GetActiveWindow(), "Done!", "GUI-less Program", MB_OK);
}
|
|
|
|
|
How should i place that in MS visual c++ in a new win32 console project?
/Johannes
|
|
|
|
|
How should i place that in MS visual c++ in a new win32 console project?
thanks for teh help
/Johannes
|
|
|
|
|
Johpoke wrote: How should i place that in MS visual c++ in a new win32 console project?
You need to create a Win32 GUI project.
|
|
|
|
|
thanks a mil
/Johannes
|
|
|
|
|
In my program can i easily add mfc support?
/Johannes
|
|
|
|
|
hi, this is my first live project. i am naive to VC++. i have to implement AES. As per my knowledge it uses symetric key + cipher for encryption and decryption.i have done a lot of study and getting confused a bit. please guide me how to generate that symetric key of 128 bit length. Is there any API or any self made method for generating this key and what should be my approach ??.Thankx so much in advance.it wud be so kind of u if u plz send me answer at my e-mail id.i have very critical dead lines.plz help.
|
|
|
|
|
|
Detecting mouse buttons itself is quite easy, but there an equaly easy way to detect if the mouse button is being held down for a period of time?
My method is to launch my own message loop, but if an error occurs it would kinda mess up the whole program. Please take a look at my code and if you see any potential probems, please point them out.
do
{
if ( ! ::GetMessage( &msg, 0, 0, 0 ) )
break;
if ( ::CallMsgFilter( &msg, MSGF_SCROLLBAR ) )
continue;
pt = msg.pt;
::ScreenToClient(m_hWnd,&pt);
if (msg.message == WM_LBUTTONUP)
HandleMouseUp(pt);
else if (msg.message == WM_MOUSEMOVE)
HandleMouseMove(pt);
else if (msg.message == WM_TIMER)
{
if ( bFirstRun )
{
bFirstRun = false;
for ( int i=0; i<50; i++ )
{
::Sleep(10);
MSG peek;
if ( PeekMessage(&peek,m_hWnd,WM_LBUTTONUP,WM_LBUTTONUP,FALSE) )
break;
}
continue;
}
HandleMouseDown(pt);
}
else
{
::TranslateMessage( &msg );
::DispatchMessageW( &msg );
}
} while ( msg.message != WM_LBUTTONUP );
|
|
|
|
|
Every time I see the Sleep function in user-interface code I know there has to be a better way. You NEVER, except under most unusual circumstances, want to Sleep in a user-facing thread.
Kudos to you for using CallMsgFilter. Been reading Raymond Chen?
What I would suggest would be rewriting it: (pseudocode)
WM_LBUTTONDOWN:
set a timer for 500ms
WM_LBUTTONUP:
kill the timer
WM_TIMER:
kill the timer
post / send / call a OnMouseHold handler
Much simpler, no Sleep()s, and unless I missed something it should work.
Mike
|
|
|
|
|
Hello,
I'm a newbie in computer programming.
I'm looking for a program help me to change file attributes(Created time,Modified time and last access) like FileDate By T.YogaRamanan.
Here is link :
http://www.codeproject.com/file/FileDate.asp[^]
But I want to ignore its user interface.(No Dialog box , No Text box)
I want to choose file as coding and change file attribute as coding too.
I have tried to read source code of FileDate above.
I still can't do.
Can you help me ?
Thank you.
|
|
|
|
|
Welcome
SetFileAttributes for attributes
SetFileTime for set date and time(your purpose)
SetFileShortName for set shor name
|
|
|
|