Dim pUser() As Byte && HERE
Dim retval&
Dim size&
Dim MyUserId$
MyUserId$ = Space(256) ' or =String$(256,0)
pUser = MyUserID$ & vbNullChar && HERE
Dim objSysData
Set objSysData = CreateObject("SysData.IssSysData")
retval = objSysData.IssUserName(pUser(0), size) && HERE
Label1.Caption = "User ID: " & Left(MyUserId$, size - 1)
HTH.
>I have created a C++ COM DLL containing a function which accepts a "string" type parameter by reference and a "long" parameter by reference. The return value of the function is a long. Internally, the COM DLL calls the API GetUserName() function to load data into the passed parameter references.
>
>I tested the DLL function in VFP and it works fine:
>
>ox = CREATEOBJECT( "SysData.IssSysData" )
>cSize = 256 && Integer type
>cUser = SPACE( cSize ) && Character type
>nResult=ox.IssUserName(@cUser,@cSize)
>?"Return = " + ALLTRIM( STR( nResult ) )
>?"Size = " + ALLTRIM( STR( cSize ) )
>MyId = '>' + LEFT( UPPER( cUser ), cSize - 1 ) + '<'
>?MyId
>ox = NULL
>
>However, when I try to test the DLL function in VB I get a return value (0) indicating the function failed, gibberish in the character type variable, but the Integer type variable contains the right value. This indicates to me that there is some problem in passing the character type variable reference. I have tried several different declarations and initializations for the character type variable but none have been successful or simply will not compile. An example of the code that compiles and runs but returns bad data is:
>
> Dim retval&
> Dim size&
> Dim MyUserId$
> MyUserId$ = Space(256) ' or =String$(256,0)
> Dim objSysData As New IssSysData
>' or:
>' Dim objSysData
>' Set objSysData = CreateObject("SysData.IssSysData")
> retval = objSysData.IssUserName(MyUserId$, size)
> Label1.Caption = "User ID: " & Left(MyUserId$, size - 1)
>
>What am I missing in how to correctly pass the character type variable in VB to the COM DLL function?
>
>Thanks,
>BillLarry Miller
MCSD
LWMiller3@verizon.net
Accumulate learning by study, understand what you learn by questioning. -- Mingjiao