Transport binary values over COM between X# and VO

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Transport binary values over COM between X# and VO

Post by wriedmann »

Hi Robert,
is there any possibility to transport binary values over the COM interface between an X# COM module and a VO application? I need that for encrypted and/or compressed values.
For sure it would work if the value is converted for and back to Base64, but I would prefer to not need that because it not only blows up data by about 33%, but has also a non indifferent performance influence.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Transport binary values over COM between X# and VO

Post by robert »

Wolfgang,
COM usually uses a SafeArray of Bytes for this.
I am afraid that this is not completely supported by VO.
SafeArray return values returned from the COM server will most likely be converted to a normal VO array where each element in the array represents a byte.
To send a Safe Array from VO you would have to create the SafeArray yourself and wrap it in a OleBinary object
The VO Ole Classes will know how to handle the OleBinary

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Transport binary values over COM between X# and VO

Post by wriedmann »

Hi Robert,
thank you very much!
Il will look into it and let you know if I was able to do it, and then publish the code here.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Transport binary values over COM between X# and VO

Post by wriedmann »

Hi Robert,
So if I understand it correctly, I have to do that:
1) from the VO application to the X# COM module I have to create a OleBinary object passing the binary string to the init method. On the X# side I should receive that as 1-based byte[] structure according to this article: http://www.windows-tech.info/1/813f6954a4261c78.php and this here https://weblog.west-wind.com/posts/2008 ... -Call-in-C
2) from the COM module I can pass a SafeArray structure to VO, and I will receive a VO array.
Thank you very much for your help!
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Transport binary values over COM between X# and VO

Post by wriedmann »

Hi Robert,
I have done now some tests.
From X#/COM to VO it works very well as you wrote:
X#:

Code: Select all

public virtual method GetByteArray() as byte[]
	local aReturn			as byte[]
	local nI				as int

	aReturn				:= byte[]{ 256 }
	for nI := 0 upto 255
		aReturn[nI+1]		:= ( byte ) nI
	next

	return aReturn
VO:

Code: Select all

METHOD GetByteArray(		) CLASS ICOMTester

	LOCAL oMethod  	AS cOleMethod
	LOCAL uRetValue	AS USUAL

	oMethod		      	:= cOleMethod{}
	oMethod:symName	  	:= String2Symbol("GetByteArray")
	oMethod:iMemberid  	:= 3 
	oMethod:wInvokeKind	:= INVOKE_METHOD  
	oMethod:bRetType   	:= VT_UI1 

	uRetValue := SELF:__Invoke(oMethod, DWORD(_BP+16),PCount())

	RETURN (uRetValue)
On the VO side I see a normal VO array of bytes.

The reverse after a bit of changes works also now:
X#:

Code: Select all

public virtual method SetByteArray( aData as byte[] ) as logic

	System.IO.File.WriteAllBytes( System.IO.Path.Combine( AppDomain.CurrentDomain:BaseDirectory, "SetByteArray.txt" ), aData )

	return true
VO:

Code: Select all

METHOD SetByteArray(;
		aData;		// AS USUAL
		) CLASS ICOMTester

	LOCAL oMethod  	AS cOleMethod
	LOCAL uRetValue	AS USUAL

	oMethod		      	:= cOleMethod{}
	oMethod:symName	  	:= String2Symbol("SetByteArray")
	oMethod:iMemberid  	:= 4 
	oMethod:wInvokeKind	:= INVOKE_METHOD  
	oMethod:nParams    	:= 1 
	oMethod:lNamedArgs 	:= TRUE 
	oMethod:cParamTypes	:= VTS_VARIANT
	oMethod:bRetType   	:= VT_BOOL 

	uRetValue := SELF:__Invoke(oMethod, DWORD(_BP+16),PCount())

	RETURN (uRetValue)
and calling that with

Code: Select all

	oOleBinary		:= OleBinary{ cBinString }
	oComTester:SetByteArray( oOleBinary )
Thank you very much for your help!

I will add that now to my SQL server libraries and try it also with the VO RDD.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply