I'm trying to call a DLL routine which calculates the MD5 message digest on a file. To test the DLL I put two fields and a button on a form. In one field you type a filename. When you press the button, the DLL routine gets called, passes the filename, and also passes a string by reference to get back the digest (16 bytes). PAL copies the digest into the other field so you can look at it.
The problem I'm having is that any filenames longer than 4 characters cause a GPF. Also the digest gets truncated to 6 bytes.
I used Microsoft Virtual C++ .NET Framework SDK to create the DLL - it's compiled as a regular non-MFC DLL.
Also, while we're at it, the PAL help file says referenced DLLs are searched for first in the "current directory". What's the current directory when running the application? Apparently it's neither where the app's forms nor exe file is. For the moment I'm copying the DLL into the windows system directory.
Here's the code:
method pushButton(var eventInfo Event)
var
result_code LongInt
dig,fn String
endVar
fn = filename ;filename is a field on the form
result_code = file_md5(fn,dig)
if result_code <> 0 then
msgInfo("Error","Result from dll call to file_md5 is: "+ string(result_code))
endIf
digest = dig ;digest is a field on the form
endMethod
Here's the uses block:
Uses md5jra
file_md5(filename CPTR, digest CPTR) CLONG
endUses
and here's the DLL code:
__declspec(dllexport)int file_md5(char *fnm,char *retdig)
{
md5_state_t state;
md5_byte_t digest[16];
FILE *infile;
unsigned int n;
char data[64];
if ((infile = fopen(fnm,"rb")) == NULL)
return -1;
md5_init(&state);
while (!feof(infile)){
n = fread(data,1,64,infile);
md5_append(&state,data,n);
}
md5_finish(&state,digest);
for (n=0;n<16;n++)
retdig[n] = digest[n];
fclose(infile);
return 0;
}
The problem I'm having is that any filenames longer than 4 characters cause a GPF. Also the digest gets truncated to 6 bytes.
I used Microsoft Virtual C++ .NET Framework SDK to create the DLL - it's compiled as a regular non-MFC DLL.
Also, while we're at it, the PAL help file says referenced DLLs are searched for first in the "current directory". What's the current directory when running the application? Apparently it's neither where the app's forms nor exe file is. For the moment I'm copying the DLL into the windows system directory.
Here's the code:
method pushButton(var eventInfo Event)
var
result_code LongInt
dig,fn String
endVar
fn = filename ;filename is a field on the form
result_code = file_md5(fn,dig)
if result_code <> 0 then
msgInfo("Error","Result from dll call to file_md5 is: "+ string(result_code))
endIf
digest = dig ;digest is a field on the form
endMethod
Here's the uses block:
Uses md5jra
file_md5(filename CPTR, digest CPTR) CLONG
endUses
and here's the DLL code:
__declspec(dllexport)int file_md5(char *fnm,char *retdig)
{
md5_state_t state;
md5_byte_t digest[16];
FILE *infile;
unsigned int n;
char data[64];
if ((infile = fopen(fnm,"rb")) == NULL)
return -1;
md5_init(&state);
while (!feof(infile)){
n = fread(data,1,64,infile);
md5_append(&state,data,n);
}
md5_finish(&state,digest);
for (n=0;n<16;n++)
retdig[n] = digest[n];
fclose(infile);
return 0;
}