-pascal OSErr AmIBeingMWDebugged(Boolean* result)
-{
- OSErr err;
- ProcessSerialNumber psn;
- OSType sig = kDebuggerSignature;
- AppleEvent theAE = {typeNull, NULL};
- AppleEvent theReply = {typeNull, NULL};
- AEAddressDesc addr = {typeNull, NULL};
- DescType actualType;
- Size actualSize;
-
- if (!result) return paramErr;
-
- err = AECreateDesc(typeApplSignature, &sig, sizeof(sig), &addr);
- if (err != noErr) goto exit;
-
- err = AECreateAppleEvent(kDebuggerSignature, 'Dbg?', &addr,
- kAutoGenerateReturnID, kAnyTransactionID, &theAE);
- if (err != noErr) goto exit;
-
- GetCurrentProcess(&psn);
- err = AEPutParamPtr(&theAE, keyDirectObject, typeProcessSerialNumber,
- &psn, sizeof(psn));
- if (err != noErr) goto exit;
-
- err = AESend(&theAE, &theReply, kAEWaitReply, kAENormalPriority,
- kAEDefaultTimeout, NULL, NULL);
- if (err != noErr) goto exit;
-
- err = AEGetParamPtr(&theReply, keyAEResult, typeBoolean, &actualType, result,
- sizeof(Boolean), &actualSize);
-
-exit:
- if (addr.dataHandle)
- AEDisposeDesc(&addr);
- if (theAE.dataHandle)
- AEDisposeDesc(&theAE);
- if (theReply.dataHandle)
- AEDisposeDesc(&theReply);