Note: This answer will be for transferring from an emulated DS Pokémon game to Gen 6/7. Pokémon from a GBA emulator can be transferred to your emulated DS game (Let's say it's gen5) by first using gen 4's Pal Park and then Pkhex (I'm not going to give a full explanation about that). You can use Pal Park with DeSmuME to transfer your GBA mons. I don't know how to transfer emulated Pokemon from gen 1 & 2 though without using Pkhex. Do not edit your Pokemon unless you want to damage them and make them hacked. They're not easy to fix either. You can also use pkhex to check if your Pokémon are legit. Enough of that now.
1. You’ll need one of these things and a reliable micro sd card (with at least 4GB, and not from your 3ds). I recommend using a gift card when ordering. You may also need a micro sd card adapter.
2. You need the ROM of your DS Pokémon game and it’s save data.
3. You need a real DS Pokémon game (I recommend Pokémon Black/White 2). This legit game has to be far enough into the story to do link trades.
4. You need 2 3ds consoles (or a 2DS and your 3ds console, or 2 2DS consoles).
5. You need an activated Pokémon Bank and Pokémon Transporter (it can be downloaded with the bank).
6. Plug your micro sd into your pc (with your adapter if needed).
7. Download the firmware of the card you ordered here.
8. Un-zip the firmware. You might need winrar.
9. Put everything you unzipped onto your micro sd card.
10. On your micro sd card make a folder called "DS Games." Put your DS rom and it’s save data (which should be found in the "battery" folder of your emulator if you’re using DeSmuME) in the ds games folder. The file type of your save file should be dsv. Change it to sav. And make sure your rom is not zipped.
11. Eject your micro sd card and put it in your r4 card.
13. Put your r4 card in one of your 3ds/2ds consoles and it should appear as a cartridge on the home menu. You don’t have to hack your 3ds/2ds. Start the app.
14. Put your legit Pokémon BW2 game in your other 3ds/2ds console. Start the game, and catch lots of route 1 trash, then head to a center.
15. Your other console should be on the r4 menu, find your DS rom and load it. The game should start.
16. On the r4 game get to a center and head to link trades.
17. On the real game head to link trades and start a link trade with the emulated trainer.
18. Trade all your emulator mons to the real trainer, replacing the route 1 trash you caught.
19. End the trade. The console with the r4 is no longer needed (note: this method works backwards).
20. In your real game put the Pokémon from the emulator in box 1. Save and exit.
21. Open Pokémon Transporter and send the mons in box 1 to Pokémon bank.
22. In Pokémon bank your emulated mons should be in the transport box (if some are missing then they have been marked "fake" and sent back to your ds game).
23. Now that your Pokémon are in the transport box you can choose to put them in gen 6 or 7.
I hope I have answered your question. Pokémon from ROM hacks cannot be transferred.
Source: The universe.