.net 如何在C#中封送int*?
我想在非托管库中调用此方法:.net 如何在C#中封送int*?,.net,marshalling,intptr,.net,Marshalling,Intptr,我想在非托管库中调用此方法: void __stdcall GetConstraints( unsigned int* puiMaxWidth, unsigned int* puiMaxHeight, unsigned int* puiMaxBoxes ); 我的解决方案: 委托定义: [非托管函数指针(CallingConvention.StdCall)] 私有委托void GetConstraintsDel(uintpttr puiMaxWidth、uintpttr
void __stdcall GetConstraints(
unsigned int* puiMaxWidth,
unsigned int* puiMaxHeight,
unsigned int* puiMaxBoxes
);
我的解决方案:
- 委托定义: [非托管函数指针(CallingConvention.StdCall)] 私有委托void GetConstraintsDel(uintpttr puiMaxWidth、uintpttr puiMaxHeight、uintpttr puimaxbox)
- 方法的调用:
// 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); }
uint GetTypeDefProps
(
uint td,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex=2)]char[] szTypeDef,
uint cchTypeDef,
out uint pchTypeDef,
out uint pdwTypeDefFlags,
out uint ptknds
);
样本使用
char[] SzTypeDef;
uint CchTypeDef;
uint PchMember;
IntPtr PpvSigBlob;
uint PbSigBlob;
SzTypeDef= new char[500];
CchTypeDef= (uint)SzTypeDef.Length;
ResPT=
MetaDataImport.GetTypeDefProps
(
td,
SzTypeDef,
CchTypeDef,
out pchTypeDef,
out pdwTypeDefFlags,
out ptkExtends
);
我相信它应该按原样工作(减去操作员的地址),没有不安全的块…它不工作。UINTPTTR的构造函数将指针地址作为参数。
char[] SzTypeDef;
uint CchTypeDef;
uint PchMember;
IntPtr PpvSigBlob;
uint PbSigBlob;
SzTypeDef= new char[500];
CchTypeDef= (uint)SzTypeDef.Length;
ResPT=
MetaDataImport.GetTypeDefProps
(
td,
SzTypeDef,
CchTypeDef,
out pchTypeDef,
out pdwTypeDefFlags,
out ptkExtends
);