Click here to Skip to main content
15,885,435 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to keep track when a dialog is invoked second time.? Pin
Sivaraman Dhamodharan19-Oct-12 0:07
Sivaraman Dhamodharan19-Oct-12 0:07 
GeneralRe: How to keep track when a dialog is invoked second time.? Pin
mbatra3119-Oct-12 0:12
mbatra3119-Oct-12 0:12 
AnswerRe: How to keep track when a dialog is invoked second time.? Pin
Jochen Arndt19-Oct-12 0:31
professionalJochen Arndt19-Oct-12 0:31 
AnswerRe: How to keep track when a dialog is invoked second time.? Pin
ThatsAlok19-Oct-12 2:03
ThatsAlok19-Oct-12 2:03 
AnswerRe: How to keep track when a dialog is invoked second time.? Pin
Sajeesh Payolam19-Oct-12 20:51
Sajeesh Payolam19-Oct-12 20:51 
QuestionHow to use a png or jpg in visual studio? Pin
DanYELL18-Oct-12 16:12
DanYELL18-Oct-12 16:12 
AnswerRe: How to use a png or jpg in visual studio? Pin
Santhosh G_18-Oct-12 20:17
Santhosh G_18-Oct-12 20:17 
Question[Solved] How to Call an x86 3+ Parameter Method Using __fastcall Calling Conentions Pin
Skippums18-Oct-12 12:38
Skippums18-Oct-12 12:38 
I am attempting to call an x86 assembly procedure that takes three parameters, and returns the third parameter to the caller. The following is a simple example of a 3-parameter fastcall attempt:
@Foo@12 PROC
  POP EAX, [ESP]
  RET
@Foo@12 ENDP

And the C++ code that calls it:
C++
#include <iostream>

using namespace std;

extern "C" int __fastcall Foo(int, int, int);

int main(int argc, const char *argv[]) {
    cout << Foo(1, 2, 3);
    cin.get();
    return 0;
}

It is my understanding that the first two parameters are passed in ECX and EDX, respectively, and the remaining parameters are pushed on the stack. The problem is that the return address appears to be pushed to the stack AFTER the third parameter. So with the code above, EAX is populated with the return address, and then I get a memory access error trying to read address 3.

The only way I have been able to get this to work, is to change my assembly to the following:
@Foo@12 PROC
  POP EDX
  MOV EAX, [ESP]
  MOV [ESP], EDX
  RET
@Foo@12 ENDP

Now my simple, one assembly instruction code tripled in complexity. My question: is there some way to force VS2010 to push the return address BEFORE the method parameters, so my first, single-instruction assembly method works as expected? Alternatively, it would also be acceptable if VS2010 took responsibility for pop-ing the third input parameter off the stack (currently, if I don't call POP exactly once, I get a stack corruption error when main exits). In either case, there must be a way to write this method using fastcall calling conventions such that it only takes a single assembly instruction. Thanks for any help!

-- EDIT --
In case anyone cares, the answer is:
@Foo@12 PROC
  MOV EAX, [ESP+4]
  RET 4
@Foo@12 ENDP

Sounds like somebody's got a case of the Mondays

-Jeff


modified 23-Oct-12 18:45pm.

AnswerRe: How to Call an x86 3+ Parameter Method Using __fastcall Calling Conentions Pin
Richard MacCutchan18-Oct-12 23:18
mveRichard MacCutchan18-Oct-12 23:18 
GeneralRe: How to Call an x86 3+ Parameter Method Using __fastcall Calling Conentions Pin
Skippums19-Oct-12 7:07
Skippums19-Oct-12 7:07 
GeneralRe: How to Call an x86 3+ Parameter Method Using __fastcall Calling Conentions Pin
Richard MacCutchan19-Oct-12 22:23
mveRichard MacCutchan19-Oct-12 22:23 
QuestionUsing Make - text books / references wanted Pin
Vaclav_18-Oct-12 4:47
Vaclav_18-Oct-12 4:47 
AnswerRe: Using Make - text books / references wanted Pin
Richard MacCutchan18-Oct-12 7:10
mveRichard MacCutchan18-Oct-12 7:10 
GeneralRe: Using Make - text books / references wanted Pin
Vaclav_18-Oct-12 7:31
Vaclav_18-Oct-12 7:31 
GeneralRe: Using Make - text books / references wanted Pin
Chris Meech18-Oct-12 8:03
Chris Meech18-Oct-12 8:03 
GeneralRe: Using Make - text books / references wanted Pin
Richard MacCutchan18-Oct-12 23:07
mveRichard MacCutchan18-Oct-12 23:07 
GeneralRe: Using Make - text books / references wanted Pin
Richard MacCutchan18-Oct-12 23:00
mveRichard MacCutchan18-Oct-12 23:00 
AnswerRe: Using Make - text books / references wanted Pin
jschell18-Oct-12 9:31
jschell18-Oct-12 9:31 
GeneralRe: Using Make - text books / references wanted Pin
Vaclav_19-Oct-12 5:53
Vaclav_19-Oct-12 5:53 
QuestionCPrintDialog doesn't see the printer Pin
blackbolek18-Oct-12 3:24
blackbolek18-Oct-12 3:24 
QuestionRe: CPrintDialog doesn't see the printer Pin
David Crow18-Oct-12 7:28
David Crow18-Oct-12 7:28 
AnswerRe: CPrintDialog doesn't see the printer Pin
blackbolek18-Oct-12 22:02
blackbolek18-Oct-12 22:02 
AnswerRe: CPrintDialog doesn't see the printer Pin
Brandon-X1200027-Oct-12 11:34
Brandon-X1200027-Oct-12 11:34 
GeneralRe: CPrintDialog doesn't see the printer Pin
blackbolek29-Oct-12 5:58
blackbolek29-Oct-12 5:58 
QuestionOpening a VC++ project into Adobe Flash Builder Pin
002comp18-Oct-12 3:00
002comp18-Oct-12 3:00 

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.