IDesignerProgrammability::MakeValidIdentifier

Generates a valid identifier based on a previously invalid string.

HRESULT MakeValidIdentifier(
   LPCOLESTR pszId,
  
LPOLESTR *ppszValidId

);

Parameters

pszId

[in] Pointer to a zero-terminated string that represents an invalid identifier in the host's programming environment.

ppszValidId

[out] Location to receive a pointer to a zero-terminated string that represents a valid identifier in the host's programming environment.

Return Values

The return value obtained from HRESULT is one of the following:

Return Value Meaning
S_OK The host successfully generated a valid identifier and returned it in ppszValidId.
S_FALSE The host could not generate a valid identifier.
E_INVALIDARG One of the arguments is invalid.
E_OUTOFMEMORY Not enough memory is available to complete the operation.

Comments

A designer calls the host's MakeValidIdentifier method to request that the host generate a valid identifier from a string that was previously judged invalid when input to IsValidIdentifier. How the host alters the string depends on the errors in the string and on the specific host. For example, if the string contains invalid characters, the host might simply remove them. If the string is syntactically sound but matches a keyword in the host's programming language, the host might append a number to create a valid identifier.

Designers should always check the returned string to ensure that it is valid within the designer code and does not duplicate an existing identifier or keyword.

The designer is responsible for calling CoTaskMemFree to free the memory allocated to the output parameter ppszValidId.

Example

The following example initializes a new string that will contain the new identifier, then calls MakeValidIdentifier, passing an existing invalid string (bstrId) and a pointer to the new string. If the method returns successfully, the example calls the local function AddIdToDesignerTypeInfo. When this function returns, the example frees the new string.

   pszCleanId = NULL;
   hr = m_piDesignerProgrammability->MakeValidIdentifier(bstrId,
      &pszCleanId);
   if (hr == S_OK) {
      if (AddIdToDesignerTypeInfo (pszCleanId)) {
         CoTaskMemFree (pszCleanId)
      }
   }

See Also

IDesignerProgrammability::IsValidIdentifier