Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
String Parameter
Message
 
 
To
12/04/2000 10:24:01
General information
Forum:
Visual Basic
Category:
ActiveX controls
Miscellaneous
Thread ID:
00358658
Message ID:
00359146
Views:
9
Hi Bill,
Try setting up a byte array and copy your string to it; then pass that to your object. I haven't tried this but this technique has worked for me with C library DLLs so it might work for COM too.
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,
>Bill
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform