Questions tagged [cdecl]

Anything related to the `cdecl` calling convention, i.e. one of the common subroutine calling conventions used on systems with x86 architecture.

Anything related to the cdecl calling convention, i.e. one of the common subroutine calling conventions used on systems with x86 architecture.

See Wikipedia on:

101 questions
6
votes
2 answers

64-bit C++ passing functions with "different" calling conventions as parameters gives ambiguous error

My goal is to easily extract a prototype of an arbitrary function with both the __cdecl and __stdcall calling conventions. It works fine in 32-bit. The only thing that's changing is the calling convention in my template function…
Goodies
  • 4,439
  • 3
  • 31
  • 57
6
votes
1 answer

C++ and FULLY dynamic functions

I have a problem with detours. Detours, as you all know, can only move among 5 bytes of space (i.e a 'jmp' call and a 4 byte address). Because of this it is impossible to have the 'hook' function in a class (a method), you cannot supply the 'this'…
Elliott Darfink
  • 1,153
  • 14
  • 34
5
votes
3 answers

C#/.NET Generics and Cdecl Varargs Bug?

Why does Foo() succeed but Bar() throws a BadImageFormatException? using System.Runtime.InteropServices; using System.Text; static class Program { [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)] static extern int…
user541686
  • 205,094
  • 128
  • 528
  • 886
5
votes
3 answers

Calling a function that can be either cdecl or stdcall

I need to write code that calls an external function that can be either stdcall call or cdecl in a 32bit windows application. My code, the caller, can't know in advance which of these its going to be. Right now, if I try to call a cdecl function…
shoosh
  • 76,898
  • 55
  • 205
  • 325
4
votes
3 answers

Assuming a calling convention when combining C and x86 Assembly

I have some assembly routines that are called by and take arguments from C functions. Right now, I'm assuming those arguments are passed on the stack in cdecl order. Is that a fair assumption to make? Would a compiler (GCC) detect this and make sure…
User123abc
  • 376
  • 3
  • 9
4
votes
2 answers

cdecl error: expected initializer before

I have a problem with the cdecl calling convention: void Test1(char* str, ...) // ok {} void cdecl Test2(char* str, ...) // error: expected initializer before 'Test2' {} int main() {} What should I do to make the compiler recognize…
Pietro M
  • 1,905
  • 3
  • 20
  • 24
4
votes
4 answers

Why isn't PInvoke crashing in case of violated calling convention (in .NET 3.5)?

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 [...]…
Alex Che
  • 6,659
  • 4
  • 44
  • 53
4
votes
4 answers

What does the following code do?

Possible Duplicate: How do you read C declarations? I Don't understand the following: int‬‬ ‪* (*(*p)[2][2])(int,int); Can you help?
Chen Kinnrot
  • 20,609
  • 17
  • 79
  • 141
4
votes
2 answers

what's the meaning of "#define __cdecl" in my C++ code?

I'm working on an existing c++ project with visual studio, and I found out that almost every function declaration gets a __cdecl in front of the function name, like:void __cdecl functionName(). Then I jump to the definition of __cdecl, which locates…
Mengfan Ma
  • 351
  • 2
  • 13
3
votes
2 answers

_cdecl calling convention

In an article about the _cdecl calling convention, the writer mentioned: Release local storage When the function allocates local, temporary space, it does so by decrementing from the stack point the amount of space needed, and this process…
user1091856
  • 3,032
  • 6
  • 31
  • 42
3
votes
3 answers

How can a reference be present in a signature of a function callable from C code?

I'm a bit confused: I have a C++ API which is supposed to be called from C code and uses __cdecl in the function declarations. There's a vtable with function pointers like this: void (__cdecl *funptr) (const MyStruct& obj); references are a C++…
Dean
  • 6,610
  • 6
  • 40
  • 90
3
votes
2 answers

What do __cdecl and (void) mean?

I'm currently programming a tcp/ip server using WSA. After some troubleshooting a friend of mine said that i should use bool __cdecl winsock_server ( void ) instead of bool winsock_server(). But he didn't explain to me what __cdecl and (void) are…
AcrimEx
  • 57
  • 1
  • 1
  • 8
3
votes
2 answers

Unable to understand example of cdecl calling convention where caller doesnt need to clean the stack

I am reading the IDA Pro Book. On page 86 while discussing calling conventions, the author shows an example of cdecl calling convention that eliminates the need for the caller to clean arguments off the stack. I am reproducing the code snippet…
user1720897
  • 1,216
  • 3
  • 12
  • 27
3
votes
1 answer

Finding out how many bytes separate esp and the stored return address on the program's stack

I'm having trouble finding out the answer. From what I've read %ebp has 32-bits, moving %esp to %ebp you'll still have 32-bits, then subtract 70 to 32, and I don't understand the rest. I am new to this so I'm not very proficient. Please give a…
3
votes
1 answer

Pass an argument from C to assembly?

How can I pass an argument from a C main function to an assembly function? I know that my custom function has to look something like: void function(char *somedata) __attribute__((cdecl)); Now how would I use somedata in an assembly file. My…
Mohit Deshpande
  • 53,877
  • 76
  • 193
  • 251