How to Pass string pointer to OLEObject

Hello everyone,

I am trying to speak with a Fiscal Device, and I am stuck in trying to pass a parameter as a pointer, so that the device can write in it its data.
The code I use for Xojo is:

ivOpos = New OLEObject("OPOS.FiscalPrinter.1.7", True) Dim params(), v As Variant params(1) = 0 params(2) = 0 params(3) = "Q/" v = ivOpos.Invoke("directio", params)

However it doesn’t work (I don’t know if it works at all, since I don’t get anything back).
In C# however the code (that works) is:

[code]string info = “”;
int error, j = 0;

info = “Q/”;
error = ivOpos.DirectIO(0, ref j, ref info);[/code]

The connection to the fiscal device works with Xojo, as all other actions that don’t require to return a value work with similar syntax!

Any ideas how I can pass a parameter (or 2) as pointers / references?

Thank you all very much in advance!

Not sure if it’s a typo… But you should give your array a size: Dim params(4) as Variant

See http://documentation.xojo.com/index.php/Dim

Yes John, just a typo (actually omitting some lines of code)

[quote=155126:@John Hansen]Not sure if it’s a typo… But you should give your array a size: Dim params(4) as Variant

See http://documentation.xojo.com/index.php/Dim[/quote]

Ups… I had a Typo. Should be Dim params(3) as Variant and not Dim params(4) as Variant

The size is The upper bound of the array. and not the total numbers of arrays… According to the documentation. http://documentation.xojo.com/index.php/Dim

I have never worked with fiscalprinter. But does it apply to the same as shown in Microsoft documentation: http://msdn.microsoft.com/en-us/library/ms850045(v=winembedded.10).aspx… If I had an example from VB6 or vbscript I would might be able to help you out on this.

All I can say is that the Invoke method works perfectly in all cases except for this one, in which I need to pass a parameter (the last one) as a reference.

And you are sure this is a method and not a property ?

Just out of interest what happen if you do this instead: v = ivOpos.directio(params(1), params(2), params(3))

[quote=153698:@FOTIS GEORGIADIS]Hello everyone,

I am trying to speak with a Fiscal Device, and I am stuck in trying to pass a parameter as a pointer, so that the device can write in it its data.
The code I use for Xojo is:

ivOpos = New OLEObject("OPOS.FiscalPrinter.1.7", True) Dim params(), v As Variant params(1) = 0 params(2) = 0 params(3) = "Q/" v = ivOpos.Invoke("directio", params)

However it doesn’t work (I don’t know if it works at all, since I don’t get anything back).
In C# however the code (that works) is:

[code]string info = “”;
int error, j = 0;

info = “Q/”;
error = ivOpos.DirectIO(0, ref j, ref info);[/code]

The connection to the fiscal device works with Xojo, as all other actions that don’t require to return a value work with similar syntax!

Any ideas how I can pass a parameter (or 2) as pointers / references?

Thank you all very much in advance![/quote]

I see in your C# you assign the error as an integer, and in Xojo you assign it as a variant.

Even though it should return an integer, I sometimes had issues it returned an object when I used variant

So what happen if you do this:

Dim ivOpos As OleObject ivOpos = New OLEObject("OPOS.FiscalPrinter.1.7", True) Dim params(3) As Variant Dim Error As integer params(1) = 0 params(2) = 0 params(3) = "Q/" Error = ivOpos.Invoke("directio", params)

John hi,
It makes no difference if the return variable is an integer or a variant,

Also it doesn’t accept the parameters separately for some reason. I had already tried that. Any other ideas?

[quote=155157:@FOTIS GEORGIADIS]John hi,
It makes no difference if the return variable is an integer or a variant,

Also it doesn’t accept the parameters separately for some reason. I had already tried that. Any other ideas?[/quote]

Difficult to help, when I don’t have more informations. But what do you see when you use the debugger. is V empty when it’s a variant

No, in both cases the return value is 0, which means no error! However, the actual method in OPOS is doing nothing and of course doesn’t return anything in params(3)…

Arrays start at 0 (zero) and not 1. Shouldn’t your params be (0), (1) and (2)?

That is correct, but when used with oleobject the array number in params has to begin with number 1

Any time you want a return value written into a string, you should pass a memoryblock. Xojo strings are immutable and cannot be written to.

Thank Tim. However the parameters have to be passed as an array - as far as I can tell - and the first variable has to be an integer, the second a reference to an integer and the third a reference to a string. Could I put a memoryblock in a variant array?

A variant array can hold any kind of object.

dim v(2) as variant
dim i as integer
dim s as string
dim mb as new memoryblock(512)
v(0) = i
v(1) = s
v(2) = mb

Note that v(2) in this instance becomes a pointer to the memory allocated by mb.

Thanks Tim. I will check it in the next couple of days and get back to you. My only concern is that the OLE object needs to read that param (since it contains the command) and then write the answer (as string) in it.
I hope it works.

[quote=155328:@FOTIS GEORGIADIS]Thanks Tim. I will check it in the next couple of days and get back to you. My only concern is that the OLE object needs to read that param (since it contains the command) and then write the answer (as string) in it.
I hope it works.[/quote]

If you had any example code in another language, that may give you a hint at the kind of parameters the DLL excepts. Could the support of that DLL provide that ?

Hi Michel,
If you see my initial post I have some working code in C#.

[quote=155332:@FOTIS GEORGIADIS]Hi Michel,
If you see my initial post I have some working code in C#.[/quote]

I am not a C# specialist, but it seems it is a C string, not an array.