-1

so what does this typedef syntax actually do?

typedef PIMAGE_NT_HEADERS (WINAPI *CHECKSUMMAPPEDFILE)
          (PVOID baseAddress, DWORD fileLength, PDWORD headerSum, PDWORD checkSum);

from what I know typedef is used like this typedef oldtype newtype; but overhere the whole thing looks like a prototype of a function, but it also looks like it is creating a new type of PIMAGE_NT_HEADERS...

as somebody responded "function typedefs" but an example of a function typedef can bye this

typedef int multiply(int arg1, int arg2);

where multiply is the function name, but in the complex one I posted above, where is the function name?

IngMike
  • 1
  • 3

2 Answers2

2

Your typedef creates an alias CHECKSUMMAPPEDFILE. CHECKSUMMAPPEDFILE is a pointer to a function that returns an PIMAGE_NT_HEADERS and takes as arguments PVOID baseAddress, DWORD fileLength, PDWORD headerSum, PDWORD checkSum. From the first look syntax of such a typedef is not obvious.

and WINAPI is calling convention.

Community
  • 1
  • 1
Nikita
  • 6,270
  • 2
  • 24
  • 37
1

This is a type alias for a function pointer. You can use it to define a variable to which you can assign a function.

This:

typedef int multiply(int arg1, int arg2);

is a typedef for a function type, you cannot use it the same way as function pointer. See example below:

int mul(int arg1, int arg2) {
}

typedef int multiply(int arg1, int arg2);
int main() {
    //multiply m = mul; // error multiply is a typedef for a funciton type
    multiply* m = mul; // ok
}

What your type alias :

typedef PIMAGE_NT_HEADERS (WINAPI *CHECKSUMMAPPEDFILE)(PVOID baseAddress,   
                               DWORD fileLength, PDWORD headerSum, PDWORD checkSum);

do:

it declares a CHECKSUMMAPPEDFILE as pointer to function (PVOID, DWORD, PDWORD, PDWORD) with WINAPI calling convention returning PIMAGE_NT_HEADERS

You might use cdecl.org to decifer function pointers, it offen requires some tweaking to make it work.

marcinj
  • 48,511
  • 9
  • 79
  • 100