Me.Text = "FindMe"
Dim deskWin As IntPtr = FindWindow(Nothing, "FindMe")
Me.Capture = True
Dim hwnd As IntPtr = GetCapture()
Me.Capture = False
6.9. 如何使用性能计数器功能?
使用QueryPerformanceFrequency函数和QueryPerformanceCounter函数可以建立精确的计时程序。 这些功能是和设备提供商相关的,如果他们不能执行,那么只能和GetTickCount功能得到一样的结果。如果能执行这些函数,就能保证计时器最准确的运行,比GetTickCounter或Environment.TickCount准确得多。TickCount其实是调用GetTickCounter的。
如果性能计数器是GetTickCount的一个实例,QueryPerformanceFrequency将把1000作为计时频率。如果这些函数不能执行,将得到返回值为0。以下代码演示了如何使用这些函数。//C#
[DllImport("CoreDll.dll")]
public static extern int QueryPerformanceFrequency(ref Int64 lpFrequency);
[DllImport("CoreDll.dll")]
public static extern int QueryPerformanceCounter(ref Int64 lpPerformanceCount);
private void TestTimer()
{
System.Int64 freq = 0;
if (QueryPerformanceFrequency(ref freq) != 0)
{
System.Int64 count1 = 0;
System.Int64 count2 = 0;
if (QueryPerformanceCounter(ref count1) != 0)
{
System.Threading.Thread.Sleep(1200);
QueryPerformanceCounter(ref count2);
System.Int64 time_ms = (count2 - count1) * 1000 / freq;
}
}
}
'VB
<DllImport("CoreDll.dll")> _
Public Shared Function QueryPerformanceFrequency(ByRef lpFrequency As Int64) As Integer
End Function
<DllImport("coredll.dll")> _
Public Shared Function QueryPerformanceCounter(ByRef lpPerformanceCount As Int64) As Integer
End Function
Private Sub TestTimer()
Dim freq As System.Int64 = 0
If QueryPerformanceFrequency(freq) <> 0 Then
Dim count1 As System.Int64 = 0
Dim count2 As System.Int64 = 0
If QueryPerformanceCounter(count1) <> 0 Then
System.Threading.Thread.Sleep(1200)
QueryPerformanceCounter(count2)
Dim time_ms As System.Int64 = (count2 - count1) * 1000 / freq
End If
End If
End Sub 'TestTimer
6.10. 调用本地代码时,数据类型有什么限制?What are the limitations on marshalling types via P/Invoke?
返回值
只能是长度小于等于32位的类型
非浮点型not floating point
参数
Only support marshaling blittable types
blittable types -> same representation in memory in both managed and native
non-blittable -> memory transformation required
Since only blittable types, all objects are pinned and never copied
Exception: passing String ByVal in VB.NET
Implies that you can't marshal nested objects since this requires a memory transformation (non-blittable)
只能是长度小于等于32位的类型
值通过堆栈传递
例外:float32
参考(References)
Pass blittable reference types
把参考传递到值类型变量
这就是如何传递float32类型的值
可以传递值类型的数组
在本地代码中,您可以使用指针指向第一个对象,然后一个接一个地访问其他对象
String是特殊的,传递char数组 -> 不变的
StringBuilder是特殊的,传递char数组 -> 易变的 (需要单独传递长度)
注意:C# bool是8个比特位的,并且不等于Win32的BOOL
队列:编译器默认的队列 (4字节)
Marshal.GetLastWin32Error 支持 GetLastError() 语义