Not able to get "Active Document" using API in case of assemblies

Hi

I have made an application in VC++. In this application you canchoose a part or assembly in a browse dialog and then it willlaunch SolidWorks(using ShellExecute) with the part or assemblychosen.
Then I get an instance pointer of SolidWorks using"CoCreateInstance".
Then I get the active document using "get_IActiveDoc2".

Now here is where the issue comes in case I loaded an assembly.
If it is a part then I am able to get the active document pointerinstantly. But incase it was a large assembly that requires timeloading all the parts that comprise it; then I get a NULL in theactive document pointer.

On the other hand if I introduce some "delay" using sleep, it givesSolidWorks enough time to load the assembly; and then I can get theactive document using get_IActiveDoc2.

This is fixed only because I entered some delay. Is there anycleaner or more efficient way to get the active document fromSolidWorks only when it is fully loaded and not before? Or is thereany event by which I can know that the active document is fullyloaded in SolidWorks? Or that SolidWorks is ready for using the APIon it to get information ?
SolidworksApi macros