Before you start hitting the gym, you must
understand that your body MUST have that 'resources' to convert
body mass into muscles, which will improve your body size and
weight. For the hard gainer, you cannot do what the others are
doing because your body condition is entirely different.
Therefore if you hit the gym mindlessly, you are probably going
nowhere in the end because your body has 'limited' resources or if
you overworked yourself, you ended up killing muscles tissues and
your mass goes down.
To gain weight, your intake MUST be more than your output. If have
skinny genes in your blood, your only hope to have significant
result is to 'shock your body into growth.' You can opt to take
mass gainer (not cheap) or if you can try the
many-meals-but-smaller-portion-a-day. Regardless, the end result
must always be such that your input is more than output and you got
to persist in that routine over a considerable period of time. Of
course, if you lose the discipline and give up, you return back to
square one immediately.
Also critically, you must watch the food that you consume because
there's a difference in quality consumed. For example, taking one
wholebread bread might give you a certain amount of calories and in
comparison, it may seemed the same as eating a bag of potatoes
chips (Just citing an example as I don't know the exact calories
involved) - the latter actually gives you inferior carbo which is
detrimental.
Therefore is not just about increasing your intake, but also taking
note of what you are consuming.
When exercising, do less cardio, but more weights. And when doing
weights, do less repetition, but more intense. 
Cheers