Hey guys,

I am trying to use a certain function from a VC++ DLL in my VB6 project. The original VC++ function looks like this:
Code:
DLLEXPORT UNI_STATUS sysTabRead (const void *pTopicString,
				const int topicIndex,
				const void *pItemString,
				const  int itemIndex,
				void *tableAddrs,
				int tableSize,
				SYS_TAB_ACCESS_TYPE accessType)

typedef enum 
{
/* bit field */
	DYNAMIC=1,
	SAVED=2,
	DEFAULT=4,
	MINIMUM=8,
	MAXIMUM=16,
} SYS_TAB_ACCESS_TYPE;

typedef enum {UNI_ERROR=-1, UNI_OK=0} UNI_STATUS;
When integrating the code in VB6, I wrote the following:
vb Code:
  1. Public Enum SYS_TAB_ACCESS_TYPE
  2.     DYNAMIC = &H1&
  3.     SAVED = &H2&
  4.     'DEFAULT = &H4&
  5.     MINIMUM = &H8&
  6.     MAXIMUM = &H10&
  7. End Enum
  8.  
  9. Public Enum UNI_STATUS
  10.     UNI_ERROR = -1&
  11.     UNI_OK = 0&
  12. End Enum
  13.  
  14. Public Declare Function sysTabRead Lib "systab.dll" ( _
  15.         ByVal pTopicString As String, _
  16.         ByVal topicIndex As Long, _
  17.         ByVal pItemString As String, _
  18.         ByVal itemIndex As Long, _
  19.         ByRef tableAddrs As Any, _
  20.         ByVal tableSize As Long, _
  21.         ByVal accessType As SYS_TAB_ACCESS_TYPE) As UNI_STATUS
Now, here comes the tricky part, I have absolutely no idea where the "ByVal" declaration is necessary. I do know, however, that "ByRef" for tabelAddrs is required because tableAddrs is a pointer. The funny thing is that when I call the function, for example, in the following test subroutine:
vb Code:
  1. Public Sub Test()
  2.     Dim errRet As UNI_STATUS, tableAddrs As Long
  3.     errRet = sysTabRead("testTopic", 0, "testKey", 0, tableAddrs, 4, DYNAMIC)
  4.     Debug.Print errRet
  5.     Debug.Print tableAddrs
  6. End Sub
I receive a run-time error (49): "Bad DLL calling convention". However, if I choose to disregard the error (On Error Resume Next...), the function actually works, errRet returning as 0 (UNI_OK), and tableAddrs returning as the long value I was expecting. The thing is that a couple of seconds after the sub ends, VB6 crashes due to an incorrect memory "read" request...

I'm pretty sure that my problem is with the ByVals or with the argument types... Any ideas?