|
Friends,
I want to load a text file using fstream (or any other standard method). Then i want to search for certain string in a text file. For example i want to find that how many times the word "codeproject" appears in the text file.
Please tell me the efficient method to do so ?? I asking here to have your advices in this regard. Actually i need to implement this in server side application where speed and efficiency are primary requirements.
|
|
|
|
|
Use a memory-mapped file (e.g., CMemFile). Read the file in chunks, and search for text using CString::Find().
|
|
|
|
|
Well,
the idea is not to compare words but characters and implement something
as state machine.
For the word "codeproject" you expect for 'c'.
if the read character equals to 'c' then you know that you expect for 'o'.
If the read character is not 'o' then you return back to expect for 'c'.
Check the following sample (where the search is case-sensitive)
suppose the file is loaded to a buffer pointed by pData.
char *pStart = "codeproject";
char *p = pStart;
int nFound = 0;
for (int i=0;i<file_length;i++)
{
if (*p == NULL)
{
nFound++;
p = pStart;
continue;
}
if (*p == pData[i])
p++;
else
p = pStart;
}
|
|
|
|
|
Hello,
I need to link my application to an OPC server (write and read data). I have no idea how to do this.
Is there anybody who has a simple example? Is it the same way as using ODBC or is it complete different thing? Do you know any good books or internet links?
Thank you in advance
|
|
|
|
|
Does anyone know how to programmatically disable/enable network adapter card on NT4?
I need to be able to enable or disable the network adapter card programmatically on NT4 for the project I am working on. I am running out of ideas...
thanks in advance.
David.
|
|
|
|
|
Perhaps you could explain what you mean by "disable/enable network adapter card."
|
|
|
|
|
hi, i hv a c function library which require me to pass a callback
function pointer into it. since that parameter cannot accept member
function, i try to solve it by passing static function pointer.
-------------------------------------------------------------------------------------------------
class CXFaceRecognitionDlg : public CDialog
{
// Construction
public:
CXFaceRecognitionDlg(CWnd* pParent = NULL); // standard constructor
static void callback(IplImage* image);
}
void CXFaceRecognitionDlg::callback(IplImage* image)
{
DetectAndDrawFaces( image ); // c function lib
//????but how to update CXFaceRecognitionDlg GUI????
}
-------------------------------------------------------------------------------------------------
but the problem goes on. i need to do some CXFaceRecognitionDlg GUI
update inside the static function. but since static callback function
can only access to static function and variable, there are no way for
me to access the member function and variable of CXFaceRecognitionDlg.
can anyone tell me how can i solve this problem?
thank you.
regards
yccheok
|
|
|
|
|
You need the this pointer in your static callback function!
Just take a look at Why can't I use a member function as a callback? at The Code Project Visual C++ Forum FAQ.
One way is to save the this pointer in a static member variable, like this:
class CXFaceRecognitionDlg : public CDialog
{
public:
CXFaceRecognitionDlg(CWnd* pParent = NULL);
static void callback(IplImage* image);
static CXFaceRecognitionDlg* m_pThis;
};
static CXFaceRecognitionDlg::m_pThis = NULL;
{
...
m_pThis = this;
...
FunctionThatNeedCallback(callback);
...
}
void CXFaceRecognitionDlg::callback(IplImage* image)
{
DetectAndDrawFaces( image );
this->DoSomeMemberFunction(...);
}
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
"You need the this pointer in your static callback function!"
Good answer, but that is true only if you need to access non-static members. The link you provided, to the FAQ, does point this out.
Trust in the code Luke. Yea right!
|
|
|
|
|
According to your question you want to pass a callback to a library function, but your code is not passing a callback to any thing.
This is not passing a pointer to callback.
void CXFaceRecognitionDlg::callback(IplImage* image)
{
DetectAndDrawFaces( image );
}
It sounds more like you are looking for some thing like this:
DetectAndDrawFaces(callback);
If you want a better answer then you need to give at least the prototype for the function requiring the pointer to the call back function.
You are correct that if you are passing a member function pointer it must be a static function pointer. Take a look at qsort() in the MFC Library to see how it is done in C and then see if you can figure out how to pass a static function pointer to qsort() [that will give the answer to your question]. You can also try looking at the articles on subclassing and hooking.
Trust in the code Luke. Yea right!
|
|
|
|
|
For several times I had to put the qustion of how to add a DIALOGBAR into window but nobody have respend then i guessed that is very difficult to do,for that i titled my message Question for the strong
|
|
|
|
|
I do not have the answer, but I do have some sujestions:
(1) Search codeproject (for toolbars, etc...).
(2) Get a copy of the "The MFC Answer Book" by Eugene Kain
or search for the MFC FAQ: which is suppost to be maintained by Scot Wingo, Stringray Division of Rogue Wave Software.
Trust in the code Luke. Yea right!
|
|
|
|
|
try VC Main Menu->Project->Add to Project->Components and Controls
Press it and select Visual C++ components, then you can see dialog bar.
|
|
|
|
|
yes ,but u don't explain how i configure to use it???
|
|
|
|
|
Search on MSDN for TN031. It is a technical article about Control Bars, which is the base of a CDialogBar.
~RaGE();
|
|
|
|
|
It's really simple to add a dialogbar.
first,
Create a Dialog template into the resource editor. Name it IDD_MYDLGBAR or whatever name you want to give to it.
second,
Into your parent windows class (probably your mainframe class),
in MyMainframe.h
CDialogBar mydlgbar;
into MymainFrame.cpp
if(!mydlgbar.Create(this, IDD_MYDLGBAR, CBRS_RIGHT, IDD_MYDLGBAR))
{
return 0; // fail to create
}
where:
first parameter = parent handler
second parameter = id of the dlg template
third parameter = position of the dlgbar CBRS_RIGHT, CBRS_LEFT, CBRS_BOTTOM, CBRS_TOP
last parameter = id of the dlg template
MemLeak
Everything's beautiful if you look at it long enough...
|
|
|
|
|
i thank you MemLeak it work well .
|
|
|
|
|
i want to add in this new DIALOGBAR one Slider and EditBox who show the progression of the Slider,but i have problem because i think that they have two DIALOGBAR in the application the first with the MFC application when it's created and the second who it's the child and i creat it .
|
|
|
|
|
Hi,
For your question with opengl, you can find a lot of stuff out there (web) to help you. Also, you can have some example here on code project. If you want more specific examples of how to use opengl with mfc you can go here:
http://pws.prserv.net/mfcogl/
hope it help you.
Everything's beautiful if you look at it long enough...
|
|
|
|
|
I am trying to have my app monitor the every key stroke. If F6 is press at any time, it should launch? Can anyone guide where I can find out how to do this?
Thank you,
SAK
|
|
|
|
|
If you want your app to be activated when a key is pressed, take a look at the RegisterHotkey[^] function, and its message friend, WM_HOTKEY[^]. You can use the RegisterHotkey function to register a hotkey that, when pressed, sends your window a WM_HOTKEY message. You can then activate your app when you get it.
BTW, F6 is not necessarily a good choice of hotkey, because another app is likely to already be using that key combination as a shortcut. Maybe you should use Ctrl+Shift+F6?
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
Thank you so much for the help..most appreciated.
|
|
|
|
|
In a winform program,I use findwindows and sendmessage to close another winform application successfully,
but when I use it the same way in a console exe in a windows service,it doesn't work!!!
why and how????
lost my way
|
|
|
|
|
That is because the window you are looking for is not on the same desktop as the service. You need to impersonate a user. You might be able to have your service login as a user, but you may just get another desktop.
This gets into a very deep topic of Win Stations and desktops.
|
|
|
|
|
thank you whatever.
So maybe I must use other method to control a win application from a service,Name pipe or tcp connect may be easier for that.
In addition, I create the winform process from that service, but I cann't get the same process ID from findwindows.It seems there are too many limitations in windows service programing.
lost my way
|
|
|
|