// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <windows.h>
#include <oleauto.h>
#include <stdio.h>
#include <string.h>

#include "MD5.h"
#include "md5c.h"

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH:
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
            break;
    }
    return TRUE;
}
MD5_API BSTR __stdcall MD5Hash(char *data)
{
   int len = strlen(data);
   MD5_CTX ctx;
   MD5Init(&ctx);
   MD5Update(&ctx, (unsigned char *)data, len);
   char hash[16];
   MD5Final((unsigned char *)hash, &ctx);
   char hexhash[33];
   for(int j=0; j<16; j++) sprintf(hexhash+2*j,"%02X",0xFF & hash[j]);
   BSTR res = SysAllocStringByteLen(hexhash, 32);
   return res;
}
