|
|
It's been a while since I've done a lot of C++, more C# these days
Isn't there something like strstr?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
yea, but i cant understand how it works, i mean they ask you for chars instead of ints I don't know how can i use it for doing this work.
|
|
|
|
|
I see what you are trying to do. Let me take a look here
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Have you looked at strncpy[^]?
That might be your ticket. Have the source string be the third character in your main string, and the length be the 5 - 3 + 1 = 3. Something along those lines.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Thanks it looks like the strncpy would work fine. but i have a problem
i have this:
char startup[MAX_PATH];
strcpy(startup, _pgmptr);
char startupnew[MAX_PATH];
strncpy(startupnew,startup,(int)(strstr(startup,"myapp.exe")-startup));
What i wanted to do was taking my app's startup path with the filename thing 'myapp.exe'. So i did this but the problem is that now startupnew, which is what i want is like: C://user/ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ until completing the MAX_PATH, but you know in a general case I wont know the actual length of the startup path. So what can i do in this case.
I want to delete this ÌÌÌÌÌÌÌÌÌÌÌ-thing.
|
|
|
|
|
letueros wrote: Thanks it looks like the strncpy would work fine.
Except it is not C++. If you are using a string object, it has the appropriate method(s).
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
What about std::string substr() function?
string substr( size_type index, size_type length = npos );
std::string i_am_a_string = "hi how r u";
std::string i_am_another_string = i_am_a_string.substr(3, 3);
Hope it helps!
|
|
|
|
|
oh, almost forgot:
char* i_am_a_char_pointer = i_am_another_string.c_str();
|
|
|
|
|
You could use CString::Mid()[^] also. See the code snippet.
CString csString = "hi how r u";
CString csExtracted = csString.Mid( 3,
3 );
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Hey everybody!
I wrote an application that performs global hooking on WH_GETMESSAGE to get clipboard hooking.
Now, I know that application doesn't have to use WM_PASTE while pasting, but I'm trying to get what I can with that.
The problem is that I'm getting WM_PASTE from Notepad, but not from anywhere else!
I read in a different forum that WordPad also uses WM_PASTE for pasting, but it doesn't seem to work in my case.
I also read that it is better hook WH_CALLWNDPROC than WH_GETMESSAGE to WM_PASTE, but when I'm hooking WH_CALLWNDPROC, I am not getting any WM_PASTE messages, not even from notepad.
Anyone have any ideas why I'm not getting WM_PASTE from WordPad (or any windows controls, like pasting to the "run" window) ???
Thanks a lot for your help!!!!!
|
|
|
|
|
Green Fuze wrote: I also read that it is better hook WH_CALLWNDPROC than WH_GETMESSAGE to WM_PASTE, but when I'm hooking WH_CALLWNDPROC, I am not getting any WM_PASTE messages, not even from notepad.
I just tried WH_CALLWNDPROC and it is working fine in the case of wordpad also. Can you paste the hook procedure you wrote...??
Why you want to hook paste operation??? Also in all case WM_PASTE need not to come such as a pate operation in a custom created window.
|
|
|
|
|
First of all thanks a lot for your help!!! (really!)
Here is the code I'm using in the DLL:
The code to register the hook:
<br />
void _declspec(dllexport) __stdcall registerHook(void)<br />
{<br />
hHook = SetWindowsHookEx(WH_CALLWNDPROC, MsgHookProc, hHookDLL, 0);<br />
}<br />
Here is the code of the MsgHookProc() callback function:
<br />
LRESULT CALLBACK MsgHookProc(int nCode, WPARAM wParam, LPARAM lParam)<br />
{<br />
if(nCode >= 0)<br />
{<br />
LPMSG m = (LPMSG)lParam;<br />
<br />
switch(m->message)<br />
{<br />
case WM_PASTE:<br />
case WM_RENDERFORMAT:<br />
case WM_RENDERALLFORMATS:<br />
MessageBox(NULL, L"Oh Yeah!", L"Paste", 0);<br />
break;<br />
<br />
case WM_COPY:<br />
OutputDebugString(L"Copy!");<br />
break;<br />
<br />
case WM_CUT:<br />
OutputDebugString(L"Cut!");<br />
break;<br />
}<br />
}<br />
<br />
return CallNextHookEx(hHook,nCode,wParam,lParam);<br />
}<br />
For your question of why I want to hook paste operation, well I'm a computer science student and I want to get a job in C++ development, I usually wrote .Net, so I was looking for a project to get my hands dirty and a bit of a challenge.
So I'm writing (well... trying to write ) a global copy/paste encrypter/decrypter.
Thanks again for your help!
|
|
|
|
|
Green Fuze wrote: LPMSG m = (LPMSG)lParam;
This the problem. If you are hooking the message using the WH_CALLWNDPROC , the LPARAM in the call back function is actually a pointer to CWPSTRUCT .
so change the code as follows..
PCWPSTRUCT pstInfo = (PCWPSTRUCT)lParam;<br />
switch(pstInfo->message)<br />
{<br />
.....<br />
}
Green Fuze wrote: a global copy/paste encrypter/decrypter.
Sorry I didnt understand the concept. If you dont mind can you explain( Just because am curious ).
Good Luck
|
|
|
|
|
Thanks a lot !!!
Using this method it works great in WordPad and windows controls, but using this method it doesn't work in notepad (pretty weird...).
WH_CALLWNDPROC should hook SendMessage(), so how come it misses the notepad which for sure gets WM_PASTE?
About the copy/paste encrypter/decrypter:
As we know it's really simple to create a clipboard viewer, meaning, every application can see what you're copying to the clipboard.
So every application can see what you're copying to the clipboard and theoretically can do malicious stuff with it.
So using the copy/paste encrypter/decrypter, you can encrypt anything you copy and decrypt anything you paste.
I know it might be a bit useless, but it's just for a bit of training....
Thanks again for your help!
|
|
|
|
|
Hi
I am writing this to help others who will also have the same problem
Creating worker thread :
CWinThread *pThread = AfxBeginThread(&MyThread,(LPVOID*)ptrParam);
MyThread is the member function of CWorker class,
and its prototype is UINT MyThread( LPVOID pParam ) ;
Now while compiling I am getting this error
Error 4 error C2665: ‘AfxBeginThread’ : none of the 2 overloads could convert all the argument types
We know the function prototype is correct.
MSDN ref :
UINT __cdecl MyControllingFunction( LPVOID pParam ); should be the function prototype.
We are also having the Exact prototype , so what could be the problem.
Solution :
All the Class member function will have one hidden parameter ( ie ) this pointer.
So Actucal function prototype of MyThread is UINT MyThread(CWorker pthis , LPVOID pParam ) ;
becoz of this, compiler gives this error.
To Solve the problem
1) Creating one global wrapper funciton around MyThread()
UINT wrapper(LPVOID pParam)
{
CWorker *p = new(std::nothrow) CWorker ;
if(!p)
return ;
p->MyThread(pParam);
return 0;
}
CWinThread *pThread = AfxBeginThread(&wrapper,(LPVOID*)ptrParam); wil work perfectly.
2) Declaring the member function as static
static UINT MyThread( LPVOID pParam ) ;
Note: static member funciton cant access non static member function and non static data member.
Regards,
WindowsPistha
|
|
|
|
|
There's nothing new about this. It's been discussed on this forum dozens of times, and there are even articles about it.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Yes you are right , I have red the below article before i posting.
It did not talk about , why compiler gives error.
so i thought of sharing here,I want to give something back to codeproject which gives lot of information to me.
http://www.codeproject.com/KB/threads/memberthread.aspx[^]
Regards,
WindowsPistha
|
|
|
|
|
|
Thank you Mr. David
here after i will double check before i posting.
Regards,
WindowsPistha
|
|
|
|
|
Can anyone please explain .....
Usually we use Semaphore or Mutex syncronization techniques to avoid deadlock between 2 or more threads.
Now my query is : Is there any other technique for 64 threads to prevent dead lock?
Thanks in Advance
|
|
|
|
|
Number of threads is irrelevant..
You will use same synchronization concepts to prevent deadlocks.
lakshmiyv17 wrote: Is there any other technique for 64 threads to prevent dead lock?
Why so much threads. There will be huge performance hit!!!
Regards,
Sandip.
modified on Saturday, August 23, 2008 12:49 PM
|
|
|
|
|
If you are using that many threads you may want to reconsider your design. This is one of the many reasons you don't see too many Netware servers around anymore. It was common to see millions of threads during primitive indexing tasks while you waited (sometimes hours) for the nightly index clean ups to finish up on Netware Servers. It was a terrible philosophy to create a thread for every little chore or socket.
If you do a search for IO Completion Ports or IOCP here on code project, you'll find some good information on why you want to limit the thread count to be more in line with the number of processing units the machine has to offer.
I hope that helps.
|
|
|
|
|
I am using the following to load a dll in a Visual C++ 2003 project.
LoadLibrary(_T"mydll.dll"));
mydll.dll is generated by a project within the solution although I have to copy it into the exe's location (or change the filepath string) to get it to load. What I want to know is:
1) Is there some kind of mechanism in Visual Studio which can reference the dll via the dll project instead of the filesystem and
2) consequently, what do I need to do to debug code that is executing from that dll project?
I hope I have worded this well enough to get what I'm trying to do across...
|
|
|
|
|
Klempie wrote: 1) Is there some kind of mechanism in Visual Studio which can reference the dll via the dll project instead of the filesystem and
I dont know what do you mean by this..
But
Klempie wrote: 2) consequently, what do I need to do to debug code that is executing from that dll project?
This can be done.
Steps
1. Put break points in the code that you want to debug.
2. Press F5(debug) on your dll project.
3. It will ask you the executable path
4. Browse and specify the path of the exe which uses this dll.
5. Now perform the action on exe that invokes dll functionality.
I hope that makes sense.
Regards,
Sandip.
|
|
|
|