You can get the SHA-1 from the .chd's header. Just take a look at mame\source\mame\src\lib\util\chd.h source file to declare those header types in your application read the checksum from them. Make sure you support all header versions from v1 to v5...
That's how my frontend Emu Loader validate CHD files. What compiler is your application created with ? My frontend is made with Borland Delphi 7.