The problem could be latency.. but it also might not be.
I had this EXACT same problem... and it took about 2 months to figure out the fix.
The problem I had was that my audio was being recorded on time (there was negligible latency)... but when I went to take a look at the playback.. the midi notes were WAY off. They were so off beat that when I quantized, it didn't even quantize properly. It sounded a hot mess and I had to spend countless minutes just moving midi notes... pain in the ass and is very unmotivating. The problem wasn't latency... and it wasn't me just being off-beat either lol.
The problem is with the MIDI port you're using (and i'm assuming this might be the case w/ FL Studio also, though i'm not 100% sure). There are two types of ports you can use... either 1) DirectMusic or 2) Windows MIDI (at least for me there were only two types). Between those two types of ports... you can either check off "Use System Timestamp" or not. So between those... you have four possible options. One of those options DEFINITELY works... you just have to figure out which setting works for your system based on trial and error (not really a big pain in the ass... it's worth it once u figure out which setting works for you).
So.. to simplify... the proper midi port setting for you could either be DirectMusic (Timestamp either checked or unchecked) or it could be Windows MIDI (Timestamp either checked or unchecked).
It's difficult to change in Cubase 5 b/c it has a MIDI port filter. You have to go to C:\Program Files\
Steinberg\Cubase 5\midi port enabler
Cut the file that says "ignoreportfilter" and paste it into the regular Cubase 5 folder (essentially taking it out of the midiport enabler folder).
Next, open up Cubase.. go to Device Setup> Midi Port Setup.
Now, you'll see all of your possible midi settings. Go to work and figure out which combination works by process of elimination. One of them definitely works.
Hopefully this solves your problem. This was a HUGE problem for me also... it took many hours of searching for an answer. I can't even remember where I found the answer for it.