RiceGnat Posted January 11, 2019 Share Posted January 11, 2019 I'm trying to read the shared memory and I'm getting an AccessViolationException when trying to open the file. I've tried running both AIDA64 and the development environment as administrator in all combinations. I'm currently using the TRIAL version on v5.99.4900. Is there a restriction for this function on the trial version? I'm looking to get the program specifically for this capability so I'd like to know whether or not it works before purchasing. Quote Link to comment Share on other sites More sharing options...
Fiery Posted January 14, 2019 Share Posted January 14, 2019 On 1/11/2019 at 9:49 PM, RiceGnat said: I'm trying to read the shared memory and I'm getting an AccessViolationException when trying to open the file. I've tried running both AIDA64 and the development environment as administrator in all combinations. I'm currently using the TRIAL version on v5.99.4900. Is there a restriction for this function on the trial version? I'm looking to get the program specifically for this capability so I'd like to know whether or not it works before purchasing. No restrictions on the shared memory access in the trial version. Have you tried to perform the shared memory reading operation by using elevation? Quote Link to comment Share on other sites More sharing options...
RiceGnat Posted January 14, 2019 Author Share Posted January 14, 2019 Yeah, I've tried it with Visual Studio running as administrator, as well as running the compiled executable as administrator. No luck. Quote Link to comment Share on other sites More sharing options...
Fiery Posted January 17, 2019 Share Posted January 17, 2019 On 1/14/2019 at 10:37 PM, RiceGnat said: Yeah, I've tried it with Visual Studio running as administrator, as well as running the compiled executable as administrator. No luck. Please show me the code you're using to open the shared memory incl. the mapping and unmapping sections. If you prefer to keep your code from the public, you can send it to me in private message as well. Quote Link to comment Share on other sites More sharing options...
RiceGnat Posted January 17, 2019 Author Share Posted January 17, 2019 Upon revisiting the issue it seems that the issue was due to the buffer size I was using. The "AccessViolationException" is probably from trying to read past the end of the file. I guess that changes the question to: How do I get the length of the string? Alternatively, what's the max buffer size? The help doc said 10KB, but that seems to be what's causing the exception. A smaller value (3K) works and I can read the XML string, but how do I know for sure I've gotten the entire file? internal const string SHARED_MEM_NAME = "AIDA64_SensorValues"; internal const int FILE_MAP_READ = 0x0004; internal const int BUFFER_SIZE = 3000; public static SensorData GetData() { // Read sensor values from shared memory StringBuilder sharedMemFile = new StringBuilder(SHARED_MEM_NAME); IntPtr handle = Kernel32.OpenFileMapping(FILE_MAP_READ, false, sharedMemFile); IntPtr mem = Kernel32.MapViewOfFile(handle, FILE_MAP_READ, 0, 0, 0); if (mem == IntPtr.Zero) { throw new Exception("Unable to read shared memory."); } string xml = Marshal.PtrToStringAnsi(mem, BUFFER_SIZE); Console.WriteLine(xml); Kernel32.UnmapViewOfFile(handle); Kernel32.CloseHandle(handle); return null; } Quote Link to comment Share on other sites More sharing options...
Fiery Posted January 21, 2019 Share Posted January 21, 2019 On 1/17/2019 at 11:25 PM, RiceGnat said: Upon revisiting the issue it seems that the issue was due to the buffer size I was using. The "AccessViolationException" is probably from trying to read past the end of the file. I guess that changes the question to: How do I get the length of the string? Alternatively, what's the max buffer size? The help doc said 10KB, but that seems to be what's causing the exception. A smaller value (3K) works and I can read the XML string, but how do I know for sure I've gotten the entire file? internal const string SHARED_MEM_NAME = "AIDA64_SensorValues"; internal const int FILE_MAP_READ = 0x0004; internal const int BUFFER_SIZE = 3000; public static SensorData GetData() { // Read sensor values from shared memory StringBuilder sharedMemFile = new StringBuilder(SHARED_MEM_NAME); IntPtr handle = Kernel32.OpenFileMapping(FILE_MAP_READ, false, sharedMemFile); IntPtr mem = Kernel32.MapViewOfFile(handle, FILE_MAP_READ, 0, 0, 0); if (mem == IntPtr.Zero) { throw new Exception("Unable to read shared memory."); } string xml = Marshal.PtrToStringAnsi(mem, BUFFER_SIZE); Console.WriteLine(xml); Kernel32.UnmapViewOfFile(handle); Kernel32.CloseHandle(handle); return null; } AIDA64 doesn't support providing the necessary buffer size, so you gotta do some test runs to find out what buffer size you need to use to comfortably fit all items you've selected. Quote Link to comment Share on other sites More sharing options...
RiceGnat Posted January 29, 2019 Author Share Posted January 29, 2019 On 1/21/2019 at 6:12 AM, Fiery said: AIDA64 doesn't support providing the necessary buffer size, so you gotta do some test runs to find out what buffer size you need to use to comfortably fit all items you've selected. Ah, that's a mighty shame. Well, thank you for helping out anyway! Will figure something out to work with that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.