Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why?
-
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.ThreadConte
-
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.ThreadConte
OK, so what is "GetPropellerVersion"? What does the import look like? What does the function do? Got any docs on this thing?
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
OK, so what is "GetPropellerVersion"? What does the import look like? What does the function do? Got any docs on this thing?
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave KreskowiakHi, I had to upload it from my machine, it's a pdf. If you're sketched out about downloading a random pdf, I copied the text below and pasted it in a code block, it's the same thing, just not as pretty as the pdf. http://temp-host.com/download.php?file=fv01pq[^] [code]
Parallax Propellent
The Parallax Propellent software is a Windows-based tool for compiling and downloading to the Parallax Propeller chip. Propellent is available as both a library (Propellent.dll) and as an executable (Propellent.exe).
ï‚·ï€ The Propellent Library (DLL) is for software developers to link into applications enabling immediate support of the Propeller using the same functions as the Parallax-made Propeller Tool development software.
ï‚·ï€ The Propellent Executable (EXE) is a program that includes the Propellent Library within it and provides many of the same functions to anyone wishing for command-line support of the Propeller chip.This document is written for the Propellent Library. For details about the Propellent Executable, see the "Propellent Executable.pdf" document, or run the executable with the '/help' switch. For more information on the
Parallax Propeller chip and tools, please visit http://www.parallax.com/propellerFeatures of the Propellent Library:
ï‚·ï€ Can download Propeller Application images (.binary or .eeprom) to Propeller chips.
ï‚·ï€ Can compile Propeller source (.spin) for downloading, for saving as a binary or eeprom image, for retrieval of source document, or just for syntax checking.
ï‚·ï€ Can run with full, limited, or no visual feedback.
ï‚·ï€ Includes the Propeller Tool's multi-threaded serial port handling and Propeller chip communication functionality.
ï‚·ï€ Includes the Propeller Tool's dialogs for indicating serial port access and download progress as well as the user-customizable serial port search options.
ï‚·ï€ Automatically stores user-modified preferences in the Windows Registry for use in future sessions. This can be disabled if desired.
ï‚·ï€ Allows access to current list of available serial ports.
ï‚·ï€ Allows calling application to view and/or specify preferences such as Library Path, Reset Signal (DTR, RTS, or both) and Serial Search Method (AUTO or specific port).
ï‚·ï€ -
OK, so what is "GetPropellerVersion"? What does the import look like? What does the function do? Got any docs on this thing?
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave KreskowiakIt's returning the numeric values on the left and the code converts it to the text value on the right hand side of the = sign.
112905168 = "COM6 : VERSION 1"
81416960 = "COM6 : VERSION 1"
How do those values equal the text? Are they memory addresses?
-
It's returning the numeric values on the left and the code converts it to the text value on the right hand side of the = sign.
112905168 = "COM6 : VERSION 1"
81416960 = "COM6 : VERSION 1"
How do those values equal the text? Are they memory addresses?
No, it's not a memory address. It tells you in the documentation exactly what that value is.
Quote:
RETURN VALUE : Format is Bits 31 [to] 16 = port id, bits 15 [to] 0 = version
It's single 32-bit value that returns 2 values. The 32-bits is divided into two fields. You've to do a bit of math to get the values separated.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
Hi, I had to upload it from my machine, it's a pdf. If you're sketched out about downloading a random pdf, I copied the text below and pasted it in a code block, it's the same thing, just not as pretty as the pdf. http://temp-host.com/download.php?file=fv01pq[^] [code]
Parallax Propellent
The Parallax Propellent software is a Windows-based tool for compiling and downloading to the Parallax Propeller chip. Propellent is available as both a library (Propellent.dll) and as an executable (Propellent.exe).
ï‚·ï€ The Propellent Library (DLL) is for software developers to link into applications enabling immediate support of the Propeller using the same functions as the Parallax-made Propeller Tool development software.
ï‚·ï€ The Propellent Executable (EXE) is a program that includes the Propellent Library within it and provides many of the same functions to anyone wishing for command-line support of the Propeller chip.This document is written for the Propellent Library. For details about the Propellent Executable, see the "Propellent Executable.pdf" document, or run the executable with the '/help' switch. For more information on the
Parallax Propeller chip and tools, please visit http://www.parallax.com/propellerFeatures of the Propellent Library:
ï‚·ï€ Can download Propeller Application images (.binary or .eeprom) to Propeller chips.
ï‚·ï€ Can compile Propeller source (.spin) for downloading, for saving as a binary or eeprom image, for retrieval of source document, or just for syntax checking.
ï‚·ï€ Can run with full, limited, or no visual feedback.
ï‚·ï€ Includes the Propeller Tool's multi-threaded serial port handling and Propeller chip communication functionality.
ï‚·ï€ Includes the Propeller Tool's dialogs for indicating serial port access and download progress as well as the user-customizable serial port search options.
ï‚·ï€ Automatically stores user-modified preferences in the Windows Registry for use in future sessions. This can be disabled if desired.
ï‚·ï€ Allows access to current list of available serial ports.
ï‚·ï€ Allows calling application to view and/or specify preferences such as Library Path, Reset Signal (DTR, RTS, or both) and Serial Search Method (AUTO or specific port).
ï‚·ï€Does the error occur on the GetPropellerVersion line or the line after it? Using that return value as a pointer is going to be a bad thing 'cause it's not a memory address to a string.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
No, it's not a memory address. It tells you in the documentation exactly what that value is.
Quote:
RETURN VALUE : Format is Bits 31 [to] 16 = port id, bits 15 [to] 0 = version
It's single 32-bit value that returns 2 values. The 32-bits is divided into two fields. You've to do a bit of math to get the values separated.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave KreskowiakIt fails on the var version = call propeller function line, but only on that one machine (so far). I read the documentation with the 2 words in the long, can you explain how they are converting the numeric value to text? I had it print out as binary and I still couldn't figure out how it was being converted?
-
It fails on the var version = call propeller function line, but only on that one machine (so far). I read the documentation with the 2 words in the long, can you explain how they are converting the numeric value to text? I had it print out as binary and I still couldn't figure out how it was being converted?
Where are you getting the text from?? NM. I just found in it in the code you originally posted. If it is an address, which your code seems to indicate it is, then the library is just storing a string and passing the address to you. But, if this really is the case, the documentation doesn't match what the library is doing and you should direct all further queries about this library to the people who wrote it.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
Where are you getting the text from?? NM. I just found in it in the code you originally posted. If it is an address, which your code seems to indicate it is, then the library is just storing a string and passing the address to you. But, if this really is the case, the documentation doesn't match what the library is doing and you should direct all further queries about this library to the people who wrote it.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave KreskowiakOk that confirms my confusion. There is another way to get the same value by using an int instead of a ptr (if I remember correctly), I will check my code and post that as well when I get home to see if heads or tails can be made of that.
-
Where are you getting the text from?? NM. I just found in it in the code you originally posted. If it is an address, which your code seems to indicate it is, then the library is just storing a string and passing the address to you. But, if this really is the case, the documentation doesn't match what the library is doing and you should direct all further queries about this library to the people who wrote it.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave KreskowiakI'm not sure why this would behave differently on different win7 machines ... but calling the InitPropellent function in form1_load fixed this issue? Strange eh?
InitPropellent((long)this.Handle, false, "");
-
I'm not sure why this would behave differently on different win7 machines ... but calling the InitPropellent function in form1_load fixed this issue? Strange eh?
InitPropellent((long)this.Handle, false, "");
No, not strange. You just converted the Handle value to a 64-bit integer. This tells me that your other machine where it works is a 32-bit machine and your Win7 machine is 64-bit.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
No, not strange. You just converted the Handle value to a 64-bit integer. This tells me that your other machine where it works is a 32-bit machine and your Win7 machine is 64-bit.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave KreskowiakBoth machines are actually 64 bit, although I have the project set to compile to 32 bit output since the dll is 32 bit.