The key call an ObjectARX application must make when it gains control is to find out the current document, which can be accomplished with the function acDocManager->curDocument().
From the current document, you can determine the current database, the relevant transaction manager, and your application's associated document-specific state, and then do whatever needs to be done before returning.
Once a command has stored the current document and associated information on its stack, it does not need to query the current document again until completion. Whenever a prompt for user input is made, the user can switch documents, but if that is done, the current command is suspended and its stack state is saved until the document is reactivated.
If your application is operating from the application execution context, it must lock and unlock the current document to modify anything associated with it. It can do so by directly invoking the AcApDocManager::lockDocument() and unlockDocument() member function.
If your application is operating from an ObjectARX or AutoLISP function, no locking should be necessary, as the system establishes the locks and removes them automatically around commands and AutoLISP expressions.