This went wrong because you skipped a required step. You must register A.dll with Regasm.exe before you try to generate B.tlb. This writes keys in the Typelib
and Interface
registry key. If you don't then Tlbexp cannot figure out that ITest is described by A.tlb and will omit the necessary importlib("A.tlb")
directive in the type library for B. Which then makes the #import directive in the C++ compiler fall over since it cannot figure out where ITest comes from. #importing A.tlb first is not a workaround.
Other than running Regasm by hand, the simplest way to ensure this is done is by letting the build system take care of that. Right-click your A project, Properties, Build tab, tick the "Register for COM interop" option. VS however must run elevated to have registry write access.
Keeping the declarations in just one project avoids this problem.