|
Use OpenProcess, VirtualQueryEx, and ReadProcessMemory to access the memory. you are probably only interested int he parts of memory marked as MEM_IMAGE, as that contaisn the code. the other parts are other data.
Pass all this data to the disassembler, which will print out the assembly language
|
|
|
|
|
alternativly just have the source included in a text file with your program and just have it print it like any other text file.
|
|
|
|
|
One thing you have to realise is that the program has no idea what it's source code is, you will need to embed the source code as you would any other string, and then you can display it the same as you would any other string.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Not possible, unless you are storing the code as part of the string table resource. The compiler turns the source code into an object file. In turn, the linker turns the object file into an executable. See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I would like my program to run at set times (for example, every minute at the start of the minute, or every 30 seconds, at either the start of the minute or :30). What is the best way to do this. I dont want to use just "Sleep(6000)" or something like that, because after a few runs, it wont be starting at exactly minute:00. How can I solve this problem??
Thank you
Rihannsu
|
|
|
|
|
Sleep for 1 second then when it wakes up look at the system time and see if you want the program to run.
Look at CTime class members.
Elaine
The tigress is here
|
|
|
|
|
Create a waitable timer - CreateWaitableTimer
Calculate the difference between the time you want to run in the future and NOW and then set the waitable timer - SetWaitableTimer.
If you want to run every 'periodic' amount of time, then calcualte that period in milliseconds and set the period when you SetWaitableTimer.
This would be more eficient then sleeping and waking up constantly.
Read MSDN about the waitable timers for their proper usage.
|
|
|
|
|
Rihannsu wrote:
I would like my program to run at set times...
So how about creating a scheduled task to do just that?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Invalid handle issue for a Service application while using GenerateConsoleCtrlEvent
Description:
I have a non GUI application.
I have an issue with GenerateConsoleCtrlEvent while running the application in Service mode.
The following code raised an "invalid handle" error (GetLastError code 6) while running in Service mode:
BOOL res = GenerateConsoleCtrlEvent( CTRL_BREAK_EVENT, dwProcessId );
The same works without any problem when it is run as a console application.
My architecture is something as follows:
I have a partnet process, which creates multiple child processes for executing specific jobs.
In normal case, the child processes finish their jobs and exit gracefully. But some times (e.g. a shutdown), the parent process want to notify the child process to terminate immediately using CTRL_BREAK_EVENT (GenerateConsoleCtrlEvent).
Further, I give the creation flag CREATE_NEW_PROCESS_GROUP while creating the child process.
The child process is a simple console appliction and which has a console handler.
The annoying part is, the above mechanism works smoothly when i run the mother process as console appliction.
I am not sure if this is the case but, my hunch is that the problem occurs because the Service does not have a console (when running as a service). But how do I give console to the Service application and hide it?
Please help me find a way,
Thanks and regards,
|
|
|
|
|
What would be the Print preview methodology for a application like Windows Paint ?
|
|
|
|
|
Would anyone know the difference between
CPaintDc and CClientDc ?
In what scenario is one preferred over the other ?
|
|
|
|
|
The CPaintDC should only be used while handling the OnPaint member function. I am pretty sure the CPaintDc wraps with a BeginPaint and an EndPaint, whereas the CClientDc is prety much safe to create without those two side effects.
|
|
|
|
|
Really had a tough time finding some sample code to achieve the same . Was wondering if someone has a good article that will demonstate this concept !
|
|
|
|
|
I was reading up on Serialization in conjunction with CObject derived classes in the context of the Document View architecture .
The examples that I read were very basic where in serialize they read in or write the data using the >> or << operators .
Say I have a CDocument derived class that contains 10 link lists and i want this info to be persistant how would i write the Serialize routine .
How would my Doc class know where on link list ends and the other begins ?
Is there a mechanism .
The gurus out there can shower some wisdom !
|
|
|
|
|
*** WARNING ***
I whipped up an example in a few minutes so the code is far from tight. However, it should server as a guide to illustrate how to serialize a linked list of objects from an MFC application.
It would be the same as serializing any object in that the document would iterate the linked list and serialize each of the objects.
For example:
* Let's say you have a class called CTest that has a next pointer to support a linked list of CTest objects:
class CTest : public CObject
{
DECLARE_SERIAL(CTest)
public:
CTest(CString strValue);
CTest();
public:
CString m_strValue;
CTest* m_pNext;
public:
void Serialize(CArchive& ar);
};
* You'll note that it's responsible for serializing itself - just as any object. You could do this serialization from the documents Serialize or from any other function that makes sense for your app.
* The CTest class' implementation might look something like this where it is initialized via being serialized:
IMPLEMENT_SERIAL(CTest, CObject, 1)
CTest::CTest()
{
m_strValue = _T("-1");
m_pNext = NULL;
}
CTest::CTest(CString strValue)
{
m_strValue = strValue;
m_pNext = NULL;
}
void CTest::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << m_strValue;
ar << m_pNext;
}
else
{
ar >> m_strValue;
ar >> m_pNext;
}
}
* As an example of using the document's Serialize (since that's the specific question you had):
void CLinkedListDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ASSERT(m_pHead);
if (m_pHead)
{
for (CTest* pCurr = m_pHead; pCurr != NULL; pCurr = pCurr->m_pNext)
{
pCurr->Serialize(ar);
}
}
}
else
{
m_pHead = new CTest();
m_pHead->Serialize(ar);
CTest* pCurr = m_pHead;
while (pCurr->m_pNext)
{
CTest* pNext = new CTest();
pNext->Serialize(ar);
pCurr->m_pNext = pNext;
pCurr = pNext;
}
}
}
* Several things to note here
* When storing, note how I simply walk the linked list and call the object's Serialize function for each object
* When loading, note how I use the stored CTest::m_pNext member only to tell me that another CTest object is in the file. That way I know to instantiate a blank CTest and then call CTest::Serialize to read in its values until I reach a CTest object that has a m_pNext value of NULL.
Cheers,
Tom Archer - Archer Consulting Group
"So look up ahead at times to come, despair is not for us. We have a world and more to see, while this remains behind." - James N. Rowe
|
|
|
|
|
|
Anonymous wrote:
Say I have a CDocument derived class that contains 10 link lists...
Are those CList objects?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I'm updating a MFC app by, among other things, adding a second dockable toolbar to it. Its original toolbar has been there a long time and it works fine: in particular, if you move it around in the frame and close the application, it turns up in the same location you left it the next time the application is opened again. (Its information is preserved and retrieved with a single pair of SaveBarState and LoadBarState calls.)
Not wanting to meddle with what works, I created the second toolbar by basically copying the code which implemented the first. It gets created at the same point in code, with the same properties, in the same way. By and large it works well, but it falls down in one important respect; the new toolbar always appears docked in the upper left corner position whenever the application starts up, even if you moved it somewhere else.
Has anyone else experienced this? Do SaveBarState and LoadBarState have some limitation with multiple toolbars I don't know about? Or is there some better mechanism for managing these which I don't know about?
Ron Ritchie
|
|
|
|
|
It may be a problem with your toolbar IDs. MFC uses the constant AFX_IDW_TOOLBAR for the main toolbar ID. It also uses a couple of successive IDs for things like the status bar, dialog bar, etc.
I would try setting the ID of the 2nd toolbar to AFX_IDW_TOOLBAR + 20 or something similar. (pass the ID via the CToolBar::Create call)
If you search the vc++ folder for AFX_IDW_TOOLBAR, you should see all the defines/constants I'm referring to.
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
That was very helpful. It didn't solve the whole problem, but knowing to search for that toolbar ID proved the key to solving the rest. Thanks!
Ron Ritchie
|
|
|
|
|
Hi Everyone!
I have a problem! How can I run an EXE directly from memory?
Thanks for any reply!
|
|
|
|
|
Yeah you can... but you have to implement your own PE loader.
That's quite difficult so I propose that you dump the exe file to the disk and execute it the normal way.
Don't try it, just do it!
|
|
|
|
|
Why did you want to run your application in memory?
It's not a normal operation. Don't do this..
---------------------------
Auto Debug for Windows
http://www.autodebug.com/
|
|
|
|
|
Does anyone know a discussion of the actual overhead imposed by using a SetWindowsHookEx(WH_CALLWNDPROC / WH_CALLWNDPROCRET) for a single thread?
I'm currently writing a test app for my specific case, but I'd be interested in what others have to say.
Pandoras Gift #44: Hope. The one that keeps you on suffering. aber.. "Wie gesagt, der Scheiss is' Therapie" boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
Hello,
Just a short question really. Could anyone either tell me how or give me a link to a webpage that explains how you turn an image using DirectDraw.
Thanks
|
|
|
|