Problems calling a VC DLL from VB 
Author Message
 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.



Tue, 29 May 2001 03:00:00 GMT  
 Problems calling a VC DLL from VB
Your problem seems to be how you're declaring the return value in VB.  In
VC, an int is a 32-bit value.  An Integer in VB is 16 bits.  So, you should
declare the return value in VB "As Long".


Tue, 29 May 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Problem calling DLL writen in VC 5.0 from VB 5.0

2. VC 6 dll called from VB 5 problem

3. Problem calling DLL writen in VC 5.0 from VB 5.0

4. Problem calling DLL writen in VC 5.0 from VB 5.0

5. Problem calling DLL writen in VC 5.0 from VB 5.0

6. vb calls vc dll and strings get chopped

7. calling VC DLL from VB

8. Calling VC++ programs and VC created dlls from VB

9. Calling C DLLs with VB/VC 5

10. Calling VB DLLs from VC/C++

11. can you create a dll in VB and call in VC

12. VB Call to VC DLL

 

 
Powered by phpBB® Forum Software