1

I'm going to write a simple algorithm provider under CNG (Cryptography Next Generation), exactly an user-mode Hash Provider.
According to the instruction in CNG Development Kit Help "A hash provider must implement the GetHashInterface function and export it by name".
To implement an algorithm provider, I need to include the "bcrypt.h" file from the CNG Development Kit. This file also define the interface for GetHashInterface function but WITHOUT an export directive, exactly:

__checkReturn
NTSTATUS
WINAPI
GetHashInterface(
    __in    LPCWSTR pszProviderName,
    __in    LPCWSTR pszAlgId,
    __out   BCRYPT_HASH_FUNCTION_TABLE **ppFunctionTable,
    __in    ULONG   dwFlags);

If I redefine the function in my header file as an exportable function, for example

#ifndef __CngHashProvider
#define __CngHashProvider
///////////////////////////////////////////////////////////////
#ifndef EXPORT
#define EXPORT extern "C" __declspec(dllexport)
#endif

EXPORT NTSTATUS WINAPI GetHashInterface(
    __in   LPCWSTR pszProviderName,
    __in   LPCWSTR pszAlgId,
    __out  BCRYPT_HASH_FUNCTION_TABLE **ppFunctionTable,
    __in   ULONG dwFlags
);

////////////////////////////////////////////////////////////////
#endif __CngHashProvider

I should get an error message:

Error C2375 'GetHashInterface': redefinition; different linkage

If I remove the EXPORT directive (or remove the whole of interface predefinition for the function), the error message should disappear, but the function can not be exported from my DLL.
So please help me, telling me the way to solve the problem to export the needed GetHashInterface function.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vova
  • 53
  • 7

2 Answers2

1

At the moment I "found" a way to solve the problem.
I coppied the file bcrypt.h from the CNG Development Kit to my project folder and then removed the definition of the GetHashInterface function. My project should include the modified header file, but not the original one.
I don't know is it a right way, but it works for me.

Vova
  • 53
  • 7
0

You can use .def file without the need to edit bcrypt.h. In Visual Studio: Add->New item->Code->Module-definition file.

Just add to this file:

LIBRARY "yourlibraryname"

EXPORTS

  GetHashInterface = GetHashInterface
plstryagain
  • 686
  • 5
  • 9