Please select To the mobile version | Continue to access the desktop computer version

Electronic Engineer Discuss

View: 5750|Reply: 3

关于C#二次开发6204BC的问题,调用GetData报内存受保护huo'sun'...

[Copy link]

2

Threads

2

Posts

2

Credits

新手上路

Rank: 1

Credits
2
Post time 2020-7-9 14:18:09 | Show all posts |Read mode
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;
        }



This post contains more resources

You have to Login for download or view attachment(s). No Account? Register

x
Reply

Use magic Report

0

Threads

4

Posts

4

Credits

新手上路

Rank: 1

Credits
4
Post time 2020-7-11 00:27:02 | Show all posts
同问,没有官方的c#demo,太郁闷了,楼主实验成功了吗?

0

Threads

4

Posts

4

Credits

新手上路

Rank: 1

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

0

Threads

4

Posts

4

Credits

新手上路

Rank: 1

Credits
4
Post time 2020-7-25 10:11:40 | Show all posts
借宝地在提问一下,请大神们关注一下吧
同样是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同样也是报警,如何处理呀
You have to log in before you can reply Login | Register

Points Rules

Dark room|Mobile|Archiver|Electronic Engineer Discuss

2024-3-29 18:27 GMT+8 , Processed in 0.229480 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

Quick Reply To Top Return to the list