public int Exec(ref Guid guidCommandGroup, uint commandID, uint commandExecOpt, IntPtr variantIn, IntPtr variantOut) {
// Cache the variants, they'll be needed if the command chain
// goes back into another IOleCommandTarget (see CommandTargetToOleShim)
CommandResult result;
try {
if (_variantStacks != null)
_variantStacks.Push(variantIn, variantOut, false);
object inputArg = TranslateInputArg(ref guidCommandGroup, commandID, variantIn);
object outputArg = null;
result = _commandTarget.Invoke(guidCommandGroup, (int)commandID, inputArg, ref outputArg);
if (outputArg != null && variantOut != IntPtr.Zero) {
Marshal.GetNativeVariantForObject(outputArg, variantOut);
}
} catch (Exception) {
// Some ICommandTarget object is throwing an exception, which will propagate out as a failed hr, which
// isn't particularly easy to track down. Put a bit of exception information in the activity log.
//ActivityLog.LogInformation("R Tools", exc.ToString());
//string logPath = ActivityLog.LogFilePath; // This actually flushes the activity log buffer
throw;
} finally {
if (_variantStacks != null)
_variantStacks.Pop();
}
return OleCommand.MakeOleResult(result);
}