-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?

5
  • function typedef. Commented Aug 26, 2016 at 10:38
  • 2
    It's a function pointer. Read this for more details. Commented Aug 26, 2016 at 10:39
  • ok going to read that now @Nikita Commented Aug 26, 2016 at 10:41
  • I've just edited your question to put a linebreak in the declaration, so we can see it without needing to scroll. Feel free to revert if you don't like it. Commented Aug 26, 2016 at 11:31
  • 1
    A somewhat useful rule of thumb: look for the verb. Commented Aug 26, 2016 at 11:36

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

... and uses the WINAPI calling convention.
@IInspectable Missed it, thnx!
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.