Click here to Skip to main content
15,907,687 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to find if two region (made by CRgn) have intersection or not? Pin
Stuart Dootson19-Feb-09 12:09
professionalStuart Dootson19-Feb-09 12:09 
GeneralRe: How to find if two region (made by CRgn) have intersection or not? Pin
A&Ms25-Feb-09 21:33
A&Ms25-Feb-09 21:33 
QuestionWebcam and Line tracking Pin
sebogawa19-Feb-09 11:51
sebogawa19-Feb-09 11:51 
AnswerRe: Webcam and Line tracking Pin
Stuart Dootson19-Feb-09 12:06
professionalStuart Dootson19-Feb-09 12:06 
QuestionHow To Execute Raw Binary From Within A Binary Pin
V3RO19-Feb-09 11:04
V3RO19-Feb-09 11:04 
GeneralRe: How To Execute Raw Binary From Within A Binary Pin
Luc Pattyn19-Feb-09 11:39
sitebuilderLuc Pattyn19-Feb-09 11:39 
AnswerRe: How To Execute Raw Binary From Within A Binary Pin
Stuart Dootson19-Feb-09 12:00
professionalStuart Dootson19-Feb-09 12:00 
AnswerRe: How To Execute Raw Binary From Within A Binary Pin
Rick York19-Feb-09 12:51
mveRick York19-Feb-09 12:51 
Several years ago I had the task of writing a machine code generator for a script engine. In other words, a JIT mechanism to accelerate the execution speed of our scripts. I didn't have the first clue of how to even start but I figured out a test for the proof of principle.

First, I decided to implement a simple little function. It doesn't really matter what this is but it needs to be simple. Here is one to compare two integers :

int CompareValues( int valueA, int valueB )
{
    int rc = 0;
    if( valueA < valueB )
        rc = -1;
    else if( valueA > valueB )
        rc = 1;
    return rc;
}

Then I defined a type that is a pointer to a function with that prototype signature :

typedef int (*CompareFunc)( int valueA, int valueB );

Next I wrote a test program to do something like the following :

int TestMethod()
{
    CompareFunc func = CompareValues;
    int valueA = 42;
    int valueB = 96;
    int returnValue = (*func)( valueA, valueB );
    return returnValue;
}

The next step is a little more involved. You have to go to the settings for your project and in the C++ section select Output Files and then enable the Assembly, Machine Code, and Source option. Now rebuild your test app and take a look at the machine code for the CompareValues function. Copy the machine code bytes and place them into an array of BYTEs :

static BYTE codeBytes[] = { ... };

Now you should be able to "invoke" this code with something like the following :

int TestMethod()
{
    CompareFunc func = (CompareFunc)codeBytes;
    int valueA = 42;
    int valueB = 96;
    int returnValue = (*func)( valueA, valueB );
    return returnValue;
}

and that's basically it. You will probably have to experiment a little to make things work right like possibly using assembly statements to push your variables onto the stack before invoking the function and things like that.

It has been a long time, ten years or so, since I did this but I used a technique just like this to get started. My JIT compiler would emit the code bytes into a buffer and then execute them using a mechanism nearly identical to this.

You should be able to get the basics of this down fairly quickly. If you can't then this could be a very difficult project for you to accomplish.
GeneralRe: How To Execute Raw Binary From Within A Binary Pin
V3RO19-Feb-09 13:30
V3RO19-Feb-09 13:30 
QuestionPlease please help with this simple Q from a C++ newbie Pin
meixiang619-Feb-09 10:11
meixiang619-Feb-09 10:11 
AnswerRe: Please please help with this simple Q from a C++ newbie Pin
Stuart Dootson19-Feb-09 10:35
professionalStuart Dootson19-Feb-09 10:35 
GeneralRe: Please please help with this simple Q from a C++ newbie Pin
meixiang619-Feb-09 10:53
meixiang619-Feb-09 10:53 
GeneralRe: Please please help with this simple Q from a C++ newbie Pin
Stuart Dootson19-Feb-09 11:42
professionalStuart Dootson19-Feb-09 11:42 
GeneralRe: Please please help with this simple Q from a C++ newbie Pin
meixiang619-Feb-09 12:00
meixiang619-Feb-09 12:00 
GeneralRe: Please please help with this simple Q from a C++ newbie Pin
Stuart Dootson19-Feb-09 12:17
professionalStuart Dootson19-Feb-09 12:17 
GeneralRe: Please please help with this simple Q from a C++ newbie [modified] Pin
meixiang619-Feb-09 14:39
meixiang619-Feb-09 14:39 
GeneralRe: Please please help with this simple Q from a C++ newbie Pin
David Crow19-Feb-09 17:08
David Crow19-Feb-09 17:08 
GeneralRe: Please please help with this simple Q from a C++ newbie Pin
Stuart Dootson19-Feb-09 21:43
professionalStuart Dootson19-Feb-09 21:43 
Questionurgent : I need help Pin
D_Isaac19-Feb-09 9:38
D_Isaac19-Feb-09 9:38 
AnswerRe: urgent : I need help Pin
CPallini19-Feb-09 11:01
mveCPallini19-Feb-09 11:01 
GeneralRe: urgent : I need help Pin
Luc Pattyn19-Feb-09 11:41
sitebuilderLuc Pattyn19-Feb-09 11:41 
GeneralRe: urgent : I need help Pin
led mike19-Feb-09 11:44
led mike19-Feb-09 11:44 
GeneralRe: urgent : I need help Pin
Luc Pattyn19-Feb-09 11:54
sitebuilderLuc Pattyn19-Feb-09 11:54 
GeneralRe: urgent : I need help Pin
led mike19-Feb-09 11:56
led mike19-Feb-09 11:56 
GeneralRe: urgent : I need help Pin
Luc Pattyn19-Feb-09 12:01
sitebuilderLuc Pattyn19-Feb-09 12:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.