/* 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>

typedef BSTR __stdcall (*VBFUNCPTR)(char *data);

char* bstr2char(BSTR s)
{
   int len,i;
   char *res;
   len = SysStringLen(s);
   res = (char*)malloc(len+1);
   for(i=0;i<len;i++)
   {
      res[i]=(char)s[i];
   }
   res[i] = 0;
   return res;
}

int main()
{
   HINSTANCE md5;
   VBFUNCPTR md5hash;
   BSTR res1;
   char *res2;
   md5 = LoadLibrary("md5.dll");
   md5hash = (VBFUNCPTR)GetProcAddress(md5,"_MD5Hash@4");
   res1 = md5hash("Dette er en lille test");
   res2 = bstr2char(res1);
   printf("%s\n",res2);
   return 0;
}
