问题描述
部分代码如下:publicstaticdoubleSpeedUp=1.0;publicstaticintStoredRealTime=0;publicstaticintStoredFakeTime=0;publicLocalHookQueryPerformanceCounterHook=null;privateboolSetSpeedUp(doubleNewSpeedUp){SpeedUp=NewSpeedUp;if(QueryPerformanceCounterHook==null){QueryPerformanceCounterHook=LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll","QueryPerformanceCounter"),newQueryPerformanceCounterDelegate(QueryPerformanceCounterEx),this);QueryPerformanceCounterHook.ThreadACL.SetExclusiveACL(newInt32[0]);}}staticboolQueryPerformanceCounterEx(outlongFakeTime){boolresult;longRealTime=0;intTickCount=timeGetTime();result=QueryPerformanceCounter(outRealTime);if(StoredRealTime==0)//Initialize{StoredRealTime=RealTime;StoredFakeTime=TickCount;}FakeTime=StoredFakeTime+(long)((RealTime-StoredRealTime)*SpeedUp);StoredRealTime=RealTime;StoredFakeTime=FakeTime;returnresult;}[DllImport("Winmm.dll")]staticexterninttimeGetTime();[UnmanagedFunctionPointer(CallingConvention.StdCall,CharSet=CharSet.Auto,SetLastError=true)]delegateboolQueryPerformanceCounterDelegate(outlonglpPerformanceCount);[DllImport("kernel32.dll")]staticexternboolQueryPerformanceCounter(outlonglpPerformanceCount);
解决方案
本帖最后由 Kasimodo2009 于 2015-02-16 11:41:00 编辑
解决方案二:
没人知道吗?第一次来CSDN发帖,不会让我失望吧……
解决方案三:
问题已解决,我自己说说吧!问题出在timeGetTime和QueryPerformanceCounter两个API函数有冲突,具体为什么我也不太清楚,但是注释掉第20行代码,初始化的StoredFakeTime用RealTime赋值就好了,希望有高手给出具体原因!
解决方案四:
分给我把