Skip to content

Developer Guidelines

Graham Sutherland edited this page Jul 19, 2018 · 1 revision

General

Some general dev guidelines:

  • Run a full set of checks on your machine before making changes to code, then compare to another full set of checks afterwards. This helps identify regressions.
  • Add new includes and lib pragmas to stdafx.h rather than individual files. This saves duplication.
  • Checks should not use printf where possible.

Calling external APIs

In many cases you'll want to call an external API, and in some cases you may want to use LoadLibrary and GetProcAddress to do dynamic loading of APIs that might not always exist due to different OS versions.

Al-Khaser has a single unified approach to doing external API calls to help minimise code duplication and also provide automatic runtime reporting of APIs that appear to be missing when they shouldn't be (e.g. due to hooks on GetProcAddress).

The key files are:

  • Shared\APIs.cpp - Contains API definitions (identifier, library, export name, min OS version)
  • Shared\ApiTypeDefs.h - Contains all function pointer typedefs.
  • Shared\APIs.h - Contains the API_IDENTIFIER enum. Each entry in this enum uniquely identifies an API.

To add a new API, take thew following steps:

  1. First check if the API has already been imported in Shared\APIs.cpp. If so, you can skip to the end.
  2. Define your function's typedef in ApiTypeDefs.h. Stick to the naming convention of pSomeFunction.
  3. Add a new identifier for the API in the API_IDENTIFIER enum in APIs.h.
  4. Add a definition for the API in the ApiData array in APIs.cpp.
  5. Use the API in your code as follows:
if (API::IsAvailable(API_IDENTIFIER::API_SomeFunction))
{
    auto SomeFunction = static_cast<pSomeFunction>(API::GetAPI(API_IDENTIFIER::API_SomeFunction));
    // do something with SomeFunction()
}

Please try to keep the API lists in alphabetical order.

Clone this wiki locally