COM 伺服器和容器偵錯COM Server and Container Debugging

COM 應用程式可以在程式設計人員直接控制之外執行許多工作。COM applications perform a number of tasks outside of the programmer's direct control. DLL 之間的通訊、物件的使用次數和剪貼簿作業只是您可能碰到預期外行為的一小部分而已。Communication between DLLs, usage counts on objects, and Clipboard operations are just a few of the areas where you might encounter unexpected behavior. 發生這種狀況時,第一步驟便是追蹤搜尋問題的來源。When this happens, your first step is to track down the source of the problem.

Visual Studio 偵錯工具可支援逐步跨越 (Step Across) 和逐步執行容器和伺服器。The Visual Studio debugger supports stepping across and into containers and servers. 這包括可支援逐步跨越遠端程序呼叫 (RPC)。This includes the ability to step across remote procedure calls (RPC).

對相同方案中的 COM 伺服器和容器進行偵錯Debugging a COM Server and Container in the Same Solution

您可以同一方案內使用兩個專案的 COM 伺服器和容器 (Container) 進行偵錯。You can debug a COM server and container using two projects within the same solution. 在每個專案中設定適當的中斷點,並進行偵錯。Set appropriate breakpoints in each project and debug. 當容器在碰到中斷點的伺服器呼叫函式時,該容器將會等待,直到從伺服端程式碼傳回 (也就是直到您完成其偵錯程序)。When the container makes a call into the server that hits a breakpoint, the container will wait until the server code returns (that is, until you finish debugging it).

偵錯 COM 容器的方法和標準程式的偵錯方法相似。Debugging a COM container is similar to debugging a standard program. 不同之處在於您在偵錯一個會產生回呼 (Callback) 的事件時 (例如將資料拖曳到容器應用程式上)。One difference is when you debug an event that generates a callback (such as dragging data over the container application). 在這種情況下,您必須在回呼函式 (Callback Function) 中設定一中斷點。In this case, you must set a breakpoint in the callback function.

在沒有容器資訊的情況下偵錯伺服器應用程式Debugging a Server Application Without Container Information

如果您沒有或不想使用容器應用程式的偵錯資訊,即可採用三步驟的處理方式,開始偵錯伺服器應用程式:If you do not have or do not want to use debugging information for your container application, starting to debug the server application is a three-step process:

  1. 如應用程式方式開始偵錯伺服器。Start debugging the server as a normal application.

  2. 依需要設定中斷點。Set breakpoints as desired.

  3. 啟動容器應用程式 (Container Application)。Start the container application.

對伺服器和網域隔離 (SDI) 應用程式進行偵錯Debugging a Server and Domain Isolation (SDI) Application

如果您要對 SDI 伺服器應用程式進行偵錯,則必須在 C/C++、C# 或 Visual Basic 專案之 [專案] 屬性頁對話方塊的 [命令列引數] 屬性中,指定 /Embedding/AutomationIf you are debugging an SDI server application, you must specify /Embedding or /Automation in the Command line arguments property in the Project Property Pages dialog box for C/C++, C#, or Visual Basic projects.

透過這些命令列的引數,偵錯工具可以啟動伺服器應用程式,就如同它是由容器所啟動。With these command line arguments, the debugger can launch the server application as though it were launched from a container. 從程式管理員或檔案管理員啟動容器,將導致容器使用由偵錯工具啟動的伺服器執行個體。Starting the container from Program Manager or File Manager will then cause the container to use the instance of the server started in the debugger.

若要存取 [專案] 屬性頁對話方塊,請在 [方案總管] 中用滑鼠右鍵按一下您的專案,然後從捷徑功能表選擇 [屬性]。To access the Project Property Pages dialog box, right-click your project in Solution Explorer, and then choose Properties from the shortcut menu. 若要尋找 [命令列的引數] 屬性,請展開 [組態屬性] 分類,然後按一下 [偵錯] 頁。To find the Command line arguments property, expand the Configuration Properties category and click the Debugging page.

請參閱See also