|
There is nothing exactly like memstr(...) in MFC or in the MS VC++ RTL. The closest things are strstr(...) and and functions like CString::Find(...) .
However, these might not work as you expect, because you said "binary string", and that usually means that NUL characters can be expected in other locations than the end of the string.
Other than taking an existing implementation and copying the source or writing your own implementation, a Q&D way would be to store the locations of all of the non-terminating NUL characters and convert them to some other character and then use a function like strstr(...) (with the strings modified as specified above).
After locating your substrings, you can convert them back by replacing the NUL s you replaced before.
Peace!
-=- James 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! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
As was mentioned before, strstr is the closest thing, but it is limited in that NULL characters terminate the buffers. So I have used this code:
#include <string.h>
char * _memmem(const char *mem, size_t mem_size, const char *sub, size_t sub_size)
{
char *ret = NULL;
char *ptr = const_cast<char *>(mem);
while (ptr && !ret)
{
ptr = reinterpret_cast<char *>(memchr(ptr, *sub, mem_size - (sub_size - 1) - (int)(ptr - mem)));
if (ptr)
{
if (!memcmp(ptr, sub, sub_size))
ret = ptr;
++ptr;
}
}
return ret;
} [edit]
cleaned up the code a little
[/edit]
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
-- modified at 18:12 Monday 21st November, 2005
|
|
|
|
|
Hi,
I have a dialog. I dynamically create some buttons in it.
The problem is with default button.
I always got the same click event (OK button) when I press 'Enter Key', regardless the button that has the focus.
What could be wrong?
Thank you.
- NS -
|
|
|
|
|
NS17 wrote: I always got the same click event (OK button) when I press 'Enter Key', regardless the button that has the focus.
That's the way dialog's are.
Pressing enter in a dialog will result in dialog being closed no matter where the focus is.
You have to override OnOk or try doing some additional scratching in PreTranslateMessage(MSG *pMsg).
PreTranslateMessage is more flexible. MSG structure has got lot's of information regarding a message to be processed.
<marquee direction="up" height="30" scrolldelay="1" step="1" scrollamount="1" hspace="0" vspace="0">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
use the CWnd::SetDefId() function to change the default button...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
It sounds like the dialog manager's idea of the default button has got out of sync with the control that has the focus. If using MFC or ATL, use the GotoDlgCtrl method instead of the SetFocus method to change the focus programmatically.
If you're not using either of these libraries, send your dialog a WM_NEXTDLGCTL message, setting wParam to the handle of the control that you want to get the focus, and lParam to TRUE.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
I use VC++6.0 to create SDI project, my View base on CEditView class. I print out to view a string by GetActiveView()->SetWindowText(CString str), str = str + addstr. The cursor always on top of view. I want the cursor go to end of string str, or view scroll to bottom when I update str.
How to do that ? please help me.
thank !
|
|
|
|
|
Surely it isn't the most efficient way, but I use this and it works!
<br />
this->GetEditCtrl().SendMessage(WM_HSCROLL,SB_LEFT);<br />
this->GetEditCtrl().SendMessage(WM_VSCROLL,SB_BOTTOM);<br />
Matteo
-- modified at 6:56 Monday 21st November, 2005
|
|
|
|
|
I try your way:
this->SendMessage(WM_HSCROLL,SB_LEFT);
this->SendMessage(WM_VSCROLL,SB_BOTTOM);
and
GetActiveView()->SendMessage(WM_HSCROLL,SB_LEFT);
GetActiveView()->SendMessage(WM_VSCROLL,SB_BOTTOM);
but nothing change.
|
|
|
|
|
|
CmyView base on CEditView class, that not support funtion .SetSel() and .ReplaceSel()
|
|
|
|
|
You'll need to call GetEditCtrl() first.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Hi,
I have an application running and I have created a modeless dialog box, named it Log window.
I need this dialog to display in it's edit box, all the log information that the actual application sends.
eg:
The actual application opens files, writes to it, closes it.
The log windows should print "File opened succesfully", "abcd data written to file", "File closed" etc.
With whatever info I have, I think I will create some thread which will continuously read a global CString and keep updating the edit box in log window. But, will this slow down the application as the thread is continously reading the string.
Another option is to call a update_log() function after each operation and this function updates the log.
These are just ideas and I am not very sure of how to implement these or anything better.
Is there a better method . how ??
please help!!
- KK
|
|
|
|
|
Hello.
I suggest you do like this:
Prepare the text line (to be logged) in your main program.
Send it to the modeless dialog by means of a SendMessage-command.
Set the message ID to something higher than VM_USER, in order to aviod conflict with the ordinary Windows messages.
Track that message ID in the modeless dialog and display the text.
|
|
|
|
|
""Prepare the text line (to be logged) in your main program"" - OK
""Send it to the modeless dialog by means of a SendMessage-command."" - not familiar with SendMesage - will find out.
""Track that message ID in the modeless dialog and display the text."" - How. Should some thread be running to display the meesage whenever a new message comes?
- KK
|
|
|
|
|
As far as i understand if u want to have
every minute update in the Log Screen (dialog)
then u need to have a dedicated thread working
behind it .
A thread wont be so costly for this work just
u need to suspend the thread for some small time
if it aquires more resources.
else SendMessage is fine
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Hello.
I assume your modeless dialog has got a Windows message loop.
If that's the case, then the logging text will come as a message in the standard message loop.
So all you have to do in the modeless dialog, is catch the specific ID (the ID you gave when you sent the logging message), get the message and then display it.
There is no need for an explicit thread in your modeless dialog.
I'm sure it will get clearer as you investigate the SendMessage func.
Unfortunately, I don't have the time to give you an example.
But search in CP for SendMessage, I'm sure you will get a lot of hits on the subject.
Good luck.
Kakan
|
|
|
|
|
I got it working. Thanks a lot.
BTW, in class wizard, I could not see OnMessage(). I had to type manually in MesageMap. Why ?
- KK
|
|
|
|
|
Great! That's the way to do it.
I don't know why MS have hidden OnMessage in ClassWizard.
Keep up the good programming!
Kakan.
|
|
|
|
|
kk_vp wrote: BTW, in class wizard, I could not see OnMessage(). I had to type manually in MesageMap. Why ?
Probably because the message you wanted to process is unknown to ClassWizard.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Can anybody tell me how can i acces the first bytes at the entrypoint of an exe. I know the PE layout, format, but i don't know how i can translate the entrypoint to fileoffset and HOW i read those bytes?
I'm waiting for any kind of suggestion (or sample code).
|
|
|
|
|
What are you trying to accomplish by modifying an EXE directly?
I can't think of a valid reason for doing so, especially wanting to modify the entry point. Your post (and the previous one) sounds like you want help writing a virus.
Software Zen: delete this;
|
|
|
|
|
I want to write a tool like PEid's PE signature viewer. A tool for compiler detection (by signature bytes).
|
|
|
|
|
Does this tool detect the compiler or the linker?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
this tool will try to detect the compiler (and the cryptor or exe modifier)
|
|
|
|