d_lalit
asked on
DLL API String return value query
Hi,
We are trying to access the following API , present in a particular DLL :
API defined in C:
short EXPORT TblGetValue(char *Param1, char *Param2, void *RetValue)
This API returns the value in the variable 'RetValue'
For Example if we need a value which satifies the conditions passed in Param1 and Param2 the value will be returned in RetVal
Stat = TblGetValue('TESTTBL','TES TKEY',RetS trValue)
The value is returned in the 'RetStrValue' parameter.
Declaration in VB:
public declare function TblGetValue LIB "TABLE32.DLL" (ByVal TblId As String, ByVal KeyId As String, ByRef Value as String) As Integer.
When we try to access this in VB we get a following message :
"Variable uses an automation type not supported in Visual Basic."
Please can anyone let us know the solution to this issue. We are using VB6.0 on Windows 2000.
Thanks
We are trying to access the following API , present in a particular DLL :
API defined in C:
short EXPORT TblGetValue(char *Param1, char *Param2, void *RetValue)
This API returns the value in the variable 'RetValue'
For Example if we need a value which satifies the conditions passed in Param1 and Param2 the value will be returned in RetVal
Stat = TblGetValue('TESTTBL','TES
The value is returned in the 'RetStrValue' parameter.
Declaration in VB:
public declare function TblGetValue LIB "TABLE32.DLL" (ByVal TblId As String, ByVal KeyId As String, ByRef Value as String) As Integer.
When we try to access this in VB we get a following message :
"Variable uses an automation type not supported in Visual Basic."
Please can anyone let us know the solution to this issue. We are using VB6.0 on Windows 2000.
Thanks
Surprisingly I think you have to call it with a ByVal instead of a ByRef
i.e.
public declare function TblGetValue LIB "TABLE32.DLL" (ByVal TblId As String, ByVal KeyId As String, ByVal Value as String) As Integer
This is to do with VB's string pointer handling. You create a buffer and pass the value of the pointer to the start of that buffer. Also, you'll need to fill the Value buffer before you call it.
i.e.
public declare function TblGetValue LIB "TABLE32.DLL" (ByVal TblId As String, ByVal KeyId As String, ByVal Value as String) As Integer
This is to do with VB's string pointer handling. You create a buffer and pass the value of the pointer to the start of that buffer. Also, you'll need to fill the Value buffer before you call it.
This may apply:
PRB: Error Compiling VB5 Project Using LPVOID in Type Library
http://support.microsoft.com/default.aspx?scid=kb;en-us;193016
Also, if the C DLL is passing char*, then I believe you must receive it into a byte array, then use the StrConv function to convert it back to inicode.
PRB: Error Compiling VB5 Project Using LPVOID in Type Library
http://support.microsoft.com/default.aspx?scid=kb;en-us;193016
Also, if the C DLL is passing char*, then I believe you must receive it into a byte array, then use the StrConv function to convert it back to inicode.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ByRef Value as any
or
ByRef Value as Variant