problem about calling-convention-Collection of common programming errors
AlBlue
com assembly x64 calling-convention
I am trying to get a definitive answer regarding the way COM behaves on a x64 machine. Does Windows use the normal x64 calling convention when dispatching calls to COM interfaces on x64 machines (assuming the COM implementation is 64 bits)? Specifically, I dynamically generate my vtbl entries to point to a chunk of assembly that’s dynamically loaded during runtime. This assembly needs to know how to get parameters correctly from whomever is calling it. Thus, I’d like to know if COM sets up the c
Lee White
c++ pinvoke calling-convention function-declaration stdcall
I have been using PInvoke to let my C# application call C++ functions I wrote.Now, I keep hearing everywhere and beyond that I need to define those externally accessible functions with the __stdcall convention. My question is: Why?So far, I have accidentally ignored this advice, and everything works like a charm. When I add __stdcall to my functions, everything keeps working in the same way (or at least it seems so). This article says that __stdcall is used for Win32 bit functions, but I am comp
Kierrow
c++ floating-point x86 microsoft calling-convention
I’ve been researching floating-point numbers for my compiler projects, especially how they are converted from decimal notation to bytes. I did find answers to all of my questions, but this YouTube video got me worried.The guy explains SSE and the instruction set pretty good and I did understand everything, but he also mentions that Microsoft’s Visual C++ apparently does not use the _stdcall calling convention when it comes to floats. This would be terrible for me as I was planning to use the C c
Brian Hsu
java this callstack calling-convention
We already knew that when we calling a method in Java, parameters and local variables will be stored on the stack.For example the following code:public class Test {int x = 10;int y = 20;void test(int y){int z = y;this.x = y; // How JVM knows where is our current object?}public static void main(String [] args){Test obj = new Test();obj.test(3);} } Will produce a call stack like the following when we called obj.test():| | +————-+ | z | | y | obj.test() +—
overboming
iphone compiler assembly arm calling-convention
I want to know how objective C runtime handle arguments when I call a objective C method like[NSString stringWithFomat:@”%@, %@”, @”Hello”, @”World”]There are three arguments for this objective C call, how does it work compared to typical way on a ARM system. I have known register r0, r1, r2, r3 will hold first 4 arguments, how about there are additional arguments? How does it put them on a stack and pop them later?
Lakshmi
calling-convention
In VS2005, I was using _cdecl calling convention and the project builds without any linker errors. After I change the calling convention to _stdcall while porting the project to VS2008, I get the following error:error LNK2001: unresolved external symbol [email protected] Settings>C\C++>Genral>Common Language Runtime support is set to No Common Language Runtime support I need help regarding any project settings or code changes that need to be done in order to resolve the issue. Any hel
user48821
c# pinvoke calling-convention
I have a business case whereby I need to be able to specify my own calling convention when using P/Invoke. Specifically, I have a legacy dll which uses a non-standard ABI, and I need to able to specify the calling convention for each function. For example, one function in this dll accepts its first two arguments via EAX and EBX, with the rest via stack. Another function accepts one argument via ECX, with the rest on the stack. I have a few hundred of these functions, and would like to avoid writ
Cody Gray
Alexey Frunze
c++ visual-c++ calling-convention
It seems to me, that MSVS ignores __stdcall directive on my functions. I’m cleaning up the stack manually, but the compiler still append ADD ESP instructions after each CALL.This is how I declare the function:extern “C” void * __stdcall core_call(int addr, …); #define function(…) (DWORD WINAPI) core_call(12345, __VA_ARGS__) return function(“Hello”, 789);And this is how the output looks like:I’ve marked with arrows redundant ADD instructions, which MSVS automatically append after each call, d
EAGER_STUDENT
mfc timer callback calling-convention stdcall
In MFC VC++, setTimer function is setted using a CALLBACK procedure. From the link I read that A function that is marked with __stdcall uses the standard callingconvention so named because all Win32 API functions (except the fewthat take variable arguments) use it.And from that, this is what I have understand, ALL THE VC++ MFC FUNCTIONS USE __stdcall as their calling conversions.And CALLBACK is defined as follows…. #define CALLBACK __stdcallWhat I have read: Preceding a function with CALLBACK
Ollie Jones
c++ visual-studio assembly calling-convention
My problem is MSVS 2010 C++ compiler is generating code in a way after returning from a function call resolved in runtime(GetProcAddress+GetModuleHandle) from another dll the compiler then tries to align stack this way:CALL DWORD PTR DS:[2000367C] ; apiresolvedinruntime.dllADD ESP,12 ; <- this is the stack alignmentThis is of course overwriting the return address and my program crashes, can someone explain me why compiler aligning the stack when it
Ben Zotto
c++ winapi callback calling-convention
I used “StartServiceCtrlDispatcher” function to register a callback function (called ServiceMain) in windows, but the callback function I declared got compiled with the wrong calling convention.The thing is that on some computers, when the application returned from the callback function, the application crashed, but on other computers the application did not crash.Now, once I found the bug everything worked, but I just don’t understand why on some computers it worked correctly without crashing ?
informatik01
c winapi calling-convention stdcall
I’m leaning some Win32 programming, and the WinMain prototype looks like:int WINAPI WinMain ( HINSTANCE instance, HINSTANCE prev_instance, PSTR cmd_line, int cmd_show )I was confused as to what this WINAPI identifier was for and found:#define WINAPI __stdcallWhat does this do? I’m confused by this having something at all after a return type. What is __stdcall for? What does it mean when there is something between the return type and function name?
Community
c++ windows calling-convention
I come across _stdcall a lot these days. And in my opinion msdn doesn’t explain very clearly what it really means, when and why should it be used, if at all.I would appreciate if someone would provide an explanation, preferably, with an example, or 2.Thanks
sashoalm
c++ visual-studio-2008 x86 hook calling-convention
I’m hooking a 32-bit C++ function by overwriting its first 6 bytes with a JMP instruction.When testing it sometimes (but not always) crashes if the functions don’t have the __stdcall calling convention. No crashes with __stdcall, so far.This made me wonder if the JMP trick works only with certain calling conventions, or does it work with all of them?I’m using VS2008 on Windows.
Alex Che
.net pinvoke calling-convention stdcall cdecl
My solution has an unmanaged C++ DLL, which exports a function, and a managed application that PInvokes this function.I’ve just converted the solution from .NET 3.5 to .NET 4.0 and got this PInvokeStackImbalance “A call to PInvoke function […] has unbalanced the stack” exception. As it turned out, I was calling __cdecl’ed function, as it was __stdcall:C++ part (callee):__declspec(dllexport) double TestFunction(int param1, int param2); // by default is __cdeclC# part (caller):[DllImport(“TestLi
grunge fightr
c assembly x86 calling-convention
sorry for my weak englishim trying to improve my asm abilities and i have found easy entry point to working on it by using machine code routines from c codei am using it in such way char asmRoutineData2[] ={0xC8, 0x00, 0x00, 0x00, // enter 0, 00xB8, 0xff, 0x00 ,0x00 ,0x00, // mov eax, 655380xC9, // leave0xc3 // ret};int (*asmRoutine)(void) = (int (*)(void)) asmRoutineData;int ret = asmRoutine();and it works pretty excellent for som
mirswith
crash calling-convention libvlc release-mode
I am using libVLC in one of my apps which I am compiling with VC2010 (also tried VC2008), the debug mode of my app works great but as soon as I compile to release mode and try to call into libVLC I get a crash. I asked for help on the vlc forums and someone mentioned this usually points to calling convention differences, however I am not sure what to check to see if this is the case or more importantly how to fix it.some notes:I am compiling libVLC using Ubuntu and following the how to guides o
Rob Kennedy
calling-convention
in my application I have 2 layers. The first layer is a C legacy exposing cdecl functions that use the “…” syntax for a varying parameter list. The only way I found to call these functions from my .Net layer (the second one) is using the DllImport technics. For example the C function below:int myFunc(char* name, …);looks like that in C#:[DllImport(“MyDll.dll”),CharSet = CharSet.Ansi,CallingConvention = CallingConvention.Cdecl] int myFunc(string name, __arglist);My problem is that sometimes I
John Zwinck
c++ windows visual-studio visual-c++ calling-convention
I cannot use __thiscall giving me the following error: error C4234: nonstandard extension used : ‘__thiscall’ keyword reserved for future useI’m calling a class function from a dll:typedef void(*SETDIRPROC)(void*,D3DXVECTOR3&);void ZMyCharacter_SetDirection_Rev( void ) {if( pZMyCharacter == 0 ){printf( “cannot set direction now\n” );return;}SETDIRPROC SetDir_Proc = (SETDIRPROC)0x004A2AF0;D3DXVECTOR3 pos = D3DXVECTOR3(4.0f,2.0f,1.0f);SetDir_Proc( pZMyCharacter, pos ); }pZMyCharacter is a void
Artefacto
c linux x64 printf calling-convention
#include <stdio.h>int main(void) {double resd = 0.000116;long long resi = 0;printf(“%lld %f %lld %f\n”, resd, resd, resi, resi);return 0; }gives (Linux, gcc, x64)0 0.000116 0 0.000116^^^^^^^^ odd, since the memory for resi is zeroedActually, compiled with g++ it gives random results instead of the second 0.I understand I gave invalid specifiers to printf and that it triggers unspecified undefined behavior, but I wonder why this specific corruption occurs, since long long and double have th
Mike
c undefined-behavior varargs calling-convention variadic-functions
I want to create a function pointer to a function that will handle a subset of cases for a function that takes a variable parameter list. The use case is casting a function that takes … to a function that takes a specific list of parameters, so you can deal with variable parameters without dealing with va_list and friends.In the following example code, I’m casting a function with a variable parameters to a function with a hard-coded parameter list (and vice versa). This works (or happens to wo
Web site is in building