My first attempt was to make it a plain C Dll, but that was too difficult. And Chris Venter the author of the library also included a C++ wrapper that makes life a lot easier. So with a second approach I modified the command line tool into a Dll that exports two functions: base64_encode() and base64_decode(). Each one uses two parameters: the input filename and the output filename. I tested it with the following Basic code:
Code: Select all
Declare Function EncodeBase64 Lib "base64.dll" Alias "base64_encode" ( inFile, outFile ) As Integer
Declare Function DecodeBase64 Lib "base64.dll" Alias "base64_decode" ( inFile, outFile ) As Integer
Sub TestEncoder
Dim sInputFile As String, sOutputFile As String
Dim nRet As Integer
sInputFile = "C:\home\rolf\staticMap.png"
sOutputFile = "C:\home\rolf\staticMap.asc"
nRet = EncodeBase64(sInputFile,sOutputFile)
MsgBox nRet
End Sub
The Dll is compiled with MinGW, so no special dependencies, but it is rather large (450kByte). I guess that's a tribute to the C++ classes that are used internally. If the input file cannot be found it a MessageBox will popup informing about this. But that's the only test that I have done apart from the pure encoding test. Better do some checks for correct padding and things like that.
And it is too large to upload it as an attachment. The zip archive is 135 KB, with bzip2 I get to 131KB, but that's still above 128 kByte. Sigh. But 7zip did the job to compress the file below 128k.