管理されていないライブラリでこのメソッドを呼び出したい:
void __stdcall GetConstraints(
unsigned int* puiMaxWidth,
unsigned int* puiMaxHeight,
unsigned int* puiMaxBoxes
);
私の解決策:
デリゲート定義:
[UnmanagedFunctionPointer(CallingConvention.StdCall)]プライベートデリゲートvoid GetConstraintsDel(UIntPtr puiMaxWidth、UIntPtr puiMaxHeight、UIntPtr puiMaxBoxes);
メソッドの呼び出し:
// PLUGIN NAME GetConstraintsDel getConstraints = (GetConstraintsDel)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(GetConstraintsDel)); uint maxWidth, maxHeight, maxBoxes; unsafe { UIntPtr a = new UIntPtr(&maxWidth); UIntPtr b = new UIntPtr(&maxHeight); UIntPtr c = new UIntPtr(&maxBoxes); getConstraints(a, b, c); }
動作しますが、「安全でない」フラグを許可する必要があります。安全でないコードのない解決策はありますか?または、このソリューションは大丈夫ですか?プロジェクトに安全でないフラグを設定することの意味をよく理解していません。
手伝ってくれてありがとう!