Call QueryPerformanceCounter from a PowerLanguage Script

Questions about MultiCharts and user contributed studies.
User avatar
PatrickSocal
Posts: 58
Joined: 27 Apr 2013
Location: San Diego, CA
Has thanked: 23 times
Been thanked: 30 times

Call QueryPerformanceCounter from a PowerLanguage Script

Postby PatrickSocal » 17 Oct 2014

Hi,

In an earlier post (viewtopic.php?f=1&t=46208#p103344), MultiCharts support gave us the attached code to measure elapsed time with approximately 15 ms resolution. It uses the "GetTickCount" Windows call.

I would like to use the QueryPerformanceCounter Windows call instead. It has finer resolution in most situations. I've tried something like this:

Code: Select all

external: "kernel32.dll", bool, "QueryPerformanceCounter", int;
But I don't know how to specify that the input argument should be a reference to an int which will receive the return value. Can someone help?

More info on these timer-related Windows calls:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
https://stackoverflow.com/questions/155 ... ncecounter
https://stackoverflow.com/questions/229 ... using-hpet

Thanks in advance...
Attachments
calculate_time_ms.pla
(2.96 KiB) Downloaded 546 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Call QueryPerformanceCounter from a PowerLanguage Script

Postby Henry MultiСharts » 21 Oct 2014

Hello PatrickSocal,

You need to create a wrapper over QueryPerformanceCounter in order to use it.
Attached is the source code, 2 dlls (32/64 bit) a test study.

Test indicator:

Code: Select all

DEFINEDLLFUNC: "test.dll", int, "QueryPerformanceCounter", int, int;

var: HighPart(0), LowPart(0);
QueryPerformanceCounter(HighPart, LowPart);
Function test in the dll:

Code: Select all

BOOL __stdcall QueryPerformanceCounter(int HPart, int LPart)
{
LARGE_INTEGER PerformanceCount = {0};
BOOL bRes = ::QueryPerformanceCounter(&PerformanceCount);
HPart = PerformanceCount.HighPart;
LPart = PerformanceCount.LowPart;
return bRes;
}
Attachments
QueryPerformanceCounter.zip
(77.27 KiB) Downloaded 231 times


Return to “MultiCharts”