I am using a hardware interface DLL provided by a third party. They provide a C++ header file with function prototypes supposedly used in the DLL, and some example VB6 code that has definite errors. I want to make sure I am defining VB6 function declarations correctly, but the only documentation I can find on VB6 declarations is for simple function arguments.
My specific 6 questions are 'numbered' below, i.e. 1) ... 2) ...with colored code snipets (C++ is blue, VB6 is green)
Could someone please confirm that EACH of the VB6 declares provided are correct?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1) Is there a difference when passing C++ const char* vs char* ? Are they both String in VB6?
typedef int XCHANDLE
typedef unsigned long ErrCode
(Note: both of these would be 4 bytes in C++, so I am using Long in VB6)
ErrCode XC_GetList(char *pList, int MaxLen)
ErrCode XC_GetPropertyValueL(const char *pProp, long *pValue)
Public Declare Function XC_GetList Lib "foo" (ByVal pList As String, ByVal MaxLen As Long) As Long
Public Declare Function XC_GetPropertyValueL (ByVal pProp As String, ByRef pValue As Long) As Long
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2) Are C++ enumerated list values passed as 4 bytes? (Long in VB6 ? It seems to work, but would Int - 2 bytes - be correct?)
typedef enum
{
X_BlaBla = 1,
X_Foo = 2,
X_Bar = 4
} XFlags;
ErrCode XC_Example(XCHANDLE h, XFlags F)
Public Declare Function XC_Example "foo" (ByVal h As Long, F As Long) As Long
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3) How are C++ void * buffers declared in VB6? (Should they be type Any or Int if I expect a buffer of 16 bit data? Both seem to work, I think)
ErrCode XC_GetFrame(XCHANDLE h, void *buffer, unsigned int size)
' Example from vendor
Public Declare Function XC_GetFrame "foo" (ByVal h As Long, ByRef buffer As Any, ByVal size As Long) As Long
' Alternate version
Public Declare Function XC_GetFrame "foo" (ByVal h As Long, ByRef buffer As Int, ByVal size As Long) As Long
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4) Is a C++ function with a void return declared as a VB6 Subroutine?
void XC_CloseCamera (XCHANDLE h);
Public Declare Sub XC_CloseCamera Lib "foo" (ByVal h As Long)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5) I am not using a callback, but I'm not sure if the function declaration is correct. I am a bit confused about how to pass a typedef as an argument type, but in this case, the 'value' to be used when calling, is zero, according to the example code provided.
/** Status callback prototype */
/** @param v_pUserParm - user parameter */
/** @param iMsg - as per XStatusMessage */
/** @param ulP - progress */
/** @param ulT - total */
/** @param pMsgParm msg parameter */
/** Notes: */
/** When iMsg == XSMessage a string pointer is passed in the integers ulP and ulT, the lower part of the address is stored in ulP, the
higher in ulT (64-bit port) */
typedef ErrCode (CALLCVCB *XStatus)(void *v_pUserParm, int iMsg, unsigned long ulP, unsigned long ulT);
XCHANDLE XC_Open(const char *name="cam://", XStatus pCallBack = 0, void *pUser=0)
' Declaration
Public Declare Function XC_Open(ByVal name As String, pCallBack As Long, ByRef pUser As Long) As Long
' or ??
Public Declare Function XC_Open(ByVal name As String, pCallBack As Long, ByVal pUser As Long) As Long
' Example use in code from vendor:
Dim lngHandle As Long
lngHandle = XC_Open("cam://", 0, 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6) Does this kind of conditional make sense for VB6 compatibility?
Their SDK header file begins with:
#ifdef _WIN32
# ifndev CALLCV
# define CALLCV __stdcall /// <Compatibility with VB6
# define CALLCVB __cdecl
# else
# pragma message ("Warning: building using custom calling convention.")
# endif
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks in advance...
My specific 6 questions are 'numbered' below, i.e. 1) ... 2) ...with colored code snipets (C++ is blue, VB6 is green)
Could someone please confirm that EACH of the VB6 declares provided are correct?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1) Is there a difference when passing C++ const char* vs char* ? Are they both String in VB6?
typedef int XCHANDLE
typedef unsigned long ErrCode
(Note: both of these would be 4 bytes in C++, so I am using Long in VB6)
ErrCode XC_GetList(char *pList, int MaxLen)
ErrCode XC_GetPropertyValueL(const char *pProp, long *pValue)
Public Declare Function XC_GetList Lib "foo" (ByVal pList As String, ByVal MaxLen As Long) As Long
Public Declare Function XC_GetPropertyValueL (ByVal pProp As String, ByRef pValue As Long) As Long
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2) Are C++ enumerated list values passed as 4 bytes? (Long in VB6 ? It seems to work, but would Int - 2 bytes - be correct?)
typedef enum
{
X_BlaBla = 1,
X_Foo = 2,
X_Bar = 4
} XFlags;
ErrCode XC_Example(XCHANDLE h, XFlags F)
Public Declare Function XC_Example "foo" (ByVal h As Long, F As Long) As Long
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3) How are C++ void * buffers declared in VB6? (Should they be type Any or Int if I expect a buffer of 16 bit data? Both seem to work, I think)
ErrCode XC_GetFrame(XCHANDLE h, void *buffer, unsigned int size)
' Example from vendor
Public Declare Function XC_GetFrame "foo" (ByVal h As Long, ByRef buffer As Any, ByVal size As Long) As Long
' Alternate version
Public Declare Function XC_GetFrame "foo" (ByVal h As Long, ByRef buffer As Int, ByVal size As Long) As Long
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4) Is a C++ function with a void return declared as a VB6 Subroutine?
void XC_CloseCamera (XCHANDLE h);
Public Declare Sub XC_CloseCamera Lib "foo" (ByVal h As Long)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5) I am not using a callback, but I'm not sure if the function declaration is correct. I am a bit confused about how to pass a typedef as an argument type, but in this case, the 'value' to be used when calling, is zero, according to the example code provided.
/** Status callback prototype */
/** @param v_pUserParm - user parameter */
/** @param iMsg - as per XStatusMessage */
/** @param ulP - progress */
/** @param ulT - total */
/** @param pMsgParm msg parameter */
/** Notes: */
/** When iMsg == XSMessage a string pointer is passed in the integers ulP and ulT, the lower part of the address is stored in ulP, the
higher in ulT (64-bit port) */
typedef ErrCode (CALLCVCB *XStatus)(void *v_pUserParm, int iMsg, unsigned long ulP, unsigned long ulT);
XCHANDLE XC_Open(const char *name="cam://", XStatus pCallBack = 0, void *pUser=0)
' Declaration
Public Declare Function XC_Open(ByVal name As String, pCallBack As Long, ByRef pUser As Long) As Long
' or ??
Public Declare Function XC_Open(ByVal name As String, pCallBack As Long, ByVal pUser As Long) As Long
' Example use in code from vendor:
Dim lngHandle As Long
lngHandle = XC_Open("cam://", 0, 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6) Does this kind of conditional make sense for VB6 compatibility?
Their SDK header file begins with:
#ifdef _WIN32
# ifndev CALLCV
# define CALLCV __stdcall /// <Compatibility with VB6
# define CALLCVB __cdecl
# else
# pragma message ("Warning: building using custom calling convention.")
# endif
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks in advance...