I know that, I just said I hope it's possible one day. We've come a long way in rom hacking, ASM hacking then C hacking. Implementing mega evolution. I hope it can be done one day.
Making it impossible to use gameshark and action replay codes designed for the original unedited rom file (for instance Firered 1.0) is totally possible. And as a hacker by doing so you can prevent most (maybe over 99,9 %) of players from using cheat codes while playing the game. However, it's practically impossible to make it so that some other gameshark codes wouldn't achive the same or similar effects as the ones for the unedited rom file.
As an example, the level modifier code for FireRed is "33007CF0 00XX" which basically means that "replace the value in address $33007CF0 with 00XX" (at least, I think that's what it does). As a rom hacker, you can modify the game to store the level of the encountered pokemon elsewhere - let's say in address $3B008D2A. Now the original gameshark code for FireRed doesn't change the level of the encountered pokemon but code "3B008D2A 00XX" instead does.
Okay - there we have a solution to the problem. Now no one can edit the level of the encountered pokemon in a hack we're making.. right? Not really as someone who is at least almost as smart as the hacker can figure out where the hacker has stored information about the level of the encountered pokemon. And if (s)he is an "evil" person, (s)he will publish this information to others as well.
So it's not really worth spending time making it impossible to cheat in a hack of yours. It first of all takes time (except for disassemblies but that's a totally different story), but second isn't really worth it in the end. Like others have also pointed out - why bother preventing some cheaters in doing something? As a hacker you're probably more interested in designing a hack both for yourself but also others who play game with the rules given by the hacker (= don't cheat). I personally don't care less about players who cheat and hence accomplish something that I have intended to be impossible to be done.
Although it's worth to take these into account at least one way or another. After all, you may accidentally program a glitch in the game which would put the player in a situation like this even when not intended.
In Dark Energy there is for instance a PC where you need to input a long confirmation code to access the inner parts of an abandoned research center. The code can be acquired later in the game when you're supposed to go there, but you can reach the PC earlier and try inputting the code already then. It's practically impossible to guess what the code is, but if you're playing for the second time or have looked up the code by googling, there has to be some kind of a backup script that is run when you try to enter the research center, and you're not supposed to get there yet.
If it didn't matter that you could reach it earlier, it wouldn't be needed, but here I kinda had to program a "secret" security script.
Okay - that post turned out pretty long. But to put it in short - you can have some protection by for example changing the addresses where data is stored in ram and thus make it impossible to use gameshark codes designed for the original unedited rom file, but even so, you can't (easily) make it impossible to use the same codes with different address parts either way. And like others have pointed out as well, it's not really worth it trying to protect against others hacking the game unless you for some reason have a very good reason behind doing so. Protection against glitches or unwanted situations that could clearly be accessed through some chain of events is a totally different thing though.