Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
String Parameter
Message
From
13/04/2000 09:38:25
 
General information
Forum:
Visual Basic
Category:
ActiveX controls
Miscellaneous
Thread ID:
00358658
Message ID:
00359232
Views:
13
Hi again Larry,

I tried this approach and was not able to get it to work. May be something I was doing wrong, but I got "Type mismatch error" when it hit the function call statement. Tried a couple of variations in the parameter declaration in the DLL with no success. Interestingly, tho I have found references in the MSDN Library and in the MS KB to passing VB strings to C DLL's, I've found nothing about passing them to COM DLLs.

Also interestingly, a VB guy here said he talked with a friend who regularly writes C++ COM components and the stated rule in their shop ( Coca-Cola ) is that no COM objects are to be written that receive VB strings. I wonder if this is indicative somehow?

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.
Previous
Reply
Map
View

Click here to load this message in the networking platform