0

Possible Duplicate:
Typedef function pointer?

TE0300_Open = (_TE0300_Open)GetProcAddress(hInstLibrary, "TE0300_Open"); typedef int (WINAPI *_TE0300_Open)(unsigned int* PHandle, int CardNo); 

Can someone explain me what this piece of code does? I know that typedef is used to assign alternative names to existing types but I don't understand this case at all.

1

2 Answers 2

4

typedef int (WINAPI *_TE0300_Open)(unsigned int* PHandle, int CardNo);

This line typedefs a function pointer to a WINAPI calling convention function returning an int, and taking an unsigned int * and an int. The function pointer type is given the alias _TE0300_Open.

Consider the following example:

typedef void (*func)(); void foo (func f) //notice we have a nice type name here { cout << "Calling function..."; f(); } void bar(){} int main() { foo (bar); } 

I believe C++11 added support for less icky syntax when using function pointers as well:

using func = void (*)(); 

As for your GetProcAddress call, this loads a function from a library. You assign it to a function pointer, and you can use that function pointer as you would the original function.

In your example, you can now call TE0300_Open as you would normally call _TE0300_Open. It should also be noted that _TE0300_Open is a name that is reserved for the implementation.

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

1 Comment

Thanks, it wasn't so strange after all, I just didn't fully understand the typedef usage.
2

It's declaring a typedef, _TE0300_Open, for a function-pointer.

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.