aboutsummaryrefslogtreecommitdiff
path: root/Src/Winamp/JSAPI.h
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Winamp/JSAPI.h
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/Winamp/JSAPI.h')
-rw-r--r--Src/Winamp/JSAPI.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/Src/Winamp/JSAPI.h b/Src/Winamp/JSAPI.h
new file mode 100644
index 00000000..a870f081
--- /dev/null
+++ b/Src/Winamp/JSAPI.h
@@ -0,0 +1,36 @@
+#pragma once
+
+// helper functions for IDispatch
+#define JSAPI_PARAM_INDEX(paramInfo, paramNumber) (paramInfo->cArgs - paramNumber)
+#define JSAPI_PARAM_EXISTS(paramInfo, paramNumber) (paramInfo->cArgs >= paramNumber)
+#define JSAPI_NUM_PARAMS(paramInfo) (paramInfo->cArgs)
+#define JSAPI_VERIFY_PARAMCOUNT(paramInfo, count) if (paramInfo->cArgs != count) return DISP_E_BADPARAMCOUNT
+#define JSAPI_VERIFY_PARAMCOUNT_OPTIONAL(paramInfo, minParams, maxParams) if (paramInfo->cArgs < minParams || paramInfo->cArgs > maxParams) return DISP_E_BADPARAMCOUNT
+#define JSAPI_VERIFY_PARAMTYPE(paramInfo, paramNumber, paramType, argErr) if (paramInfo->rgvarg[paramInfo->cArgs - paramNumber].vt != paramType) { *argErr = paramInfo->cArgs - paramNumber; return DISP_E_TYPEMISMATCH; }
+#define JSAPI_VERIFY_PARAMTYPE_OPTIONAL(paramInfo, paramNumber, paramType, argErr) if (JSAPI_PARAM_EXISTS(paramInfo, paramNumber) && paramInfo->rgvarg[paramInfo->cArgs - paramNumber].vt != paramType) { *argErr = paramInfo->cArgs - paramNumber; return DISP_E_TYPEMISMATCH; }
+#define JSAPI_GETSTRING(str, paramInfo, paramNumber, argErr) switch(paramInfo->rgvarg[paramInfo->cArgs - paramNumber].vt) { case VT_BSTR: str = paramInfo->rgvarg[paramInfo->cArgs - paramNumber].bstrVal; break; default: *argErr = paramInfo->cArgs - paramNumber; return DISP_E_TYPEMISMATCH; }
+#define JSAPI_GETNUMBER_AS_STRING(str, buffer, paramInfo, paramNumber, argErr) \
+ if (JSAPI_PARAM(paramInfo, paramNumber).vt == VT_I4) {\
+ int val_int = JSAPI_PARAM(paramInfo, paramNumber).lVal;\
+ StringCbPrintfW(buffer, sizeof(buffer), L"%d", val_int);\
+ str = buffer;\
+ } else if (JSAPI_PARAM(paramInfo, paramNumber).vt == VT_BSTR)\
+ str = JSAPI_PARAM(paramInfo, paramNumber).bstrVal;\
+ else {\
+ if (argErr) *argErr = paramInfo->cArgs - paramNumber;\
+ return DISP_E_TYPEMISMATCH;\
+ }
+#define JSAPI_GETUNSIGNED_AS_NUMBER(num, paramInfo, paramNumber, argErr) \
+ if (JSAPI_PARAM(paramInfo, paramNumber).vt == VT_I4) num = (UINT)JSAPI_PARAM(paramInfo, paramNumber).lVal;\
+ else if (JSAPI_PARAM(paramInfo, paramNumber).vt == VT_BSTR) num = wcstoul(JSAPI_PARAM(paramInfo, paramNumber).bstrVal,0, 10); \
+ else return DISP_E_TYPEMISMATCH;
+
+
+#define JSAPI_PARAM(paramInfo, paramNumber) (paramInfo->rgvarg[paramInfo->cArgs - paramNumber])
+#define JSAPI_PARAM_OPTIONAL(paramInfo, paramNumber, dispID, opt) (JSAPI_PARAM_EXISTS(paramInfo, paramNumber)?paramInfo->rgvarg[paramInfo->cArgs - paramNumber].##dispID:(opt))
+#define JSAPI_VERIFY_METHOD(flags) if (!(wFlags & DISPATCH_METHOD)) return DISP_E_MEMBERNOTFOUND
+#define JSAPI_INIT_RESULT(result, type) if (result) { VariantInit(result); V_VT(result) = type; }
+#define JSAPI_SET_RESULT(result, field, value) if (result) { (result)->field = value; }
+#define JSAPI_EMPTY_RESULT(result) if (result) { V_VT(result) = VT_EMPTY; }
+#define JSAPI_SET_VARIANT(result, macro, value) if (result) { macro(result) = value; }
+#define JSAPI_DISP_ENUMIFY(x) __jsapi__enum__ ## x