problem with dlls

smremde

Member
Joined
Oct 10, 2003
Messages
6
i have this class
Code:
Imports System.Runtime.InteropServices

Public Class Timer

    Private m_Frequency As Long
    Private m_Count As Long

    Public Sub New()
        QueryPerformanceFrequency(m_Frequency)
    End Sub

    Public ReadOnly Property FTime() As Double
        Get
            QueryPerformanceCounter(m_Count)
            Return m_Count / m_Frequency
        End Get
    End Property

    <DllImport("Kernel32.dll")> Private Function QueryPerformanceCounter(ByRef lpPerformanceCount As Long) As Boolean
    End Function
    <DllImport("Kernel32.dll")> Private Function QueryPerformanceFrequency(ByRef lpFrequency As Long) As Boolean
    End Function
End Class

and i get exceptions here QueryPerformanceFrequency(m_Frequency) and here QueryPerformanceCounter(m_Count):

An unhandled exception of type System.InvalidProgramException occurred in xfengine.dll

Additional information: Error: PInvoke item (field,method) must be Static.

The program [1588] XF2.exe has exited with code 0 (0x0).


xfengine.dll is my class library containing the high resolution timer and XF2.exe is the console app using xfengine.dll

any help much appreciated
Stephen
 
All external Dll references must be static. In C# the keyword is static, Im not sure if its the same in VB.NET (I think it might be Shared?).

Also, I dont think the params should be ByRef for those functions. And I think it should return an Int32, not Boolean (though Bool *might* work, I wouldnt count on it).

-Nerseus
 
Back
Top