Click here to Skip to main content
15,905,508 members
Home / Discussions / C#
   

C#

 
GeneralRe: Logic of prime numbers Pin
Richard MacCutchan3-Jan-15 21:05
mveRichard MacCutchan3-Jan-15 21:05 
GeneralRe: Logic of prime numbers Pin
BillWoodruff3-Jan-15 21:21
professionalBillWoodruff3-Jan-15 21:21 
GeneralRe: Logic of prime numbers Pin
Richard MacCutchan3-Jan-15 22:02
mveRichard MacCutchan3-Jan-15 22:02 
AnswerRe: Logic of prime numbers Pin
SledgeHammer012-Jan-15 14:16
SledgeHammer012-Jan-15 14:16 
GeneralRe: Logic of prime numbers Pin
Member 113371082-Jan-15 14:19
Member 113371082-Jan-15 14:19 
GeneralRe: Logic of prime numbers Pin
SledgeHammer012-Jan-15 14:32
SledgeHammer012-Jan-15 14:32 
GeneralRe: Logic of prime numbers Pin
Member 113371082-Jan-15 15:06
Member 113371082-Jan-15 15:06 
GeneralRe: Logic of prime numbers Pin
SledgeHammer012-Jan-15 15:24
SledgeHammer012-Jan-15 15:24 
GeneralRe: Logic of prime numbers Pin
BillWoodruff3-Jan-15 11:59
professionalBillWoodruff3-Jan-15 11:59 
Questionhow can get number in a string in c# :(((((( Pin
mhd.sbt2-Jan-15 6:13
mhd.sbt2-Jan-15 6:13 
AnswerRe: how can get number in a string in c# :(((((( Pin
Pete O'Hanlon2-Jan-15 6:28
mvePete O'Hanlon2-Jan-15 6:28 
AnswerRe: how can get number in a string in c# :(((((( Pin
BillWoodruff2-Jan-15 7:43
professionalBillWoodruff2-Jan-15 7:43 
QuestionCan I write my own XBox 360 program? Pin
trantrum2-Jan-15 4:41
professionaltrantrum2-Jan-15 4:41 
AnswerRe: Can I write my own XBox 360 program? Pin
Richard MacCutchan2-Jan-15 4:53
mveRichard MacCutchan2-Jan-15 4:53 
AnswerRe: Can I write my own XBox 360 program? Pin
OriginalGriff2-Jan-15 5:00
mveOriginalGriff2-Jan-15 5:00 
GeneralRe: Can I write my own XBox 360 program? Pin
trantrum2-Jan-15 5:07
professionaltrantrum2-Jan-15 5:07 
GeneralRe: Can I write my own XBox 360 program? Pin
OriginalGriff2-Jan-15 5:13
mveOriginalGriff2-Jan-15 5:13 
GeneralRe: Can I write my own XBox 360 program? Pin
trantrum2-Jan-15 5:21
professionaltrantrum2-Jan-15 5:21 
GeneralRe: Can I write my own XBox 360 program? Pin
OriginalGriff2-Jan-15 5:25
mveOriginalGriff2-Jan-15 5:25 
AnswerRe: Can I write my own XBox 360 program? Pin
BillWoodruff2-Jan-15 6:56
professionalBillWoodruff2-Jan-15 6:56 
GeneralRe: Can I write my own XBox 360 program? Pin
trantrum2-Jan-15 9:20
professionaltrantrum2-Jan-15 9:20 
QuestionUnhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 4:28
turbosupramk32-Jan-15 4:28 
I'm getting this error message on my laptop (win7 64bit/visual studio 2012 express), but not my desktop (win7 64bit/visual studio 2012 pro), code is unchanged.

This is happening when my code runs through
Quote:
var versionPtr = GetPropellerVersion();

Which is a dll import call via the code below, so it has something to do with the unmanaged code, but I'm a bit confused as to why? I believe the dll is 32 bit, so I've set the project to force x86, but I'm unsure as to what else could cause this? The project is set to 'copy always' the dll as well. I've also tried it in debug and release mode, same conflicting results.

Does anyone have any ideas? Thanks for reading.



Quote:
[DllImport("Propellent.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr GetPropellerVersion();



Quote:
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at program.GetPropellerVersion()
at program.btnDetectPort_Click(Object sender, EventArgs e) in program\Form1.cs:line 1750
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.NatiThe program '[48096] program.exe: Managed (v2.0.50727)' has exited with code -1073741819 (0xc0000005) 'Access violation'.
veWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at program.Program.Main() in program\Program.cs:line 19



C#
private void btnDetectPort_Click(object sender, EventArgs e)
        {
            cbxSerialPort.Items.Clear();
            string[] ports = SerialPort.GetPortNames();
            foreach (string port in ports)
            {
                cbxSerialPort.Items.Add(port);
                cbxSerialPort.SelectedIndex = 0;
                serialPort1.PortName = port;
                serialPort1.BaudRate = 115200;
                serialPort1.Encoding = Encoding.ASCII;

                try
                {
                    serialPort1.Open();
                    this.Invoke(new EventHandler(delegate
                    {
                        serialPort1.Close();
                    }));
                }
                catch (Exception)
                {
                   // do nothing
                }

            }

            var versionPtr = GetPropellerVersion();                     // error here
            string version = Marshal.PtrToStringAnsi(versionPtr);       

            int delimiter = version.IndexOf(':');
            if (delimiter > -1)
            {
                string comPort = version.Remove(delimiter - 1);
                string firmWare = version.Remove(0, delimiter + 2);
                tbxPropPortFound.Text = comPort;
                                int comPortIndex = cbxSerialPort.FindString(comPort);
                cbxSerialPort.SelectedIndex = comPortIndex;
            }
        }

AnswerRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
Dave Kreskowiak2-Jan-15 4:35
mveDave Kreskowiak2-Jan-15 4:35 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 5:07
turbosupramk32-Jan-15 5:07 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
Dave Kreskowiak2-Jan-15 8:39
mveDave Kreskowiak2-Jan-15 8:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.