I am using libhash++'s getHashFromFile() as seen in this example to get the hash from files.

When the file is a simple text file I get the same result as I get with md5_file() in PHP and the program md5sums, but when it is a binary file I don't get the same result (md5_file() in PHP still returns the same as the md5sums program).

So my question is: How do I use libhash++ (or something equivalent) to return the same hash from a binary file as md5_file() in PHP would?

I am not familiar with that library, but looking at the docs, I am not convinced that it is treating the file as a binary file. Therefore, the first null byte will stop the hash process.

Why not use the MD5 class in the same library?

Pseudo code:
Create context
Read file X bytes at a time.
while (i have data)