|
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:
#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.
|
|
|
|
|
I'm not sure where you got your information but as far as I know, all arguments are pushed onto the stack when calling any function from C/C++. This MSDN page[^] would seem to confirm that.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
On the page you quoted, it says "C and C++ function arguments are usually passed on the stack". This is if you are using the cdecl or stdcall calling conventions (all arguments are pushed to the stack, but they vary in who is responsible for clean-up). I am attempting to use the fastcall calling convention, where the first two parameters are passed in ECX and EDX, respectively, and all remaining parameters are pushed to the stack right-to-left. Confirmation of this can be found on MSDN[^]
When I actually run in the debugger, the stack pointer register (ESP) is pointing to the return value (pushed from EIP, the program execution pointer, after my third parameter is pushed), with [ESP + 4] (the second item in the stack) being my third parameter. When using fastcall, the callee is responsible for removing the parameters from the stack. However, I currently have to swap the two arguments on the stack (at addresses [ESP] and [ESP + 4]), otherwise I pop the return address off the stack, then try to return to address 3 when the RET statement executes.
This seems counter-intuitive to me. Why should I have to swap the stack arguments? Is there some other way to do this where I don't have to swap the arguments?
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
If you create a dummy function in C with the __fastcall attribute and compile it with the /FAs compiler options, you can see how the C compiler generates the code for such a call. If you ignore the fact that the C generated code moves the parameters around quite a bit, you can see that it does not pop the arguments off the stack, but addresses them directly by their offset relative to the stack pointer. It then clears the pushed arguments by using the ret N return command.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
This may be a wrong place to post this request,my apology.
I am currently using a USB dongle called LittleWire as a control interface to I2C device.
I am trying to learn how to build libraries and so far I pretty much stuck with morass of header files.
I can build simple Static library ( in VC ) , but it appears that “outside MS” developers rely heavily on variety of Make /Cmake tools.
My obviously obsolete programming book "Inside Visual C++” does not cover Make.
I have never used VC Make wizard and would like to learn how to do that.
I would greatly appreciate any personall recomendations, links/ references, on “ using Make”.
( Yes I can Google, I am looking for a real experience recomendation )
Thanks for your time.
Cheers Vaclav
|
|
|
|
|
The first question I would pose to you, is why you think you need make rather than the Microsoft tools? If you are clear that make is the only way to go then I would recommend looking at the GNU manual[^], which explains it all. But be prepared for a lot of reading and re-reading; make is great when it works but it does take some getting used to.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I did find some material to study and the first thing that jumped out was “it is a cross-platform tool”.
Being a MS “developer” I definitely do not need that. I was just looking to see if I can adopt the open source libraries without having to copy all the source files to VC library projects. Looks like I would not gain any better organization / directory structure than what VC creates.
At this point I agree with you, but still like to learn how to use “Makefile” project wizard in VC.
I am also not sure if either MS or other vendors results of “Male” can be debugged at the source level.
I have found few libraries I just cannot use wiht my archaic VC and just do not like to be blindfolded and not be able to get to the source level.
|
|
|
|
|
Vaclav_Sal wrote: I did find some material to study and the first thing that jumped
out was “it is a cross-platform tool”.
Make is just about as cross-platform as mark-up is cross-browser.
Correct me if I'm wrong, but doesn't VS allow you to import a makefile and it will create a VS specific project file for you? Perhaps at one time it did, but now no longer.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Chris Meech wrote: Make is just about as cross-platform as mark-up is cross-browser. The voice of bitter experience.
Chris Meech wrote: doesn't VS allow you to import a makefile I have not succeeded in doing this with any other than those that were generated by VS in the first place.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Vaclav_Sal wrote: I am also not sure if either MS or other vendors results of “Male” can be debugged at the source level. Sure they can, Make is just a tool (like msbuild) that automates the compile and link phases of a project. It is your choice as to how much debug information is generated within those operations by the use of compiler and linker switches.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
|
I think I'll start with Reilly’s book.
Personally, I feel as a "victim" of VC wizards.
Always using "MFC project" I have no real knowledge how the compiler and linker works.
I only know about some of the (MFC) files when the IDE breaks, which is pretty common in VC.
I believe "automation" is nice, but at present I am looking at "Make" as an another layer which hides the real works.
To really appreciate "Make" I need to learn how to control the compiler using commands.
Yet another project, darn, on top of "honey do's".
Cheers Vaclav
|
|
|
|
|
Hi,
I'm developing an MFC application using VS2010.
I noticed that the the printing in my application stopped to work. I reckon that it happened when I moved from VS2005 to VS2010, as it was working fine before.
So the releveant piece of code is here:
CPrintDialog PrintDlg(FALSE, PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_NOSELECTION | PD_DISABLEPRINTTOFILE, this);
if(PrintDlg.DoModal() == IDOK)
When PrintDlg.DoModal() is executed it comes up with this message:
"Before you can perform printer-releted tasks such as page setup or printing a document, you need to install a printer. Do you want to install a printer now?"
When I press the 'Yes' button it comes with another error:
"Windows can't open Add Printer. The local print spooler service is not running. Please restart the spooler or restart the machine"
I have network printer installed as default, and I can print from any other application without a problem.
I'm using Windows 7, but I checked on Windows XP and it comes with the same error.
I tried to swap the above code with:
CPageSetupDialog psd(PSD_INTHOUSANDTHSOFINCHES | PSD_MARGINS | PSD_ENABLEPAGEPAINTHOOK, this);
if(psd.DoModal() == IDOK)
but it does the same thing.
EDIT:
Actually I run old version of application (compiled with VS2005) and it behaves the same way. So it's not caused by VS2010 after all.
Any ideas?
modified 18-Oct-12 10:00am.
|
|
|
|
|
Have you tried recreating this with a "dummy" application, either console OR dialog based? Put nothing in it but the use of CPrintDialog .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
modified 19-Oct-12 8:02am.
|
|
|
|
|
Yes - I tried it with dummy app and it does the same thing.
|
|
|
|
|
blackbolek wrote: The local print spooler service is not running. Please restart the spooler or restart the machine
You need to start your "Print Spooler" service, through the Services Manager, and then restart your computer, so that the service is running error-free.
To do this
1.) Go to the start menu.
2.) Type in "Services".
3.) Click the item that has the gears on it.
4.) UAC will pop up (since your affecting the whole system and every user on it), Click OK or Yes. If it requests a password, enter the one of the account your on then click OK or Yes.
5.) Then look for the service.
6.) To Start it (look below)
a.) Right-click it, then click "Properties".
b.) Under the tab "General", on the label "Startup type", click the combo box, then click "Automatic" (it may ask you to restart your computer, but you need to anyways).
c.) Click OK, exit out of the Services Manager.
7.) Restart your computer.
Finally, I would test that application, to see if it works now.
Also, if you did not know the service was disabled, maybe malicious software is on your computer, or someone was messing with your computer, just throwing that out there.
Simple Thanks and Regards,
Brandon T. H.
Programming in C and C++ now, now developing applications, services and drivers (and maybe some kernel modules...psst kernel-mode drivers...psst).
Many of life's failures are people who did not realize how close they were to success when they gave up. - Thomas Edison
modified 27-Oct-12 17:43pm.
|
|
|
|
|
I checked and the Print Spooler service is running, start is set to Automatic.
I don't think it has anything to do with it because all the other application on this PC are printing without any problem.
Thanks for your replay anyway.
|
|
|
|
|
Hello Friends
I created a project in VS2010 used adobe SDk and created adobe illustrator plugin(.aip).
Now,i want to open this project in Adobe Flash Builder to convert into ZXP format.
But,I am not able to open this vs2010 project in flash builder.
Any Ideas?
Regards
Yogesh
|
|
|
|
|
At a guess I would say the Flash Builder is not designed to handle Visual Studio project files.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Are you trying to open the vs2010 project in flash builder or are you trying to open your plugin in flash builder?
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
I am trying to vs2010 project in flash builder.
Bcoz I want to create output as .zxp so that i can install in CS Extension manager.
Or is ther any other way to create .zxp format As I am having .aip plugin tht i got as output of vs2010 project.
Or Can I create .zxp format in vs2010 ?
Any Ideas?
Thanks & Regards
Yogesh
modified 19-Oct-12 0:16am.
|
|
|
|
|
ListView_InsertColumn associated subitem.
How does it really works if it works?
It seems that I can create columns with associated subitem -1. Does it mean that this column has no associated items ? also if it has associated subitem it seems that has no affect...
|
|
|
|
|
I'm not sure what you are asking but the subitem is the column index (0 to N) when adding columns. I have not used -1, so would be interested to know what results you see.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
ok, then theoretically you can assign one subitem to several columns. Does it mean that all columns will display for example subitem 1 data?
what if I will delete column 2 which is associated with subitem 1 (while column 1 is associated to subtiem 1 also)?
|
|
|
|
|
As far as I am aware, from using ListView controls, the subitems are merely column indices and are adjusted as columns are added or deleted. Once you have set your columns then the subitems are in ascending order starting at zero.
One of these days I'm going to think of a really clever signature.
|
|
|
|