Electronic Engineer Discuss

Title: 关于C#二次开发6204BC的问题,调用GetData报内存受保护huo'sun'... [Print this page]

Author: Stillwater    Time: 2020-7-9 14:18
Title: 关于C#二次开发6204BC的问题,调用GetData报内存受保护huo'sun'...
Edited by Stillwater at 2020-7-9 14:20

我在用C#二次开发时遇到调用HTHardDll.dll中的dsoHTGetData()时发生“ System.AccessViolationException:“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”
”的错误,请问我的代码哪儿有问题吗?谢谢解答

[DllImport(“ HTHardDll.dll”,CharSet = CharSet.Unicode,CallingConvention = CallingConvention.StdCall)]
       p'rivate  unsafe extern short short dsoHTGetData(short nDeviceIndex,short * pCH1Data,short * pCH2Data,short * pCH3Data,short * pCH4Data,ControlData pControl);
        private static bool GetData(index,out short [] bufferCH1,out short [] bufferCH2,out short [] bufferCH3,out short [] bufferCH4,ControlData pControl)
        {
            bool readSuccess = false;
            bufferCH1 =new short [pControl.nReadDataLen];
            bufferCH2 =new short [pControl.nReadDataLen];
            bufferCH3 =new short [pControl.nReadDataLen];
            bufferCH4 =new short [pControl.nReadDataLen];
            unsafe
            {
                 fiexd(short * pBufferCH1 = bufferCH1)
                 fiexd(short * pBufferCH2 = bufferCH2)
                 fiexd(short * pBufferCH3 = bufferCH3)
                 fiexd(short * pBufferCH4 = bufferCH4)
                    readSuccess = dsoHTGetData(index,pBufferCH1,pBufferCH2,pBufferCH3,pBufferCH4,pControl)!= 0;此处发生“AccessViolationException:“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”错误
            }
             return readSuccess;
        }




Author: rossi1984    Time: 2020-7-11 00:27
同问,没有官方的c#demo,太郁闷了,楼主实验成功了吗?

Author: rossi1984    Time: 2020-7-12 15:32
楼上大侠,我这里 总是 报警 ,要么 1`无法加载 DLL“HTHardDll.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。
要么 2`试图加载格式不正确的程序。 (异常来自 HRESULT:0x8007000B)
切换项目属性的平台类别(X86,X64,ANY CPU)也不作用,请大侠指点一下,

Author: rossi1984    Time: 2020-7-25 10:11
借宝地在提问一下,请大神们关注一下吧
同样是RELAY_CONTROL的结构
在c++的demo中是这样定义的
typedef struct _HT_RELAY_CONTROL
{
        BOOL bCHEnable[MAX_CH_NUM];//此处定义的为 bool
        WORD nCHVoltDIV[MAX_CH_NUM];
        WORD nCHCoupling[MAX_CH_NUM];
        BOOL bCHBWLimit[MAX_CH_NUM];
        WORD nTrigSource;
        BOOL bTrigFilt;
        WORD nALT;
}RELAYCONTROL,*PRELAYCONTROL;
而在VB的demo中
Type RelayControl '详见SDK_HTHardDll_CHS.pdf
    bCHEnable(3) As Long//此处又定义为long了
    nCHVoltDIV(3) As Integer
    nCHCoupling(3) As Long
    bCHBWLimit(3) As Integer
    nTrigSource As Integer
    bTrigFilt As Long
    nALT As Integer
End Type
现在我调用C#调用dll同样也是报警,如何处理呀





Welcome to Electronic Engineer Discuss (https://www.eediscuss.com/) Powered by Discuz! X3.2