Corrup7ioN
asked on
QueryPerformanceFreqency - Memory access error
Hi,
I've been clinging on to VB6 for way too long and decided to move on to VB.NET 2008. I know practically nothing about .NET, but I do know that it has lots of new fangled memory protecty goodness. Unfortunately this seems to be preventing me from using QueryPerformanceFrequency and I have no idea how to get around it short of reading lots of 'Intro to .NET' articles (which I don't have time for at the minute).
I get the following error when calling QueryPerformanceFrequency:
System.AccessViolationExce ption was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I've created an empty project and put in the basic code to execute QueryPerformanceFreqency on a form; could someone please fix the code and briefly explain what had to be done (and why) to get it working.
Many Thanks
I've been clinging on to VB6 for way too long and decided to move on to VB.NET 2008. I know practically nothing about .NET, but I do know that it has lots of new fangled memory protecty goodness. Unfortunately this seems to be preventing me from using QueryPerformanceFrequency and I have no idea how to get around it short of reading lots of 'Intro to .NET' articles (which I don't have time for at the minute).
I get the following error when calling QueryPerformanceFrequency:
System.AccessViolationExce
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I've created an empty project and put in the basic code to execute QueryPerformanceFreqency on a form; could someone please fix the code and briefly explain what had to be done (and why) to get it working.
Many Thanks
Public Class Form1
Public Declare Function QueryPerformanceFrequency Lib "kernel32.dll" Alias "QueryPerformanceFrequency" (ByVal lpFrequency As Int64) As Long
Public Declare Function QueryPerformanceCounter Lib "kernel32.dll" Alias "QueryPerformanceCounter" (ByVal lpPerformanceCount As Int64) As Long
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim frequency As Int64
QueryPerformanceFrequency(frequency)
End Sub
End Class
OK the problem was the returned type. Those are also working and I think the 2nd is best suited:
Public Declare Auto Function QueryPerformanceFrequency _
Lib "kernel32.dll" (ByRef counter As Int64) As Integer
Public Declare Auto Function QueryPerformanceFrequency _
Lib "kernel32.dll" (ByRef counter As Int64) As Boolean
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good spot. I copied the declarations from a colleagues old VB6 program which didn't specify ByRef/Val. It turns out that VB.NET 2008 automatically inserts ByVal if nothing is specified.
ASKER
D'oh
Thanks :P
Thanks :P
Probably your variable are too big so your app is hitting a location that is not available.
I've tried with what I suggest, it works.
Open in new window