For those looking to get CKeyID, you might be going the wrong path (like I did). I needed to convert an address in String format into a hash that can make into a custom transaction, which is something that Devcoin does in order to transfer a certain amount of newly minted coins to a list of addresses (beneficiaries).
Little context, currently I'm updating Devcoin from old Bitcoin 0.8.x up to Bitcoin Core 22.x, so many things have changed! Also, I was missing the fact that Bitcoin transactions need pubkey hashes, not the actual pubkeys. An address derives from a pubkey hash, which then derives from a pub key. Btw, there is no way back from hashes to pub keys, since that would break the actual purpose of hashes (they are irreversible). Hopefully, address are base58 formatted, it means that they are reversible to their hash. Last but not least, modern Bitcoin has great functions that handle the different types of addresses and their hashes, so we do the following:
CMutableTransaction myTx;
myTx.vin.resize(1);
myTx.vin[0].prevout.SetNull();
const string addressString = "my_address";
CAmount amount = 10;
string error_str;
CTxDestination destination = DecodeDestination(addressString, error_str);
// You don't need much more checks than the following
if (!IsValidDestination(destination)) {
return error(error_str);
}
CScript pubKeyHash = GetScriptForDestination(destination);
myTx.vout[0] = CTxOut(amount, pubKeyHash);
An implementation of the above:
https://github.com/devcoin/core/blob/4ec355c0e42108afcfc8d2467fdeed0119a4123b/src/miner.cpp#L163- develCuy