الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

AccessViolationException

مغلق
بدأه magzz في 30 يونيو 2006 · 7 رد · 868 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله

اهلا شباب انا كنت بعمل كود علشان اشغل بيه وظايف قراءة وكتابة على memory card

فكنت باستخدم dll اللى مع البرنامج

import dllبتاع

البرنامج وتمام عملت وابتديت انادى على

functions

بخصوص الكود بتاعى

انا عملت import for dll

[DllImport("SCARD32.DLL", EntryPoint="SCardComand", SetLastError=true, CallingConvention=CallingConvention.Winapi, CharSet=CharSet.Ansi, ExactSpelling=true)]

public static extern int SCardComand(int handle , [MarshalAs(UnmanagedType.BStr)] string cmd , int cmdLen , [MarshalAs(UnmanagedType.BStr)] string dataIn, int dataInLen , [MarshalAs(UnmanagedType.BStr)] string dataOut, int dataOutLen);

وعملت ليها function

وكله تمام وعملت على سبيل التجربة

read memory function

int L;

string D = " ";

//D = String(200, 0);

string nil="";

L = SCardComand(0, "Card,Memread,1152,1183", 0, nil, 0, D, 200);

MessageBox.Show(D);

ولما جيت اعمل ليها run

طلع ليا Exception

************** Exception Text **************

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

at WindowsApplication1.Form1.SCardComand(Int32 handle, String cmd, Int32 cmdLen, String dataIn, Int32 dataInLen, String dataOut, Int32 dataOutLen)

at WindowsApplication1.Form1.button1_Click(Object sender, EventArgs e) in I:\s\s\Form1.cs:line 41

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************

mscorlib

Assembly Version: 2.0.0.0

Win32 Version: 2.0.50727.42 (RTM.050727-4200)

CodeBase: file:///D:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll

----------------------------------------

s

Assembly Version: 1.0.0.0

Win32 Version: 1.0.0.0

CodeBase: file:///I:/s/s/bin/Release/s.exe

----------------------------------------

System.Windows.Forms

Assembly Version: 2.0.0.0

Win32 Version: 2.0.50727.42 (RTM.050727-4200)

CodeBase: file:///D:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll

----------------------------------------

System

Assembly Version: 2.0.0.0

Win32 Version: 2.0.50727.42 (RTM.050727-4200)

CodeBase: file:///D:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll

----------------------------------------

System.Drawing

Assembly Version: 2.0.0.0

Win32 Version: 2.0.50727.42 (RTM.050727-4200)

CodeBase: file:///D:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll

----------------------------------------

************** JIT Debugging **************

To enable just-in-time (JIT) debugging, the .config file for this

application or computer (machine.config) must have the

jitDebugging value set in the system.windows.forms section.

The application must also be compiled with debugging

enabled.

For example:

<configuration>

<system.windows.forms jitDebugging="true" />

</configuration>

When JIT debugging is enabled, any unhandled exception

will be sent to the JIT debugger registered on the computer

rather than be handled by this dialog box.

مع العلم انا باستخدم vc#2005

وعملتimport unmanaged

dll

انا حاولت مع الexception ده بس مش عارف اتعامل معاه كل مرة لما بيعمل dubgging

متشكر جدا يا اخوانى على تعبكم معانا

وجزاك الله خيرا

ماجد

#2
اقتباس
Attempted to read or write protected memory

الـ Memory Card الذي تسخدمه مقفل (مثل الـ Floppy Disk)، ابحث عن مكان الفتح في الكارت نفسه و جرب..

رأس الحكمة الإيمان بالله

#3

السلام عليكم

لا ال memory card اعتقد انه مالوش دعوة

انا اعتقد ان الexception ده بيظهر علشان انا مستخدم umanaged code

انا عايز حد يدينى الحل لو سمحتم مستعجل جدا

ده مشروع تخرج يا ناس

وشكرا

وربنا يكون معانا كلنا

ماجد

#4

السلام عليكم ورحمة الله

اود ان اشكر وجود هذا المنتدى لمدى نفعه الشديد الذى يعود على سائر الاخوان بالنفع والثواب لمن يعطى المعلومة

ولكن انا يا جماعة واقع فى مشكلة ومحتاج حد معايا فيها باررررب تبعتلى اللى يساعدنى انا يا جماعة بقالى يومين ناشر الموضوع ومحدش رد عليا

