Q: Can I simply this expression?

S

Somebody

Pardon the Windows types :)... they are just pointers to DWORDs and BYTEs...
Is there a way to simplify this monstrosity?

BOOL (CFile::*pFunc)(CFileStatus&) const = &CFile::GetStatus;

TRACE("%x\n", *((LPDWORD)(*((LPDWORD)(((LPBYTE)*((LPDWORD)&pFunc)) + 2)))));

I *think* what this is supposed to mean is:

pFunc is a ptr to a func, I need to take the address of that + 2 bytes then
double indirect it as dword addresses :).
 
S

Somebody

Somebody said:
Pardon the Windows types :)... they are just pointers to DWORDs and
BYTEs... Is there a way to simplify this monstrosity?

BOOL (CFile::*pFunc)(CFileStatus&) const = &CFile::GetStatus;

TRACE("%x\n", *((LPDWORD)(*((LPDWORD)(((LPBYTE)*((LPDWORD)&pFunc)) +
2)))));

I *think* what this is supposed to mean is:

pFunc is a ptr to a func, I need to take the address of that + 2 bytes
then double indirect it as dword addresses :).

Got it down to this:

TRACE("%x\n", **((LPDWORD*)((*((LPDWORD)&pFunc)) + 2)));

A little nicer :), can I do any better?
 
A

Andrey Tarasevich

Somebody said:
Got it down to this:

TRACE("%x\n", **((LPDWORD*)((*((LPDWORD)&pFunc)) + 2)));

A little nicer :), can I do any better?

TRACE("%x\n", **(LPDWORD*)(*(LPDWORD) &pFunc + 2));
 
K

kwikius

Got it down to this:

TRACE("%x\n", **((LPDWORD*)((*((LPDWORD)&pFunc)) + 2)));

A little nicer :), can I do any better?

Maybe wrap the offending part in a function:

(Untested)

// assume its cast into a DWORD?
inline // optional
DWORD TraceFormat(
BOOL (CFile::*pFunc)(CFileStatus&)
)
{
return *((LPDWORD)(*((LPDWORD)(((LPBYTE)*((LPDWORD)&pFunc)) + 2;
}


TRACE("%x\n", TraceFormat(pFunc));

regards
Andy Little
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top