CryptoSys Home > PKI > Programming with CryptoSys PKI

Programming with CryptoSys PKI


Classic Visual Basic (VB6) and VBA

To use CryptoSys PKI with classic Visual Basic (VB6) or VBA, copy the declarations in the file basCrPKI.bas into a module in your project. VBA programmers (MS Office, Access, Excel, etc) should delete the first line with Attribute VB_Name in it.

This simple example will display the version number and licence type:

Dim nRet As Long    
nRet = PKI_Version(0, 0)
Debug.Print "PKI_Version = " & nRet    
nRet = PKI_LicenceType(0)
Debug.Print "PKI_LicenceType is " & Chr(nRet)

C/C++

Compiling With C/C++

Use #include "diCrPKI.h" in your source code and link with the library diCrPKI.lib. Here is some minimal code:-

/* myver.c */
#include <stdio.h>
#include "diCrPKI.h"
int main()
{
    long version;
    version = PKI_Version(NULL, NULL);
    printf("Version=%ld\n", version);
    return 0;
}

To create myver.exe with MSVC++:

cl myver.c diCrPKI.lib

With Borland C++ (but see Using With Borland C++ below to generate a new lib file):

bcc32 myver.c diCrPKI.lib

With some compilers you can avoid having to link explicitly to the LIB file by inserting this line in the source code:

#pragma comment(lib, ".\\diCrPKI.lib")

The #pragma statement instructs the linker to link to the library file located - in this case - in the current working directory. Edit the location to suit your own situation. This #pragma method works for MSVC++ and Borland C++5.

Using with MSVC++

To compile our example code with MSVC, you can create a `command-line' project and add the two files PKI_Example.c and diCrPKI.h to it.

Alternatively, use this command line instruction:

C:\>CL PKI_Examples.c diCrPKI.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 11.00.7022 for 80x86
Copyright (C) Microsoft Corp 1984-1997. All rights reserved.

PKI_Examples.c
Microsoft (R) 32-Bit Incremental Linker Version 5.10.7303
Copyright (C) Microsoft Corp 1992-1997. All rights reserved.

/out:PKI_Examples.exe
PKI_Examples.obj
diCrPKI.lib

Using With Borland C++

The lib file distributed with the program is made using Microsoft VC++. This will not work with Borland (which uses a different library format) and you need to generate a new .lib file directly from the DLL using the IMPLIB utility.

C:\>implib diCrPKI.lib diCrPKI.dll

Borland Implib Version 3.0.22 Copyright (c) 1991, 2000 Inprise Corporation

Note the order of the parameters (.lib then .dll). If you get them the wrong way round it will destroy your DLL file!

To compile our test source code using Borland C++ for Win32, do the following:-

C:\>bcc32 PKI_examples.c
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
pki_examples.c:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

In our PKI_Example.c code, we used certain variables in assert statements as a quick-and-dirty error checking mechanism. The Borland compiler will warn you that they are not used, even though they are. To avoid these warnings, use this command:

bcc32 -w-8004 PKI_examples.c

Using With .NET: C# and VB.NET

Using the CryptoSys PKI with C# and VB.NET is almost identical. To use in a .NET project, set a reference in your project to the Class Library diCrSysPKINet.dll and include the line (for C#)

using CryptoSysPKI;

or (for VB.NET)

Imports CryptoSysPKI

in your source code. Alternatively, with C#, you can include the source code module CryptoSysPKI.cs in your project and do not set a reference.

using CryptoSysPKI;

int n;
n = General.Version();
Console.WriteLine("Version={0}", n);
Imports CryptoSysPKI

Dim n As Integer
n = General.Version()
Console.WriteLine("Version={0}", n)

For more details, see the section in the manual Using with .NET: C# and VB.NET.

Using with other languages

See Writing an interface in another programming language for interfaces to CryptoSys PKI in other languages, including Delphi, Visual FoxPro and Clarion.

Contact

For more information or to comment on this page, please send us a message.

This page last updated 3 January 2019