shared: Fix bug with ifdef placement for msgid cast

Instead of casting hashmap key on use in HASHMAP_FOREACH_KEY, use an
appropriately sized element to assign the key to in the first place.
test: Fixup handle_callback_response_check