ساعدونى رحمكم الله

ماجد

#5

هل البرنامج الذي يستخدم Scard32.dll هذه يعمل بصوره صحيحه على جهازك ؟

واذا كان يعمل, هل انت متأكد أنه لا يستخدم DLLs أخرى أو لا يتسدعي Methods معينه قبل استدعاء SCardComand ؟

على أي Windows تعمل ؟

#Read

http://MoutazShams.blogspot.com

projects003.gif

أعتذر عن التغيب هذه الأيام نظرا للانشغال المريب

#6

أيضا جرب هذا الاعلان :

[DllImport("SCARD32.DLL")]
public static extern long SCardComand(long handle,
									  string cmd,long cmdLen,
									  string dataIn,long dataInLen,
									  string dataOut,long dataOutLen);

وهل أنت متأكد أن القيم التي مررتها للـ cmdLen وللـ dataOutLen هي قيم سليمه ؟

#Read

http://MoutazShams.blogspot.com

projects003.gif

أعتذر عن التغيب هذه الأيام نظرا للانشغال المريب

#7

متشكر يا استاذ معتز على التعاون والجدعنة التمام

انا شغال على SP2-winXP

VC#2005

وايوة البرنامج شغال مع الScard32.dll تمام علشان كان فيه برنامج تطبيق بسيط كده بال فيجوال بيسك شغال برضه معاه تمام

ومفيش حاجة خالص بيحتاج ليها غير Scard32.dll بس وخلاص

بس انا المفروض انادى ال functionsاللى اانا عايزها

وهى جاية مع الdata sheet بتاع الجهاز smart card reader

وانا على فكرة جربت الكود بتاعك وبرضه لسه بيدينى نفس المشكلة

ووصف الfunction مضبوط

L = SCardComand ( 0 , "Card,Memread,1152,1183", 0, nil, 0, D, 200); 0

انت عارف انا حاسس انها مشكلة compiler علشان انا اول مرة اشتغل 2005

وشكلها كده مش تمام

على فكرة انا عايز اوريك الكود باستخدام الvb.net

كان شغال تمام بس لما جينا نحاوله الى c# خنق علينا كده

Imports System.Runtime.InteropServices

Public Class Form1

Inherits System.Windows.Forms.Form

<DllImport("SCARD32.DLL", EntryPoint:="SCardComand", SetLastError:=True, CallingConvention:=CallingConvention.Winapi, CharSet:=CharSet.Ansi, ExactSpelling:=True)> Public Shared Function SCardComand(ByRef handle As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef cmd As String, ByRef cmdLen As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef dataIn As String, ByRef dataInLen As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef dataOut As String, ByRef dataOutLen As Integer) As Integer

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'Try

' Dim c As New Class1

' Dim nil As String

' Dim cmd As String = "Card,MemRead,32,128"

' Dim x As Integer

' Dim d As String

' Dim l As Integer

' c.readdata()

' MsgBox(c.readdata())

'Catch ex As Exception

' MsgBox(ex)

'End Try

Dim L As Integer

Dim D As String = " "

Dim nil As String

' D = String(200, 0)

L = SCardComand(0, "Card,Memread,1184,1215", 0, nil, 0, D, 200)

MessageBox.Show(D)

End Sub

انا بفكر اعير وارجع اجربه على 2003 يمكن يضبطولا انت رايك ايه صحيح هى الshared function اللى موجودة فى الmethod ديه تقابل ايه فى c#انا عملتها static صح ولا غلط

مشكور

#8

يا اخى AccessViolation Exception

اتى من المحاوله على كتابه بيانات على smart card لان البيانات محميه زى بالظبط الاسطوانات المحميه.

ثانيا اذا انت حاولت قبل كده وطلع معاك صحيح على جهازك بس مش جهاز غيرك اقصد يعنى ان الكود اشتغل كويس على جهازك ومش جهاز غيرك

يبقى دى احتمال تكون مشكله Access code Security Restriction شوف النمسبيس دى System.Security.Permissions

بس لا تقلق دى مش مشكله method محتاجها فى ملف تانى Com تعرف ليه لان لو لو فى another method فى ملف تانى محتاجها علشان يشتغل الملف كان طلعلك This exception --- InvalidComStateException

وشكرا يا اخى

هذا الموضوع مغلق.

مواضيع مشابهة