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:
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.