Search code examples
cwindowswinapitimerdriver

How to convert an Integer to LARGE_INTEGER


How do i convert an integer to LARGE_INTEGER?

For example, when I want to trigger a timer immediately:

LARGE_INTEGER zero;  
zero.QuadPart = 0;  
KeSetTimer(pTimer, zero, pDpc);

Is there any way to convert 0 to LARGE_INTEGER? So I could do this instead:

KeSetTimer(pTimer, (SomeType)0, pDpc);

I have tried:

KeSetTimer(pTimer, (LARGE_INTEGER )0, pDpc);

But it doesn't work. I have Googled, but couldn't find any help.


Solution

  • LARGE_INTEGER is a struct. It is not possible to cast a value to a struct type.

    You need to create an instance of the struct and set its fields as needed.

    For example:

    LARGE_INTEGER intToLargeInt(int i) {
        LARGE_INTEGER li;
        li.QuadPart = i;
        return li;
    }
    

    You can then use it like this:

    KeSetTimer(pTimer, intToLargeInt(0), pDpc);