Thanks for these very useful comments. I fixed the BSTR issues (by always using CComBSTR), and called Initialize and Terminate functions.
I do not use smart pointers for COM objects, but normal pointers initialized to NULL in the class constructor and released in the destructor, because they are class members declared in a .h file in which I do not want to include any COM stuff.
I agree that the difference can result from the solver tolerance. Note that the relative error can be as high as 1e-4 for certain values of p and T:
Computing internal energy and its derivatives:
T 2.704082e+002 p 6.816327e+006 U -2.533797e+005
Computing only internal energy:
T 2.704082e+002 p 6.816327e+006 U -2.534055e+005