Hi all
I experimenting with the MS Winsock OCX.
I use the normal OCX support in FF to use it
I can connect to an echo server on my PC OK
I can send Data to the echo server and see it on the echo server.
I can close the connection OK.
when I receive the replay from the echo server the DataArrival event does fire and I get a valid bytesTotal (13 in my case)
when I call the .GetData method and convert the variant paramter to a string it appears to be blank.
below is the actual code I am using from the events.inc file
I am leaving the office now and will only be back on Monday AM, so if I don't respond till then , it's not because I don't appreciate the help
regards
' ********************************************************************************************
' Function name: DataArrival
' ********************************************************************************************
FUNCTION MSWinsockDMSWinsockControlEvents1_DataArrival(BYVAL dwCookie AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
LOCAL pv AS VARIANT PTR, pvapi AS VARIANTAPITYPE PTR
pv = pdispparams.VariantArgs : pvapi = pv
' ==============================================================================
' Parameters in DISPPARAMS are zero based and in reverse order
' ==============================================================================
LOCAL bytesTotal AS LONG
bytesTotal = VARIANT#(@pv[0])
' ==============================================================================
' *** Put your code here ***
' ==============================================================================
Dim vBuff As Variant
Object Call DISPATCH_FORM1_SOCKMAIN.GetData(vBuff)
Call OutputDebugString("data arrival fired " & Str$(bytesTotal) & " " & Str$(Err) & " " & Hex$(ObjResult) & " " & Variant$(vBuff))
FUNCTION = 0 ' %S_OK
END FUNCTION
You aren't specifying the type of data to recover, so it must be returning an array of bytes. Use:
Dim vBuff As Variant
Dim vType As Variant
Dim vMaxLen As Variant
vType = %VT_BSTR As Long
vMaxLen = bytesTotal As Long
Object Call DISPATCH_FORM1_SOCKMAIN.GetData(vBuff, vType, vMaxLen)
Jose
I had tried similar approaches on Friday, but left them out in order to simplify my post.
I used the code suggested in your post and still got an empty string.
I added a call to the VARIANTVT function as in the code below
Dim vBuff As Variant
Dim vType As Variant
Dim vMaxLen As Variant
Dim iVariantType As Long
vType = %VT_BStr As Long
vMaxLen = bytesTotal As Long
Object Call DISPATCH_FORM1_SOCKMAIN.GetData(vBuff, vType, vMaxLen)
iVariantType = VariantVT(vBuff)
Call OutputDebugString("Vartype = " & Str$(iVariantType))
Call OutputDebugString("data arrival fired " & Str$(bytesTotal) & " " & Str$(Err) & " " & Hex$(ObjResult) & " " & Variant$(vBuff))
iVariantType is 0, which acc to the doc is EMPTY.
I ran the ocx thru the PB COM Browser and this is from the Interface / End interface block
Member Call GetData<&H00000044>(inout data As Variant<&H00000000>, optional in type As Variant<&H00000001>, optional in maxLen As Variant<&H00000002>)
Where would I add this declaration in my fireFly code which does not use the PB Com Browser, I think the INOUT of the first param is the problem, or is this handled automatically in the line
Object Call DISPATCH_FORM1_SOCKMAIN.GetData(vBuff, vType, vMaxLen)
[/code]
Which version of the compiler are you using? If you are using 8.03 you can try the following:
DIM strBuff AS STRING
DIM vBuff AS VARIANT
DIM vType AS VARIANT
DIM vMaxLen AS VARIANT
vType = %VT_BSTR AS LONG
vMaxLen = bytesTotal AS LONG
vBuff = BYREF strBuff
Object Call DISPATCH_FORM1_SOCKMAIN.GetData(vBuff, vType, vMaxLen)
MSGBOX ACODE$(strBuff) ' or MSGBOX VARIANT$(vBuff)
If it fails, you can try:
FUNCTION WinsockControl_GetData ( _
BYVAL pthis AS DWORD PTR _
, BYREF prmdata AS VARIANT _
, BYVAL varPrmtype AS VARIANT _
, BYVAL maxLen AS VARIANT _
) AS LONG
LOCAL HRESULT AS LONG
CALL DWORD @@pthis[26] USING WinsockControl_GetData(pthis, prmdata, varPrmtype, maxLen) TO HRESULT
FUNCTION = HRESULT
END FUNCTION
DIM hr AS LONG
DIM vBuff AS VARIANT
hr = WinsockControl_GetData(OBJPTR(DISPATCH_FORM1_SOCKMAIN), vBuff, %VT_BSTR, bytesTotal)
MSGBOX VARIANT$(vBuff)
Thanks Jose
Will try this as soon as I get a chance and let you know the result.
unfortunately a meeting beckons...
Jose
I tried both methods you suggested and both work perfectly, thanks very much for your help.
Just out of interest the first method (version 8 of PB compiler)
vBuff has a variant type of 16392 which is %VT_BYREF or %VT_BSTR
While the second method vBuff has a variant type of 8 which is %VT_BSTR
Using the second method you are seeing how things really work. As with any other function, parameters are passed by reference or by value. That's all.
Using the first method, Automation intervenes. For some reason, some out or inout parameters of some components want a VT_BYREF variant containing a reference to a variable. Using my browser, they can be identified when they have an indirection level of 1.
I downloaded your Type Lib Browser and genned the code for Winsock as an example. I can see the value as a tool for getting COM to work with PB, now I just need to become more familiar with the internals of COM as I enjoy understanding how the wrappers work internally even though they work perfectly at a more abstract level. Thanks for an amazing contribution to the PB/FF community.