Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i have this class

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

  • *Experts*
Posted

All external Dll references must be static. In C# the keyword is static, I'm not sure if it's the same in VB.NET (I think it might be Shared?).

 

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

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...