IDesignerDebugging::BeforeRun

Notifies the designer that the IDE is ready to enter run mode.

HRESULT BeforeRun(
   void *ppvData
);

Parameter

ppvData

[out] Pointer to data allocated by this method that will be passed to IDesignerDebugging::AfterRun.

Return Values

The designer returns one of the following values:

Return Value Meaning
S_OK Success.
Other statuses Errors.

Comments

The designer implements this method.

If the designer specifies the DESIGNERFEATURE_NOTIFYBEFORERUN flag in the registry, the host calls the BeforeRun method when the IDE is ready to leave design mode and enter run mode.

In ppvData, the designer returns a pointer to a data structure that the host later passes to the AfterRun method. The designer must allocate this data with CoTaskMemAlloc; the host will free it after AfterRun returns. Note, however, that if the structure contains pointers to other dynamically allocated data, the designer is responsible for freeing those nested pointers.

By setting the flag and implementing the BeforeRun method, the designer can prepare for the creation of run-time instances. However, successfully returning from this method does not guarantee that a run-time instance will be created; errors or user actions that occur after BeforeRun returns can cause the IDE to fail to enter run mode.

Example

The following example allocates and writes two strings, which the host will later pass to the designer's AfterRun method. Here, the strings represent the name of a file to delete and to rename after the IDE has left run mode.

STDMETHODIMP MyDesigner::BeforeRun(LPVOID FAR* ppvData)
{
// Allocate memory for the information we need to pass and copy the info
// into our RunModeInfo structure, which contains file names and paths
// we'll need later.

  *ppvData = CoTaskMemAlloc(sizeof(RunModeInfo));
  ZeroMemory(*ppvData, sizeof(RunModeInfo));
  memcpy(*ppvData, &m_rmiRunMode, sizeof(RunModeInfo));
  
// Create new copies of the strings.
  m_rmiRunMode.bstrRunFile = SysAllocString(m_rmiRunMode.bstrRunFile);
  m_rmiRunMode.bstrFileToRename = 
     SysAllocString(m_rmiRunMode.bstrFileToRename);
  
return S_OK;
}

See Also

IDesignerDebugging::AfterRun, DESIGNERFEATURE_NOTIFYBEFORERUN