Jump to content

GetTickCount()


layer
 Share

Recommended Posts

Hey guys, just thre together a quick little Dll that gets the mili seconds your system has been running since startup... It's pretty neat. Source of the Dll is in the zip, the Dll is in the zip, and an example is in the zip :(

:(

FootbaG
Link to comment
Share on other sites

No no no, lol, I was at home when I coded the Dll, but when I was at home, I was realllly bored, and I didn't have anything better to do and I just wanted to burn some time :( But when I wrote that post, I was at my friends house checking the status of my posts :( My friends are hella fun, trust me :

FootbaG
Link to comment
Share on other sites

Its actually a poor example. 95% of the code is not necessary; its virtually all wizard-generated. The exported class is never used, so its a waste. The header isn't necessary unless you intend to link statically against the DLL; AutoIt can't, so that's a waste as well.

The code should look more like:

#include <windows.h>

BOOL APIENTRY DllMain(HINSTANCE, DWORD, LPVOID)
{
    return TRUE;
}

extern "C" DWORD WINAPI GetSysTicks()
{
    return GetTickCount();
}

Thats all that's really needed.

Writing a paper thin wrapper around an API function that can be called directly isn't a very good example. A small function that does something useful would be a good example. But all this example showed was that layer can spend 30 seconds creating a new DLL project and adding a thin wrapper around a function.

And, unless I'm mistaken, any function that AutoIt calls needs to be declared as using the __stdcall calling convention. I think the default is __cdecl, so running under a debugger, I expect to see some esp (stack pointer) errors*. Although this won't introduce a crash, it may leak some resources.

In layer's defense, I don't expect him to know about the calling convention as its not documented anywhere (Not documented in AutoIt that it needs to be __stdcall). However, still, his example does more wrong than it does right, so it is not a good source for reference.

* There may be no errors since no parameters are pushed onto the stack.

Link to comment
Share on other sites

Yea, I didn't intend for it to be an example... And lol, yea, it's all wizard generated except for this:

extern "C"__declspec(dllexport) int GetSysTicks(){
       return GetTickCount();
}

Actually, not really wizard generated, more of a default template :(

FootbaG
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...