Sample code to call Runtime modules in Delphi
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This project is written in Delphi 6 but will work in more recent versions
(they will upgrade the Project to the latest version. For Delphi XE or earlier
you will need to delete the reference to System.UITypes).

If you want to create multi-platform or multi-device applications please use
the FireMonkey projects instead.

The source files in the project are:

File name       Description
apitest.pas     main source code file for Delphi
dris.pas        contains DRIS structure definition and other definitions.
apitest.dfm
ObjTest.dpr     project file

The idea is to include the dris.pas file in your project and use/modify which ever
functions from apitest.pas you feel are appropriate.

This sample can also compile to 64-bit code (if your version of Delphi supports 64-bit
code i.e. Delphi XE2 and higher). Just Add the 64-bit Platform to the project.

In order for the projects to compile without modification we have also installed in
this folder the relevant object modules for Delphi:

dpwin32_omf.obj        for 32-bit builds
dpwin64_delphi.obj     for 64-bit builds

The sample code will detect whether you are building in 32-bit or 64-bit and compile
the appropriate Windows module.

The sample code contains 11 functions. You will not need to use all these
functions in your code. Just use which ever functions are most appropriate
and customise in your own way. The sample code is just a guide. You should
implement the protection in a stronger way using the techniques described in
the "Increasing your Protection" chapter of the manual.

Code marked with !!!! are places where you should customise the sample code so
that it will work properly:

* Change the MY_SDSN value to the value of your SDSN
* Change the MY_PRODCODE value to the Product Code in the dongle
* Change the MyAlgorithm code (if you call a user algorithm)
* Change the CryptDRIS code (if you encrypt the DRIS)
* Change the CryptApiData (if you encrypt Data you send to our API)
* Change the MyRWAlgorithm code (if encrypt Data you send to our API using the R/W algorithm)

You will also probably want to replace our error messages with your own. However, you should
still display or log any error codes returned by the protection check otherwise you will not
be able to identify the cause of the error. (You can look up error codes in our knowledge
base: microcosm.com/kb).

The project currently links with our static protection modules. If you want to link to
our dynamic protection modules instead (dpwin32.dll or dpwin64.dll) then you need
to modify dris.pas as follows:

1) Modify the declarations of DDProtCheck and DDGetNetUserList so that they refer
   to the appropriate runtime DLL.

2) Delete the code that links the object module.

We have made these changes and put them in a file called dris_for_dll.pas.
Use this in your project instead of dris.pas.

It is also recommended that you rename dpwin32.dll to a name of your choice. In
this case you will need to modify the dll name in the dris.pas file.

Note - if you link the static module dpwin32_omf.obj then you should protect your program.
If you are linking to dpwin32.dll then you need to protect dpwin32.dll and *not* your program.
Because your program is linked to the DLL it is protected. The protected DLL will need to be
in the same folder as your compiled program for it to run correctly.

Debug Modules
~~~~~~~~~~~~~~
Note - once your program (or dpwin32.dll) is protected you will not be able to debug
your program - after our API has been called. Our strong anti-debug code will cause
the debugger to throw an exception. You will also not be able to run your program from
the development platform either as Delphi still has the Debugger running. You should run
it instead from My Computer or from the command line. If you do want to debug your code
then you can use our debug module: dpwin32_omf_debug.obj (or dpwin32debug.dll), but these
should not be used for release.

You could setup your project so that your code links the debug module during your debug build
and the standard module when you produce your release code.

Note: the debug module has the following restrictions:

1) It will not correctly start a network user (network dongles only). However, other than that
   the protection check will function correctly and return success.
2) You will not be able to encrypt the DRIS. (If you do encrypt the DRIS in your release build
   then you should make sure that CryptDRIS does not get called in your debug build).
3) The protection check will take slightly longer than normal.
4) The DDGetNetUserList function will return error 428 (not implemented).
5) A temporary subprocess is created which may be (falsely) detected as malicious by anti-virus
   programs.
