It seems to me that a better way to do this (in the abstract case :) ) would be to librarify dpkg -- that is, to make a libdpkg which approximately parallels libapt. This would also have the effect of solving some annoying quirks in the apt/dpkg interaction which are caused (if I remember correctly) by the fact that apt marshalls a whole lot of package installations for a single dpkg call, but can't easily tell which ones were successfully performed and which failed if something goes wrong.
Of course, having never even tried to look at dpkg's code, I have no idea how easy this is given the program's design. I suspect that if it were possible someone would have done it already :) Daniel -- The only thing worse than infinite recursion is infinite recursion.