How does a miner perform hashing?
This question is a complicated one, but I'll see what I can do to answer it. Also, I won't try tackling the issue of endianness, as in the case of Bitcoin it gives me a headache...

First, lets see what we have in a block header given to us by getwork. Lets take the Genesis Block for an example.

01000000 - version
0000000000000000000000000000000000000000000000000000000000000000 - prev block
3BA3EDFD7A7B12B27AC72C3E67768F617FC81BC3888A51323A9FB8AA4B1E5E4A - merkle root
29AB5F49 - timestamp
FFFF001D - bits
00000000 - nonce (it will be set to 1DAC2B7C later)
00 - number of transactions (always 0, this is the block header)
0000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000 - padding


In order to calculate the midstate, we split the header into two parts that are accepted by SHA algorithm (64 bytes each):

0100000000000000000000000000000000000000000000000000000000000000000000003BA3EDFD7A7B12B27AC72C3E67768F617FC81BC3888A51323A9FB8AA
4B1E5E4A29AB5F49FFFF001D00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000


We load the first part into the SHA algorithm. We take save this state for later use (midstate) (sorry for lack of examples, but I don't have my hashing algorithms on hand). Then we load the second part into the SHA algorithm. We read the output, this is the first hash. We take that output, plug it back to a new input, and get its result. That is the second hash. Assuming we got the correct nonce (in our case - 1DAC2B7C), our result should look something like this:

000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f


and compare it to our target:

00000000ffff0000000000000000000000000000000000000000000000000000


Taken as a number, which is bigger? The target. This means that we have the correct nonce, and we can submit our full header as the result. Profit!

From what I understand, you tried to break up the resulting numbers too much, instead of operating on really big numbers like Bitcoin appears to be doing. Then again, endianness is also a big problem with the protocol and what not...

I hope this answers your problem.