
Problems calling a VC DLL from VB
I'm having a problem with VB 5.0 (SP3) and VB 6.0 (SP1) giving me an
"memory could not be read" message in a program after calling a win32
DLL built in-house with VC 5.0 (SP3). The DLL is declared in VB as:
Private Declare Function cryptfile Lib "aegdes.dll" _
(ByVal action As Integer, ByVal _
InFile As String, ByVal OutFile As String, ByVal keyin As String)_
As Integer
The call to the DLL looks like:
dim retval as integer
dim strInFile as String
dim strOutFile as String
dim strKey as String
strInFile = "Foo"
strOutFile = "Foo.cry"
strKey = "mykey"
' Parameter 2 indicates that the action should be to decrypt
retval = cryptfile(2, strInFile, strOutFile, strKey)
The declaration in VC for the exported function is:
extern "C" __declspec(dllexport) int cryptfile(const int action, const
char in[], const char out[], const char keyin[])
The "memory could not be read" error ocurrs AFTER the dll has returned
sucessfully (ususally within a few statements of the call). There
seems to be no fault in the dll and the error only happens when called
with a VB program, a production program in VC that uses the DLL works
flawlessly and a call to _heapchk() in VC returns HEAP_OK both before
and after calling the DLL. The DLL does not use a custon DLLMain, it
uses whatever default VC links in.
Also, one other interesting fact, the error ONLY happens if the VB
program is compiled with optimizations turned ON. If I turn OFF
optimization in VB, the program works flawlessly and returns no
error.
The exact error I get is:
'The instruction at "0x0016f989" referenced memory at "0x0000f872".
The memory could not be "read". '
The first addresses also "move" and are not constant between
invocations.
Any help or ideas would be greatly appreciated.
Thomas
--
Thomas Hays
Aegis Marketing Group, Inc.