- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我遇到了一个问题,我已经两天没能解决了。
错误信息如下所示:
无法获取托管类型的地址、大小或声明指向托管类型的指针('Control_Vertilon.Imports.PHOTONIQ_CONFIG_TABLE')
下面是代码,
UInt16[] Arguments = new UInt16[PHOTONIQ_ARG_BUFF_SZ];
PHOTONIQ_CONFIG_TABLE PhotoniqConfigTable = new PHOTONIQ_CONFIG_TABLE();
UInt16 *cfgPtr = (UInt16*)&PhotoniqConfigTable;
for(int i = 0; i < Imports.CONFIG_TABLE_SZ; i++){
Arguments[i+1] = *cfgPtr++;
}
Imports.ControlInterface(Opcode, Arguments, 0x1, Imports.TimeoutMs, ref errInNoErrorStruct, ref NumRetArguments, ref PhotoniqConfigTable, Imports.CONFIG_TABLE_SZ, ref errOutStruct);
我整理的 PhotoniqConfigTable 如下所示,
[StructLayout(LayoutKind.Sequential)]
unsafe public struct PHOTONIQ_CONFIG_TABLE
{
[MarshalAs(UnmanagedType.U2)]
public UInt16 SystemMode; //Indicates current system mode, acquire or standby mode 0 = Standby Mode 1 = Acquire Mode
[MarshalAs(UnmanagedType.U2)]
public UInt16 HVLimit0; // Maximum allowed voltage on HV supply 1 Range = 500 ?9250 (50 ?925V)
[MarshalAs(UnmanagedType.U2)]
public UInt16 HVLimit1;
[MarshalAs(UnmanagedType.U2)]
public UInt16 NumChannelsB0;
[MarshalAs(UnmanagedType.U2)]
public UInt16 NumChannelsB1;
[MarshalAs(UnmanagedType.U2)]
public UInt16 NumChannelsB2;
[MarshalAs(UnmanagedType.U2)]
public UInt16 NumChannelsB3;
[MarshalAs(UnmanagedType.U2)]
public UInt16 HVEnabled;
[MarshalAs(UnmanagedType.U2)]
public UInt16 HVSetpoint0;
[MarshalAs(UnmanagedType.U2)]
public UInt16 HVSetpoint1;
[MarshalAs(UnmanagedType.U2)]
public UInt16 UserConfigID;
[MarshalAs(UnmanagedType.U2)]
public UInt16 DCRD_AOut_0;
[MarshalAs(UnmanagedType.U2)]
public UInt16 BandEnables;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band0StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band0StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band1StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band1StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band2StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band2StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band3StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band3StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band4StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band4StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band5StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band5StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band6StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band6StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band7StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band7StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 FlagEnables; // pterm flag enables
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public UInt16[] Flag0Operands; // flag 0 operands: 64 bits
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public UInt16[] Flag1Operands; // flag 0 operands: 64 bits
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public UInt16[] Flag2Operands; // flag 0 operands: 64 bits
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public UInt16[] Flag3Operands; // flag 0 operands: 64 bits
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public UInt16[] Flag4Operands; // flag 0 operands: 64 bits
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public UInt16[] Flag5Operands; // flag 0 operands: 64 bits
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public UInt16[] Flag6Operands; // flag 0 operands: 64 bits
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public UInt16[] Flag7Operands; // flag 0 operands: 64 bits
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm0; // flag 0 - 7 product terms
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm1;
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm2;
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm3;
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm4;
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm5;
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm6;
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm7;
[MarshalAs(UnmanagedType.U2)]
public UInt16 DataFilterEnable; // 1 = enable spectral filtering, 0 = disable
[MarshalAs(UnmanagedType.U2)]
public UInt16 ProcessingEnables; // bit 0 = spect filt, bit 1 = gain, 2 = bkgnd sub.
[MarshalAs(UnmanagedType.U2)]
public UInt16 TimestampEnable; // 1 = enable time stamp, 0 = disable
[MarshalAs(UnmanagedType.U2)]
public UInt16 DACspare;
[MarshalAs(UnmanagedType.I4)]
public Int32 TimestampInterval; //
[MarshalAs(UnmanagedType.U2)]
public UInt16 CustomWordsEnable; // 1/0
[MarshalAs(UnmanagedType.U2)]
public UInt16 EventCustomCount; //
[MarshalAs(UnmanagedType.U2)]
public UInt16 RESERVED;
[MarshalAs(UnmanagedType.U2)]
public UInt16 ImageAcqMode; // 1 = image, 0 = particle
[MarshalAs(UnmanagedType.U2)]
public UInt16 InputTrigThresh;
[MarshalAs(UnmanagedType.U2)]
public UInt16 InputTrigChannel; //
[MarshalAs(UnmanagedType.U2)]
public UInt16 RangeErrorEnable; // 1 = enable range error, 0 = disable
[MarshalAs(UnmanagedType.U2)]
public UInt16 CrossBankConfig; //
[MarshalAs(UnmanagedType.U2)]
public UInt16 ReportPackingMode; //
[MarshalAs(UnmanagedType.U2)]
public UInt16 GPOutputEnable; //
[MarshalAs(UnmanagedType.I4)]
public Int32 GPOutputDelay; //
[MarshalAs(UnmanagedType.I4)]
public Int32 GPOutputPeriod; //
[MarshalAs(UnmanagedType.U2)]
public UInt16 IntBoxcarEnable;
[MarshalAs(UnmanagedType.U2)]
public UInt16 BoxcarWidthEnable;
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public Int32[] ResetDelay;
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public UInt16[] TrigSource;
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public Int32[] TrigPeriod;
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public Int32[] IntegPeriod;
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public Int32[] IntegDelay;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel0;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel1;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel2;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel3;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel4;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel5;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel6;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel7;
[MarshalAs(UnmanagedType.I4)]
public Int32 TriggerEndCount;
[MarshalAs(UnmanagedType.U2)]
public UInt16 TrigStampSelect;
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public UInt16[] DataFormat; // 4 banks: 0 = 17bit sign/mag, 1 = 16bit 2's, comp, 2 = 16b, 2's 1/2 scale
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 7)]
public UInt16[] RESERVED1;
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 256)]
public UInt16[] GainArray;
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 256)]
public UInt16[] TrigThreshArray;
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 16)]
public UInt16[] TrigEnableArray; // 256 bits, 1/0 for each channel (max of 256 channels)
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 322)]
public UInt16[] RESERVED2; // 678-999
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 250)]
public UInt16[] CustomArray; // user custom space: 1000-1249
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 567)]
public UInt16[] FactoryArray; // start of factory table
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 32)]
public SByte[] ModelNumber; // model number
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 151)]
public UInt16[] FactoryArray1; // last piece of factory table
}
问题是,我以为我将结构设为非托管类型,但编译器却说它是托管类型。
或者可能是指向这种方式的 UInt16 指针在托管代码中是错误的。
buffer Argument[] 是 16 位的,这是 dll 函数中的传递参数,所以我坚持使用 16 位,无论是用作指针还是缓冲区来移动数据。
如果有人能帮助解决这个问题,那将是一个巨大的帮助。
我在网上搜索过,但找不到准确的答案。
提前致谢。
============================================= ===================================
您好,感谢您的回复,
在这里,我收到以下代码的不同错误:
fixed (UInt16 *cfgPtr = (UInt16*)&PhotoniqConfigTable){
//modify config table, then send it back up to PhotoniQ
PhotoniqConfigTable.NumChannelsB0 = 6;
PhotoniqConfigTable.IntegPeriod[0] = per;
PhotoniqConfigTable.TrigPeriod[0] = 100000;
PhotoniqConfigTable.TrigStampSelect = 1;
PhotoniqConfigTable.TimestampEnable = 0;
PhotoniqConfigTable.RangeErrorEnable = 0;
PhotoniqConfigTable.DataFormat[0] = 0;
PhotoniqConfigTable.GPOutputEnable = 1;
PhotoniqConfigTable.GPOutputDelay = 10;
PhotoniqConfigTable.GPOutputPeriod = 1000;
for (int i = 0; i < Imports.CONFIG_TABLE_SZ; i++)
{
Arguments[i + 1] = *cfgPtr++;
}
}
错误信息是:
无法分配给“cfgPtr”,因为它是“固定变量”。
固定语句赋值的右侧不能是强制转换表达式。
您不能使用包含在不固定表达式中的固定大小缓冲区。尝试使用 fixed 语句。 (不同行三个相同的错误)
任何可以向我解释的人都会有很大的帮助,因为我的时间很紧。
现在的结构如下所示:
[StructLayout(LayoutKind.Sequential)]
unsafe public struct PHOTONIQ_CONFIG_TABLE
{
[MarshalAs(UnmanagedType.U2)]
public UInt16 SystemMode; //Indicates current system mode, acquire or standby mode 0 = Standby Mode 1 = Acquire Mode
[MarshalAs(UnmanagedType.U2)]
public UInt16 HVLimit0; // Maximum allowed voltage on HV supply 1 Range = 500 ?9250 (50 ?925V)
[MarshalAs(UnmanagedType.U2)]
public UInt16 HVLimit1;
[MarshalAs(UnmanagedType.U2)]
public UInt16 NumChannelsB0;
[MarshalAs(UnmanagedType.U2)]
public UInt16 NumChannelsB1;
[MarshalAs(UnmanagedType.U2)]
public UInt16 NumChannelsB2;
[MarshalAs(UnmanagedType.U2)]
public UInt16 NumChannelsB3;
[MarshalAs(UnmanagedType.U2)]
public UInt16 HVEnabled;
[MarshalAs(UnmanagedType.U2)]
public UInt16 HVSetpoint0;
[MarshalAs(UnmanagedType.U2)]
public UInt16 HVSetpoint1;
[MarshalAs(UnmanagedType.U2)]
public UInt16 UserConfigID;
[MarshalAs(UnmanagedType.U2)]
public UInt16 DCRD_AOut_0;
[MarshalAs(UnmanagedType.U2)]
public UInt16 BandEnables;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band0StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band0StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band1StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band1StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band2StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band2StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band3StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band3StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band4StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band4StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band5StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band5StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band6StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band6StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band7StartIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 Band7StopIndex;
[MarshalAs(UnmanagedType.U2)]
public UInt16 FlagEnables; // pterm flag enables
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed UInt16 Flag0Operands[4]; // flag 0 operands: 64 bits
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed UInt16 Flag1Operands[4]; // flag 0 operands: 64 bits
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed UInt16 Flag2Operands[4]; // flag 0 operands: 64 bits
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed UInt16 Flag3Operands[4]; // flag 0 operands: 64 bits
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed UInt16 Flag4Operands[4]; // flag 0 operands: 64 bits
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed UInt16 Flag5Operands[4]; // flag 0 operands: 64 bits
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed UInt16 Flag6Operands[4]; // flag 0 operands: 64 bits
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed UInt16 Flag7Operands[4]; // flag 0 operands: 64 bits
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm0; // flag 0 - 7 product terms
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm1;
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm2;
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm3;
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm4;
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm5;
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm6;
[MarshalAs(UnmanagedType.U2)]
public UInt16 PTerm7;
[MarshalAs(UnmanagedType.U2)]
public UInt16 DataFilterEnable; // 1 = enable spectral filtering, 0 = disable
[MarshalAs(UnmanagedType.U2)]
public UInt16 ProcessingEnables; // bit 0 = spect filt, bit 1 = gain, 2 = bkgnd sub.
[MarshalAs(UnmanagedType.U2)]
public UInt16 TimestampEnable; // 1 = enable time stamp, 0 = disable
[MarshalAs(UnmanagedType.U2)]
public UInt16 DACspare;
[MarshalAs(UnmanagedType.I4)]
public Int32 TimestampInterval; //
[MarshalAs(UnmanagedType.U2)]
public UInt16 CustomWordsEnable; // 1/0
[MarshalAs(UnmanagedType.U2)]
public UInt16 EventCustomCount; //
[MarshalAs(UnmanagedType.U2)]
public UInt16 RESERVED;
[MarshalAs(UnmanagedType.U2)]
public UInt16 ImageAcqMode; // 1 = image, 0 = particle
[MarshalAs(UnmanagedType.U2)]
public UInt16 InputTrigThresh;
[MarshalAs(UnmanagedType.U2)]
public UInt16 InputTrigChannel; //
[MarshalAs(UnmanagedType.U2)]
public UInt16 RangeErrorEnable; // 1 = enable range error, 0 = disable
[MarshalAs(UnmanagedType.U2)]
public UInt16 CrossBankConfig; //
[MarshalAs(UnmanagedType.U2)]
public UInt16 ReportPackingMode; //
[MarshalAs(UnmanagedType.U2)]
public UInt16 GPOutputEnable; //
[MarshalAs(UnmanagedType.I4)]
public Int32 GPOutputDelay; //
[MarshalAs(UnmanagedType.I4)]
public Int32 GPOutputPeriod; //
[MarshalAs(UnmanagedType.U2)]
public UInt16 IntBoxcarEnable;
[MarshalAs(UnmanagedType.U2)]
public UInt16 BoxcarWidthEnable;
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed Int32 ResetDelay[4];
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed UInt16 TrigSource[4];
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed Int32 TrigPeriod[4];
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed Int32 IntegPeriod[4];
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed Int32 IntegDelay[4];
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel0;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel1;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel2;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel3;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel4;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel5;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel6;
[MarshalAs(UnmanagedType.U2)]
public UInt16 SibSel7;
[MarshalAs(UnmanagedType.I4)]
public Int32 TriggerEndCount;
[MarshalAs(UnmanagedType.U2)]
public UInt16 TrigStampSelect;
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed UInt16 DataFormat[4]; // 4 banks: 0 = 17bit sign/mag, 1 = 16bit 2's, comp, 2 = 16b, 2's 1/2 scale
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 7)]
public fixed UInt16 RESERVED1[7];
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 256)]
public fixed UInt16 GainArray[256];
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 256)]
public fixed UInt16 TrigThreshArray[256];
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 16)]
public fixed UInt16 TrigEnableArray[16]; // 256 bits, 1/0 for each channel (max of 256 channels)
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 322)]
public fixed UInt16 RESERVED2[322]; // 678-999
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 250)]
public fixed UInt16 CustomArray[250]; // user custom space: 1000-1249
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 567)]
public fixed UInt16 FactoryArray[567]; // start of factory table
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 32)]
public fixed SByte ModelNumber[32]; // model number
//[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 151)]
public fixed UInt16 FactoryArray1[151];
//public fixed UInt16 FactoryArray1[151]; // last piece of factory table
};
最佳答案
第二个答案,回答你的第二个问题:
The error messages are:
Cannot assign to 'cfgPtr' because it is a 'fixed variable'.
The right hand side of a fixed statement assignment may not be a cast expression.
You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement.
错误消息告诉您哪里出了问题。阅读它们。
Cannot assign to 'cfgPtr' because it is a 'fixed variable'.
你在这里分配给它:
Arguments[i + 1] = *cfgPtr++;
一旦您初始化了一个包含指向固定空间 block 的指针的变量,您就不能更改该变量因为您可能会将其更改为指向一个非固定空间 block 。为了防止这个常见错误,C# 阻止您修改该变量。
如果您想修改变量,改为创建一个不同的变量。将其设置为等于 cfgPtr
,然后修改 that 变量。确保你做得正确;你现在有责任确保你的指针指向固定的东西。
The right hand side of a fixed statement assignment may not be a cast expression.
在我的上一个回答中,我告诉您阅读规范的第 18.7 节,其中指出“固定”语句采用:
A simple-name or member-access that references a fixed size buffer member of a moveable variable
强制转换表达式不是“简单名称或成员访问”。强制转换表达式是强制转换表达式。而且这个 Actor 甚至没有意义!指向结构的指针不是指向 ushort 的指针!
删除类型转换。将初始化程序中的表达式更改为对可移动变量的固定大小缓冲区成员的成员访问。
You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement.
您正在直接使用固定大小的缓冲区。 你不能那样做。你只能通过获取指向它的指针来使用固定大小的缓冲区。同样,这是安全系统的一部分,可确保您不会意外访问未就地固定的固定大小缓冲区。停止尝试直接访问缓冲区。获取指向缓冲区的指针并通过指针访问它。
anybody who can explain to me will be great help since I am in short of time.
让我非常清楚这一点:您已经关闭了托管安全系统,您的程序的正确性和流程的稳定性现在是您的问题,而不是托管运行时的问题。如果您不了解有关如何安全地管理您自己的指针的一切,请停止您正在做的事情并仔细阅读直到您理解为止。如果现在就匆忙编写一大堆你不理解的代码,你将冒着以后不得不处理可怕错误的风险。现在不是匆忙的时候。
首先阅读第 18 章的全部内容。只有彻底理解所有内容后,您才能尝试编写复杂的不安全代码。
关于c# - 在c#中声明一个指向c dll中的非托管结构的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7603230/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!