Dll C# "System.AccessViolationException"
От: Kitofnet  
Дата: 29.11.13 23:55
Оценка:
Помогите перенести функцию из Dll

c++
#ifdef HTMARCH_EXPORTS
#define HTMARCH_API extern "C" __declspec(dllexport)
#else
#define HTMARCH_API extern "C"__declspec(dllimport)
#endif
#define WINAPI __stdcall

HTMARCH_API short WINAPI dsoReadHardData(WORD DeviceIndex,short* pCH1Data, short* pCH2Data,ULONG nReadLen,short* pCalLevel,int nCH1VoltDIV,int


    [DllImport("HTMarch.dll", CharSet = CharSet.Unicode)]
        public static extern short dsoReadHardData(short DeviceIndex,ref short[] pCH1Data,ref short[] pCH2Data, ulong nReadLen,
      ref short[] pCalLevel,int nCH1VoltDIV,int nCH2VoltDIV,short nTrigSweep,short nTrigSrc,short nTrigLevel,short nSlope,
      int nTimeDIV,short nHTrigPos,ulong nDisLen,ref ulong nTrigPoint,short nInsertMode);

Вызов функции



                int nReadLen = 10240;//10k
                int nDrawLen = 10000;
                short nTrigLevel = 64;
                short nSlope = 0;// 0:Rise; 1: Fall
                short nHTrigPos = 50;// 0 ~ 100
                ulong nTrigPoint = 0;
                short[] pCH1Data = new short[nReadLen];
                short[] pCH2Data = new short[nReadLen];
           
                short nRe = Hantek.dsoReadHardData(m_nDevIndex,
                                            ref pCH1Data,
                                            ref pCH2Data,
                                            (ulong)nReadLen,
                                            ref m_nCalData,
                                            m_nCH1VoltDIV,
                                            m_nCH2VoltDIV,
                                            0,//0:AUOT; 1:Normal; 2: Signal
                                            0,//CH1
                                             nTrigLevel,
                                            nSlope,
                                            m_nTimeDIV,
                                            nHTrigPos,
                                            (ulong)nDrawLen,
                                             ref nTrigPoint,
                                            0);

Данные об ошибке
System.AccessViolationException не обработано
_HResult=-2147467261
_message=Попытка чтения или записи в защищенную память. Это часто свидетельствует о том, что другая память повреждена.
HResult=-2147467261
IsTransient=false
Message=Попытка чтения или записи в защищенную память. Это часто свидетельствует о том, что другая память повреждена.
Source=testnode
StackTrace:
в testnode.Hantek.dsoReadHardData(Int16 DeviceIndex, Int16[]& pCH1Data, Int16[]& pCH2Data, UInt64 nReadLen, Int16[]& pCalLevel, Int32 nCH1VoltDIV, Int32 nCH2VoltDIV, Int16 nTrigSweep, Int16 nTrigSrc, Int16 nTrigLevel, Int16 nSlope, Int32 nTimeDIV, Int16 nHTrigPos, UInt64 nDisLen, UInt64& nTrigPoint, Int16 nInsertMode)
в testnode.Form1.button1_Click(Object sender, EventArgs e) в c:\Users\Kobyakin Nikita kit\Documents\Visual Studio 2013\Projects\testnode\testnode\Form1.cs:строка 55
в System.Windows.Forms.Control.OnClick(EventArgs e)
в System.Windows.Forms.Button.OnClick(EventArgs e)
в System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
в System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
в System.Windows.Forms.Control.WndProc(Message& m)
в System.Windows.Forms.ButtonBase.WndProc(Message& m)
в System.Windows.Forms.Button.WndProc(Message& m)
в System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
в System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
в System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
в System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
в System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
в System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
в System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
в System.Windows.Forms.Application.Run(Form mainForm)
в testnode.Program.Main() в c:\Users\Kobyakin Nikita kit\Documents\Visual Studio 2013\Projects\testnode\testnode\Program.cs:строка 19
в System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
в System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
в Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
в System.Threading.ThreadHelper.ThreadStart_Context(Object state)
в System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
в System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
в System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
в System.Threading.ThreadHelper.ThreadStart()
InnerException:
Re: Как это изобразить на С#?
От: SSTREGG Россия  
Дата: 01.12.13 15:07
Оценка:
Здравствуйте, Kitofnet, Вы писали:

K>Помогите перенести функцию из Dll


K>c++

K>
K>#ifdef HTMARCH_EXPORTS
K>#define HTMARCH_API extern "C" __declspec(dllexport)
K>#else
K>#define HTMARCH_API extern "C"__declspec(dllimport)
K>#endif
K>#define WINAPI __stdcall

K>HTMARCH_API short WINAPI dsoReadHardData(WORD DeviceIndex,short* pCH1Data, short* pCH2Data,ULONG nReadLen,short* pCalLevel,int nCH1VoltDIV,int


K>
K>    [DllImport("HTMarch.dll", CharSet = CharSet.Unicode)]
K>        public static extern short dsoReadHardData(short DeviceIndex,ref short[] pCH1Data,ref short[] pCH2Data, ulong nReadLen,
K>      ref short[] pCalLevel,int nCH1VoltDIV,int nCH2VoltDIV,short nTrigSweep,short nTrigSrc,short nTrigLevel,short nSlope,
K>      int nTimeDIV,short nHTrigPos,ulong nDisLen,ref ulong nTrigPoint,short nInsertMode);
K>

K>Вызов функции

K>


K>                int nReadLen = 10240;//10k
K>                int nDrawLen = 10000;
K>                short nTrigLevel = 64;
K>                short nSlope = 0;// 0:Rise; 1: Fall
K>                short nHTrigPos = 50;// 0 ~ 100
K>                ulong nTrigPoint = 0;
K>                short[] pCH1Data = new short[nReadLen];
K>                short[] pCH2Data = new short[nReadLen];
           
K>                short nRe = Hantek.dsoReadHardData(m_nDevIndex,
K>                                            ref pCH1Data,
K>                                            ref pCH2Data,
K>                                            (ulong)nReadLen,
K>                                            ref m_nCalData,
K>                                            m_nCH1VoltDIV,
K>                                            m_nCH2VoltDIV,
K>                                            0,//0:AUOT; 1:Normal; 2: Signal
K>                                            0,//CH1
K>                                             nTrigLevel,
K>                                            nSlope,
K>                                            m_nTimeDIV,
K>                                            nHTrigPos,
K>                                            (ulong)nDrawLen,
K>                                             ref nTrigPoint,
K>                                            0);

K>

K>Данные об ошибке
K>System.AccessViolationException не обработано
K> _HResult=-2147467261
K> _message=Попытка чтения или записи в защищенную память. Это часто свидетельствует о том, что другая память повреждена.
K> HResult=-2147467261
K> IsTransient=false
K> Message=Попытка чтения или записи в защищенную память. Это часто свидетельствует о том, что другая память повреждена.
K> Source=testnode
K> StackTrace:
K> в testnode.Hantek.dsoReadHardData(Int16 DeviceIndex, Int16[]& pCH1Data, Int16[]& pCH2Data, UInt64 nReadLen, Int16[]& pCalLevel, Int32 nCH1VoltDIV, Int32 nCH2VoltDIV, Int16 nTrigSweep, Int16 nTrigSrc, Int16 nTrigLevel, Int16 nSlope, Int32 nTimeDIV, Int16 nHTrigPos, UInt64 nDisLen, UInt64& nTrigPoint, Int16 nInsertMode)
K> в testnode.Form1.button1_Click(Object sender, EventArgs e) в c:\Users\Kobyakin Nikita kit\Documents\Visual Studio 2013\Projects\testnode\testnode\Form1.cs:строка 55
K> в System.Windows.Forms.Control.OnClick(EventArgs e)
K> в System.Windows.Forms.Button.OnClick(EventArgs e)
K> в System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
K> в System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
K> в System.Windows.Forms.Control.WndProc(Message& m)
K> в System.Windows.Forms.ButtonBase.WndProc(Message& m)
K> в System.Windows.Forms.Button.WndProc(Message& m)
K> в System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
K> в System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
K> в System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
K> в System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
K> в System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
K> в System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
K> в System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
K> в System.Windows.Forms.Application.Run(Form mainForm)
K> в testnode.Program.Main() в c:\Users\Kobyakin Nikita kit\Documents\Visual Studio 2013\Projects\testnode\testnode\Program.cs:строка 19
K> в System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
K> в System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
K> в Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
K> в System.Threading.ThreadHelper.ThreadStart_Context(Object state)
K> в System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
K> в System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
K> в System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
K> в System.Threading.ThreadHelper.ThreadStart()
K> InnerException:


[DllImport("HTMarch.dll", CharSet = CharSet.Unicode)]
public static extern short dsoReadHardData(
    short DeviceIndex, short[] pCH1Data, short[] pCH2Data, uint nReadLen,
    short[] pCalLevel, int nCH1VoltDIV, int nCH2VoltDIV, short nTrigSweep,
    short nTrigSrc, short nTrigLevel, short nSlope, int nTimeDIV, short nHTrigPos,
    uint nDisLen, ref uint nTrigPoint, short nInsertMode);

Если ошибка останется, то приводите полное описание функции, ну и библиотеку можно было бы посмотреть на всякий случай.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.