How can I make equivalents to these methods in C? I read somewhere that they could be "replaced with functions that take a structure pointer as the first parameter," but I'm not sure how to do this, if that is the right thing to do.
struct SCustomKeys
{
struct SCustomKey Save[10];
struct SCustomKey Load[10];
struct SCustomKey Slot[10];
struct SCustomKey PrintScreen;
struct SCustomKey LastItem; // dummy, must be last
//--methods--
struct SCustomKey &key(int i) { return ((SCustomKey*)this)[i]; }
struct SCustomKey const &key(int i) const { return ((SCustomKey*)this)[i]; }
};
Here's an example of how they are used:
void ZeroCustomKeys (SCustomKeys *keys)
{
int i = 0;
SetLastCustomKey(&keys->LastItem);
while (!IsLastCustomKey(&keys->key(i))) {
keys->key(i).key = 0;
keys->key(i).modifiers = 0;
i++;
};
}
More context: http://pastebin.com/m649210e8
Thanks for the help. I haven't been able to the suggested replacement for the C++ method working with this function yet though. Any ideas on how to approach this?
void InitCustomKeys (struct SCustomKeys *keys)
{
UINT i = 0;
SetLastCustomKey(&keys->LastItem);
while (!IsLastCustomKey(&keys->key(i))) {
SCustomKey &key = keys->key(i);
key.key = 0;
key.modifiers = 0;
key.handleKeyDown = NULL;
key.handleKeyUp = NULL;
key.page = NUM_HOTKEY_PAGE;
key.param = 0;
i++;
};
//an example key
keys->PrintScreen.handleKeyDown = HK_PrintScreen;
keys->PrintScreen.code = "PrintScreen";
keys->PrintScreen.name = L"Print Screen";
keys->PrintScreen.page = HOTKEY_PAGE_MAIN;
keys->PrintScreen.key = VK_PAUSE;
}
And the new function I'm trying now is:
struct SCustomKey* key(struct SCustomKeys *scs, int i) {
return &(((SCustomKey*)scs)[i]);
}