Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
String Parameter
Message
De
13/04/2000 07:31:22
 
 
Information générale
Forum:
Visual Basic
Catégorie:
Contrôles ActiveX
Divers
Thread ID:
00358658
Message ID:
00359168
Vues:
10
Hi Larry,

Thanks for the info. I will give this a try and see how it works. My latest response to D. Frankenbach in the "Removing a DLL from memory" thread outlines my current "solution".

Bill

>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
William A. Caton III
Software Engineer
MAXIMUS
Atlanta, Ga.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform