|
To be very frank, I don't see any help code in the link.. How do i do this in VC??
|
|
|
|
|
Does anyone know how to install IIS using Sysocmgr.exe?
|
|
|
|
|
Hey everybody.
Here's a C++ question.
I have 2 classes:
template<typename T>
class A_template
{
public:
... other stuff ...
void operator = (T* other){ _obj = other; }
protected:
T* _x;
};
class B : public A_template<C>
{
... some functions ...
};
Now, the problem is that if I have the following line of code:
C* x = CreateC();
B b;
b = x; // <--- compiler returns that there is no possible conversion, but it does, in A ! what am I doing wrong??
Thanks a lot !!!
|
|
|
|
|
Oh,
and the definition of B is:
class B : public A_template<c>.
|
|
|
|
|
assignment operator works like the constructor when it comes to inheritance. You should read more about this.
Also read about:
<br />
using A<T>::operator =;<br />
which should be placed in the declaration of B
|
|
|
|
|
Thanks
I read about what you said, and I understand why the copy assignment is not being derived,
but I can't find anything about the "using A<t>::operator =;".
Can I tell c++ explicitly that I want to use the operator at the base class?
|
|
|
|
|
just put that line in your B implementation and it should work
|
|
|
|
|
Hi,
I want to create a model-less dialog as a child of CFormView class.
what I did is as follow :
m_pDlg = new CMyDlg(this);
if(! m_pDlg->Create(IDD_DIALOG_DIAGRAM, this))
{
::AfxMessageBox(L"An unknown error occurred while creating the window.");
return;
}
I have created a Dialog with the ID of IDD_DIALOG_DIAGRAMbut in my resource editor And also I override the necessary methods to have model-less dialog But It always fail.
When I trace the dialog creation note that the
BOOL bResult = CreateIndirect(hTemplate, pParentWnd, hInst); returns the error.
What is my problem?
|
|
|
|
|
Check the template of your dialog is correct, lso your CMyDlg constructor. Perhaps you should post the code for both parts here.
It's time for a new signature.
|
|
|
|
|
thanks I found the mistake the uninitialized RichEdit was causing the error.
|
|
|
|
|
Who can tell me how to use the "Detours" to Hook WriteProcessMemory?
I want to get WriteProcessMemory the memory of information.
<br />
BOOL WINAPI MyWriteProcessMemory(<br />
HANDLE hProcess,
LPVOID lpBaseAddress,
LPVOID lpBuffer,
DWORD nSize,
LPDWORD lpNumberOfBytesWritten
);<br />
DETOUR_TRAMPOLINE(BOOL WINAPI CopyWriteProcessMemory(HANDLE, LPVOID, LPVOID, DWORD, LPDWORD), WriteProcessMemory);<br />
BOOL WINAPI MyWriteProcessMemory(<br />
HANDLE hProcess,
LPVOID lpBaseAddress,
LPVOID lpBuffer,
DWORD nSize,
LPDWORD lpNumberOfBytesWritten)
{<br />
BOOL nResult=WriteProcessMemory(hProcess,lpBaseAddress,lpBaseAddress,nSize,lpNumberOfBytesWritten);
MessageBoxA(NULL,(LPCTSTR)lpBaseAddress,"Hook!",MB_OK); <br />
return nResult;<br />
}<br />
this's my code ,but is not work.
|
|
|
|
|
rockago wrote: but is not work
what exactely do you mean ?? - what are the signs, symptoms and/or error codes - we cant read your mind and formulate an answer based on not knowing what 'not working' means
'g'
|
|
|
|
|
<br />
#include "stdafx.h"<br />
#include "DetourDll.h"<br />
<br />
#include "detours.h"
<br />
#pragma comment(lib,"detours.lib")<br />
<br />
BOOL WINAPI MyWriteProcessMemory(<br />
HANDLE hProcess,
LPVOID lpBaseAddress,
LPVOID lpBuffer,
DWORD nSize,
LPDWORD lpNumberOfBytesWritten
);<br />
DETOUR_TRAMPOLINE(BOOL WINAPI CopyWriteProcessMemory(HANDLE, LPVOID, LPVOID, DWORD, LPDWORD), WriteProcessMemory);<br />
BOOL WINAPI MyWriteProcessMemory(<br />
HANDLE hProcess,
LPVOID lpBaseAddress,
LPVOID lpBuffer,
DWORD nSize,
LPDWORD lpNumberOfBytesWritten)
{<br />
BOOL nResult=WriteProcessMemory(hProcess,lpBaseAddress,lpBaseAddress,nSize,lpNumberOfBytesWritten);
MessageBoxA(NULL,(LPCTSTR)lpBaseAddress,"Hook!",MB_OK); <br />
return nResult;<br />
}<br />
<br />
BOOL APIENTRY DllMain( HANDLE hModule, <br />
DWORD ul_reason_for_call, <br />
LPVOID lpReserved<br />
)<br />
{<br />
switch (ul_reason_for_call)<br />
{<br />
case DLL_PROCESS_ATTACH:<br />
OutputDebugString("Detour dll Load!");<br />
DetourFunctionWithTrampoline((PBYTE)CopyWriteProcessMemory, (PBYTE)MyWriteProcessMemory);<br />
break;<br />
case DLL_THREAD_ATTACH:<br />
break;<br />
case DLL_THREAD_DETACH:<br />
break;<br />
case DLL_PROCESS_DETACH:<br />
OutputDebugString("Detour dll Exit!");<br />
DetourRemove((PBYTE)CopyWriteProcessMemory, (PBYTE)MyWriteProcessMemory);<br />
break;<br />
}<br />
return TRUE;<br />
}<br />
<br />
<br />
LRESULT WINAPI MsgProc(int code, WPARAM wParam, LPARAM lParam)<br />
{<br />
return(CallNextHookEx(NULL,code,wParam,lParam));<br />
}<br />
<br />
EXPORTS<br />
;dll export functions<br />
MsgProc<br />
<br />
<br />
#ifdef DETOURDLL_EXPORTS<br />
#define DETOURDLL_API __declspec(dllexport)<br />
#else<br />
#define DETOURDLL_API __declspec(dllimport)<br />
#endif<br />
<br />
LRESULT WINAPI MsgProc(int code, WPARAM wParam, LPARAM lParam);<br />
this's my all code.
When I use the "WriteProcessMemory" after the injection, but it won't execute "MessageBoxA"
|
|
|
|
|
well, your formatting sucks for a start .. I cant quite put my finger on whats wrong .. looking at examples, I cant help feel that this (your code),
BOOL WINAPI MyWriteProcessMemory(
HANDLE hProcess,
LPVOID lpBaseAddress,
LPVOID lpBuffer,
DWORD nSize,
LPDWORD lpNumberOfBytesWritten)
{
BOOL nResult=WriteProcessMemory(hProcess,lpBaseAddress,lpBaseAddress,nSize,lpNumberOfBytesWritten);
MessageBoxA(NULL,(LPCTSTR)lpBaseAddress,"Hook!",MB_OK);
return nResult;
}
should be this :-
BOOL WINAPI MyWriteProcessMemory(
HANDLE hProcess,
LPVOID lpBaseAddress,
LPVOID lpBuffer,
DWORD nSize,
LPDWORD lpNumberOfBytesWritten)
{
BOOL nResult=CopyWriteProcessMemory(hProcess,lpBaseAddress,lpBaseAddress,nSize,lpNumberOfBytesWritten);
MessageBoxA(NULL,(LPCTSTR)lpBaseAddress,"Hook!",MB_OK);
return nResult;
}
CopyWriteProcessMemory has replaced WriteProcessMemory so calling WriteProcessMemory I dont think will work. Ive seen 'Real_' used instead of 'Copy', to make it a bit more obvious .. ie instead of
CopyWriteProcessMemory you would have Real_WriteProcessMemory
Obviously that means you start with
DETOUR_TRAMPOLINE(BOOL WINAPI Real_WriteProcessMemory(HANDLE, LPVOID, LPVOID, DWORD, LPDWORD), WriteProcessMemory);
Other than that I cant spot anything dramatically wrong ..
You might want to compare your code with this http://code.google.com/p/dxhook/source/browse/trunk/dxhook.cpp?r=4[^] to see if it helps
'g'
|
|
|
|
|
thx.
But when I taked "WriteProcessMemory "to" Real_WriteProcessMemory", After injection into or unable to carry out "MessageBoxA."
|
|
|
|
|
|
rockago wrote: MessageBoxA(NULL,(LPCTSTR)lpBaseAddress,"Hook!",MB_OK);
lpBaseAddress is a pointer to void, I have no idea what it is pointing to but unless it's a string of ASCII characters you cannot cast it to LPCTSTR and expect MessageBoxA() to work.
It's time for a new signature.
|
|
|
|
|
if thats what his issue is Ive been wasting my breath !!! oh well ..
|
|
|
|
|
I think a bit of lateral thinking and lots of guesswork is needed here. I only noticed that because he mentioned the MessageBox call in two posts. I've no idea what the rest of it is, or is supposed to be, doing.
It's time for a new signature.
|
|
|
|
|
Hi, I have written a function to cause a thread to wait for a given time. But the problem is that If this function is called, I notice from task manager (in Windows) that the CPU Usage shoots up to 100 percent. But if I rather use the Windows function Sleep(), the CPU Usage falls back to around 2%, 3%, and 4%. The following is how I wrote the function, with the header file <time.h> included.
void Wait(clock_t milliseconds)
{
clock_t delay_time = milliseconds + clock();
while (delay_time > clock())
;
return;
}
I don't know why my CPU usage shoots up to 100% when I use this function rather than Windows Sleep() function. I don't want my application to assume the use of Windows. Please help.
|
|
|
|
|
Dan_K wrote: that the CPU Usage shoots up to 100 percent
No wonder: you're using the CPU, aren't you?
That's not the best way to pause an application on a multitasking system.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You should upgrade your hardware. If you buy a dual-core system, it will become twice as efficient: the CPU load will be around 50%. Or go for a quad-core and see it sitting idle with a load of a mere 25%.
If you don't like that idea, you should either use a sleep function or a timer.
FWIW: you could do both to make absolutely sure.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Your CPU usage goes to 100% simply because you are actually doing something: the while loop and the checks are operations done by the CPU, and in your case without interruption, so the CPU is always busy.
|
|
|
|
|
Cedric Moonen wrote: so the CPU is always busy
It's the ancient wise's rule: "keep the CPU busy and the brain sleeping..."
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
All the CPU cycles are going to reaing the clock over and over. If you want to be independant of windows, the function uSleep is Unix the equivelent of Sleep, just add
<br />
#ifndef WIN32<br />
#define Sleep(x) uSleep(x * 1000)<br />
#endif<br />
<br />
To the top of your code
|
|
|
|
|