Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #12059 > unrolled thread

C-DLL with paramter VARIANT and FILETIME?

Started byGerhard Bunzel <g.bunzel@domonet.de>
First post2018-10-19 04:38 +0200
Last post2018-10-23 21:07 +0200
Articles 11 — 3 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  C-DLL with paramter VARIANT and FILETIME? Gerhard Bunzel <g.bunzel@domonet.de> - 2018-10-19 04:38 +0200
    Re: C-DLL with paramter VARIANT and FILETIME? "Wolfgang Riedmann" <wriedmann@gmail.com> - 2018-10-19 06:18 +0200
      Re: C-DLL with paramter VARIANT and FILETIME? Gerhard Bunzel <g.bunzel@domonet.de> - 2018-10-19 11:29 +0200
        Re: C-DLL with paramter VARIANT and FILETIME? "Wolfgang Riedmann" <wriedmann@gmail.com> - 2018-10-21 05:58 +0200
          Re: C-DLL with paramter VARIANT and FILETIME? Gerhard Bunzel <g.bunzel@domonet.de> - 2018-10-21 15:06 +0200
            Re: C-DLL with paramter VARIANT and FILETIME? "Karl-Heinz" <invalid@invalid.invalid> - 2018-10-21 16:36 +0200
              Re: C-DLL with paramter VARIANT and FILETIME? Gerhard Bunzel <g.bunzel@domonet.de> - 2018-10-22 17:26 +0200
                Re: C-DLL with paramter VARIANT and FILETIME? "Karl-Heinz" <invalid@invalid.invalid> - 2018-10-22 21:20 +0200
                  Re: C-DLL with paramter VARIANT and FILETIME? Gerhard Bunzel <g.bunzel@domonet.de> - 2018-10-23 16:47 +0200
                    Re: C-DLL with paramter VARIANT and FILETIME? "Karl-Heinz" <invalid@invalid.invalid> - 2018-10-23 18:20 +0200
                      Re: C-DLL with paramter VARIANT and FILETIME? "Karl-Heinz" <invalid@invalid.invalid> - 2018-10-23 21:07 +0200

#12059 — C-DLL with paramter VARIANT and FILETIME?

FromGerhard Bunzel <g.bunzel@domonet.de>
Date2018-10-19 04:38 +0200
SubjectC-DLL with paramter VARIANT and FILETIME?
Message-ID<pqbg3b$hf7$1@news-1.m-online.net>
Hi all,

I have to use a C-DLL in a VO application.
Most of the C DLL-Functions are working fine - only one function with 
parameters as Variant and FILETIME wont work.

This is the C-function:
BOOL ReadOPCItem (HANDLE hConnect, HANDLE hGroup, HANDLE hItem, VARIANT 
*pVar, FILETIME *pTimeStamp, DWORD *pQuality);

Have used that with PTR, _winVariant, _winFiletime, __Variant2Usual() - 
nothing is working.
I would be very pleased if somone had a tip on how this C-funktion can 
be used.

Thanks in advance.

Best regards

Gerhard Bunzel

[toc] | [next] | [standalone]


#12060

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2018-10-19 06:18 +0200
Message-ID<g2t47vF5268U1@mid.individual.net>
In reply to#12059
Hi Gerhard,

probably you have to allocate memory for the relative structures and
pass in the pointers.

local strTimeStamp as _winFileTime


strTimeStamp := MemAlloc( _sizeof( _winFileTime ) )

and after the call to the function, don't forget to call MemFree(),

Wolfgang


Gerhard Bunzel wrote:

> Hi all,
> 
> I have to use a C-DLL in a VO application.
> Most of the C DLL-Functions are working fine - only one function with
> parameters as Variant and FILETIME wont work.
> 
> This is the C-function:
> BOOL ReadOPCItem (HANDLE hConnect, HANDLE hGroup, HANDLE hItem,
> VARIANT *pVar, FILETIME *pTimeStamp, DWORD *pQuality);
> 
> Have used that with PTR, _winVariant, _winFiletime, __Variant2Usual()
> - nothing is working.  I would be very pleased if somone had a tip on
> how this C-funktion can be used.
> 
> Thanks in advance.
> 
> Best regards
> 
> Gerhard Bunzel



-- 

[toc] | [prev] | [next] | [standalone]


#12061

FromGerhard Bunzel <g.bunzel@domonet.de>
Date2018-10-19 11:29 +0200
Message-ID<pqc867$oa4$1@news-1.m-online.net>
In reply to#12060
Hi Wolfgang,

thanks for your fast answer.

I've already tried that - in different variations.
Also the declaration of the C function with different types:
..., pFileTime AS _winFileTime, pQuality REF DWORD) ...
..., pFileTime REF _winFileTime, pQuality REF DWORD) ...
..., pFileTime AS PTR, pQuality REF DWORD) ...
..., pFileTime REF PTR, pQuality REF DWORD) ...
Nothing wants to work.

Any idea about VARIANT?

Thank you very much for your efforts.

Best regards

Gerhard


Am 19.10.2018 um 06:18 schrieb Wolfgang Riedmann:
> Hi Gerhard,
> 
> probably you have to allocate memory for the relative structures and
> pass in the pointers.
> 
> local strTimeStamp as _winFileTime
> 
> 
> strTimeStamp := MemAlloc( _sizeof( _winFileTime ) )
> 
> and after the call to the function, don't forget to call MemFree(),
> 
> Wolfgang

[toc] | [prev] | [next] | [standalone]


#12066

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2018-10-21 05:58 +0200
Message-ID<g32bruF75toU1@mid.individual.net>
In reply to#12061
Hi Gerhard,

working with pointers should work, it works in many places in my own
applications.

But I have now idea about VARIANT, never used it.
AFAIK VARIANT has to do with COM, I have seen it only there, and
Wikipedia says the same: https://en.wikipedia.org/wiki/Variant_type

So I  suspect you are trying to use the DLL the wrong way: with _DLL
instead of with COM/OLE.
What says the documentation about it?

Wolfgang

Gerhard Bunzel wrote:

> Hi Wolfgang,
> 
> thanks for your fast answer.
> 
> I've already tried that - in different variations.
> Also the declaration of the C function with different types:
> ..., pFileTime AS _winFileTime, pQuality REF DWORD) ...
> ..., pFileTime REF _winFileTime, pQuality REF DWORD) ...
> ..., pFileTime AS PTR, pQuality REF DWORD) ...
> ..., pFileTime REF PTR, pQuality REF DWORD) ...
> Nothing wants to work.
> 
> Any idea about VARIANT?
> 
> Thank you very much for your efforts.
> 
> Best regards
> 
> Gerhard
> 
> 
> Am 19.10.2018 um 06:18 schrieb Wolfgang Riedmann:
> > Hi Gerhard,
> > 
> > probably you have to allocate memory for the relative structures and
> > pass in the pointers.
> > 
> > local strTimeStamp as _winFileTime
> > 
> > 
> > strTimeStamp := MemAlloc( _sizeof( _winFileTime ) )
> > 
> > and after the call to the function, don't forget to call MemFree(),
> > 
> > Wolfgang



-- 

[toc] | [prev] | [next] | [standalone]


#12069

FromGerhard Bunzel <g.bunzel@domonet.de>
Date2018-10-21 15:06 +0200
Message-ID<pqhtkh$di7$1@news-1.m-online.net>
In reply to#12066
Hi Wolfgang,

thanks for your answer.

 > So I  suspect you are trying to use the DLL the wrong way: with _DLL
 > instead of with COM/OLE.
 > What says the documentation about it?
In the documentation is nothing about COM/OLE. There is also no 
registration needed.
All Function are working as expected - only this one with FileTime an 
VARIANT not.

VARIANT is a VB Data Type - like USUAL in VO:
https://docs.oracle.com/cd/B40099_02/books/VBLANG /VBLANGLangOverview15.html
After my previous research, that VARIANT should be a structur of 
_winVARIANT or _winVariantArg. There is also a function 
VariantInit(ptrVariant) available. To use that VARIANT in VO, there 
should be the function __Variant2Usual(..) used. Inside the SDK you can 
see, that function is reading the data type inside that VARIANT and 
gives back a VO data type. Reading an item with the DLL-function can 
habe different data types - date/time or string or logic or numeric. So 
VARIANT makes sense for that.
I hade never a problem with pointers and DLL. A function with callback 
for events of that DLL is also working - only FileTime and VARIANT in 
that one function will not.

Thanks in advance.

Best regards

Gerhard



Am 21.10.2018 um 05:58 schrieb Wolfgang Riedmann:
> Hi Gerhard,
> 
> working with pointers should work, it works in many places in my own
> applications.
> 
> But I have now idea about VARIANT, never used it.
> AFAIK VARIANT has to do with COM, I have seen it only there, and
> Wikipedia says the same: https://en.wikipedia.org/wiki/Variant_type
> 
> So I  suspect you are trying to use the DLL the wrong way: with _DLL
> instead of with COM/OLE.
> What says the documentation about it?
> 
> Wolfgang
> 
> Gerhard Bunzel wrote:
> 
>> Hi Wolfgang,
>>
>> thanks for your fast answer.
>>
>> I've already tried that - in different variations.
>> Also the declaration of the C function with different types:
>> ..., pFileTime AS _winFileTime, pQuality REF DWORD) ...
>> ..., pFileTime REF _winFileTime, pQuality REF DWORD) ...
>> ..., pFileTime AS PTR, pQuality REF DWORD) ...
>> ..., pFileTime REF PTR, pQuality REF DWORD) ...
>> Nothing wants to work.
>>
>> Any idea about VARIANT?
>>
>> Thank you very much for your efforts.
>>
>> Best regards
>>
>> Gerhard
>>
>>
>> Am 19.10.2018 um 06:18 schrieb Wolfgang Riedmann:
>>> Hi Gerhard,
>>>
>>> probably you have to allocate memory for the relative structures and
>>> pass in the pointers.
>>>
>>> local strTimeStamp as _winFileTime
>>>
>>>
>>> strTimeStamp := MemAlloc( _sizeof( _winFileTime ) )
>>>
>>> and after the call to the function, don't forget to call MemFree(),
>>>
>>> Wolfgang
> 
> 
> 

[toc] | [prev] | [next] | [standalone]


#12071

From"Karl-Heinz" <invalid@invalid.invalid>
Date2018-10-21 16:36 +0200
Message-ID<g33h9aFei8aU1@mid.individual.net>
In reply to#12069
Hi Gerhard,

i think you´ve also tried :

struVariant := memalloc ( _sizeof ( _winVariant ) )   ?


i found a description of the ReadOPCItem() func

//
// ReadOPCItem(...)
//
// May be used by an application to read the current value of an item.
// Is only valid if EnableDLLBuffering has been set to TRUE when the
// connection was established.
//


Did you set EnableDLLBuffering to true according the docs  ?

What does Getlasterror() show after the ReadOPCItem() call ?


regards
Karl-Heinz 

[toc] | [prev] | [next] | [standalone]


#12077

FromGerhard Bunzel <g.bunzel@domonet.de>
Date2018-10-22 17:26 +0200
Message-ID<pqkq76$8hj$1@news-1.m-online.net>
In reply to#12071
Hi Karl-Heinz,

thanks for your answer.


 > Did you set EnableDLLBuffering to true according the docs  ?
Yes - DllBuffering is enabled with:
myserverhandle := ConnectOPC(mymachinename, String2Psz(myserverlist[1]), TRUE)


I have tried:
    ptrVariant  := MemAlloc(_SIZEOF(_winVARIANT))	
    ptrFileTime := MemAlloc(_SIZEOF(_WINFILETIME))

ReadOPCItem(myserverhandle, mygrouphandle, myItemhandle, ptrVariant, ptrFileTime, @nQuality)
gives back a TRUE. GetLastError() is 0 - no Error.

So - maybe ptrVariant has to be initialized with:
VariantInit(ptrVariant)
ReadOPCItem() give also back a TRUE and GetLastError() is 0 - but no variant value.

If I look into the structure of _winVARIANT after ReadOPCItem() and check the members:
STRUCT _winVARIANT		ALIGN 1
	MEMBER   vt          	AS SHORT
vt is the data type of the Variant-Variable - should be VT_I2 or VT_I4 or VT_UI2 or VT_UI4 or VT_R4 or...
But vt is 0 - no data type. The complete structure is empty.

For the DLL function I have tried:
_DLL FUNCTION ReadOPCItem (nConnect AS LONG, pGroupConnect AS LONG, pItemConnect AS LONG, pVariant AS _winVARIANT, pFileTime AS _winFILETIME, pQuality REF DWORD) AS LOGIC PASCAL:WTclient._ReadOPCItem@24
and
_DLL FUNCTION ReadOPCItem (nConnect AS LONG, pGroupConnect AS LONG, pItemConnect AS LONG, pVariant AS PTR, pFileTime AS PTR, pQuality REF DWORD) AS LOGIC PASCAL:WTclient._ReadOPCItem@24
Should make no differece - both will not work.

The members of _winFiletime - dwLowDateTime and dwHighDateTime have the same value - for example 91362660

ptrFileTime with GetFDate(ptrFileTime) and GetFTime(ptrFileTime) gives only empty values.


I'm grateful for every tip.

Thanks in advance.

Best regards

Gerhard



Am 21.10.2018 um 16:36 schrieb Karl-Heinz:
> Hi Gerhard,
> 
> i think you´ve also tried :
> 
> struVariant := memalloc ( _sizeof ( _winVariant ) )   ?
> 
> 
> i found a description of the ReadOPCItem() func
> 
> //
> // ReadOPCItem(...)
> //
> // May be used by an application to read the current value of an item.
> // Is only valid if EnableDLLBuffering has been set to TRUE when the
> // connection was established.
> //
> 
> 
> Did you set EnableDLLBuffering to true according the docs  ?
> 
> What does Getlasterror() show after the ReadOPCItem() call ?
> 
> 
> regards
> Karl-Heinz

[toc] | [prev] | [next] | [standalone]


#12078

From"Karl-Heinz" <invalid@invalid.invalid>
Date2018-10-22 21:20 +0200
Message-ID<g36m7sF46l2U1@mid.individual.net>
In reply to#12077
Hi Gerhard,

> ReadOPCItem(myserverhandle, mygrouphandle, myItemhandle, ptrVariant,
> ptrFileTime, @nQuality)
> gives back a TRUE. GetLastError() is 0 - no Error.

strange ....


> This is the C-function:
> BOOL ReadOPCItem (HANDLE hConnect, HANDLE hGroup, HANDLE hItem, VARIANT
> *pVar, FILETIME *pTimeStamp, DWORD *pQuality);


_DLL FUNCTION ReadOPCItem (nConnect AS LONG, pGroupConnect AS LONG,
pItemConnect AS LONG, pVariant AS _winVARIANT, pFileTime AS _winFILETIME,
pQuality REF DWORD) AS LOGIC PASCAL:WTclient._ReadOPCItem@24

Why "AS LONG" ?  IMO nConnect, pGroupConnect and pItemConnect should be
declared "AS PTR" and not "AS LONG" ?

Have you tried to run the VB sample exe files that are included in
WTclient.zip - just to see that ReadOPCItem() works at least with VB ?


Isn´t there any C sample that shows how ReadOPCItem()  is called ?


regards
Karl -Heinz 

[toc] | [prev] | [next] | [standalone]


#12080

FromGerhard Bunzel <g.bunzel@domonet.de>
Date2018-10-23 16:47 +0200
Message-ID<pqncac$vuj$1@news-1.m-online.net>
In reply to#12078
Hi Karl-Heinz,

thanks for your answer.

In VB a Handle is a LONG - so I used it the same way. A PTR is also only a numeric value.
http://codingdomain.com/visualbasic/win32api/datatypes/

A C-Wrapper for VPE from Wolfgang Riedmann is also using LONG for the handle - and it's working perfect.

The VB-Sample is working and shows the items values.
This is from that sample:
Private Record(1 To 1000) As Rec
Private myconnectionhandle(100), mygrouphandle(100), myitemhandle(1000) As Long
Private mytimestamp As Date
Private myitemdata As Variant
Private myrate, myquality As Long

Private Type Rec
      Key As String
      ConnectionHandle As Long
      GroupHandle As Long
      TagHandle As Long
      Description As String
      Kind As String
      Units As String
      ArrayNumber As Integer
      Room As Integer
      Value As Variant
      FieldName As String
End Type

And here reading of an item:
tf = ReadOPCItem(ByVal Record(i).ConnectionHandle, ByVal Record(i).GroupHandle, ByVal Record(i).TagHandle, Record(i).Value, mytimestamp, myquality)


Out of the file opcda.h from a C-Sample:
typedef DWORD OPCHANDLE;

The data type LONG for the handles schound not b the problem. All other functions without VARIANT and FILETIME are working.
I can read the server- and the itemnames, connect to the server, create a group, add an item to the group, disconnect from server.
But I can't read a itemvalue :-(


Thanks in advance.

Best regards

Gerhard



Am 22.10.2018 um 21:20 schrieb Karl-Heinz:
> Hi Gerhard,
> 
>> ReadOPCItem(myserverhandle, mygrouphandle, myItemhandle, ptrVariant,
>> ptrFileTime, @nQuality)
>> gives back a TRUE. GetLastError() is 0 - no Error.
> 
> strange ....
> 
> 
>> This is the C-function:
>> BOOL ReadOPCItem (HANDLE hConnect, HANDLE hGroup, HANDLE hItem, VARIANT
>> *pVar, FILETIME *pTimeStamp, DWORD *pQuality);
> 
> 
> _DLL FUNCTION ReadOPCItem (nConnect AS LONG, pGroupConnect AS LONG,
> pItemConnect AS LONG, pVariant AS _winVARIANT, pFileTime AS _winFILETIME,
> pQuality REF DWORD) AS LOGIC PASCAL:WTclient._ReadOPCItem@24
> 
> Why "AS LONG" ?  IMO nConnect, pGroupConnect and pItemConnect should be
> declared "AS PTR" and not "AS LONG" ?
> 
> Have you tried to run the VB sample exe files that are included in
> WTclient.zip - just to see that ReadOPCItem() works at least with VB ?
> 
> 
> Isn´t there any C sample that shows how ReadOPCItem()  is called ?
> 
> 
> regards
> Karl -Heinz

[toc] | [prev] | [next] | [standalone]


#12081

From"Karl-Heinz" <invalid@invalid.invalid>
Date2018-10-23 18:20 +0200
Message-ID<g3906iFim07U1@mid.individual.net>
In reply to#12080
Hi  Gerhard,

puuh, i´m running out of ideas...

In the VO28RUN.dll there are two more "Variant" funcs. After reading your
msgs again, it seems you didn´t try the Usual2Variant() till now ?

_DLL FUNCTION Usual2Variant    (pItem AS PTR, pvarg AS PTR)           AS
LOGIC PASCAL:VO28RUN.Usual2Variant
_DLL FUNCTION Variant2Usual    (pvarg AS PTR, pItem AS PTR)           AS
LOGIC PASCAL:VO28RUN.Variant2Usual

i´ve searched the SDK prg sources but both funcs are never used. So the
param usage is not clear.

i think the best would be to contact the vendor for a C sample that shows
the OPCReaditem() usage.

Good luck !

regards
Karl-Heinz




"Gerhard Bunzel"  schrieb im Newsbeitrag
news:pqncac$vuj$1@news-1.m-online.net...

Hi Karl-Heinz,

thanks for your answer.

In VB a Handle is a LONG - so I used it the same way. A PTR is also only a
numeric value.
http://codingdomain.com/visualbasic/win32api/datatypes/

A C-Wrapper for VPE from Wolfgang Riedmann is also using LONG for the
handle - and it's working perfect.

The VB-Sample is working and shows the items values.
This is from that sample:
Private Record(1 To 1000) As Rec
Private myconnectionhandle(100), mygrouphandle(100), myitemhandle(1000) As
Long
Private mytimestamp As Date
Private myitemdata As Variant
Private myrate, myquality As Long

Private Type Rec
      Key As String
      ConnectionHandle As Long
      GroupHandle As Long
      TagHandle As Long
      Description As String
      Kind As String
      Units As String
      ArrayNumber As Integer
      Room As Integer
      Value As Variant
      FieldName As String
End Type

And here reading of an item:
tf = ReadOPCItem(ByVal Record(i).ConnectionHandle, ByVal
Record(i).GroupHandle, ByVal Record(i).TagHandle, Record(i).Value,
mytimestamp, myquality)


Out of the file opcda.h from a C-Sample:
typedef DWORD OPCHANDLE;

The data type LONG for the handles schound not b the problem. All other
functions without VARIANT and FILETIME are working.
I can read the server- and the itemnames, connect to the server, create a
group, add an item to the group, disconnect from server.
But I can't read a itemvalue :-(


Thanks in advance.

Best regards

Gerhard



Am 22.10.2018 um 21:20 schrieb Karl-Heinz:
> Hi Gerhard,
>
>> ReadOPCItem(myserverhandle, mygrouphandle, myItemhandle, ptrVariant,
>> ptrFileTime, @nQuality)
>> gives back a TRUE. GetLastError() is 0 - no Error.
>
> strange ....
>
>
>> This is the C-function:
>> BOOL ReadOPCItem (HANDLE hConnect, HANDLE hGroup, HANDLE hItem, VARIANT
>> *pVar, FILETIME *pTimeStamp, DWORD *pQuality);
>
>
> _DLL FUNCTION ReadOPCItem (nConnect AS LONG, pGroupConnect AS LONG,
> pItemConnect AS LONG, pVariant AS _winVARIANT, pFileTime AS _winFILETIME,
> pQuality REF DWORD) AS LOGIC PASCAL:WTclient._ReadOPCItem@24
>
> Why "AS LONG" ?  IMO nConnect, pGroupConnect and pItemConnect should be
> declared "AS PTR" and not "AS LONG" ?
>
> Have you tried to run the VB sample exe files that are included in
> WTclient.zip - just to see that ReadOPCItem() works at least with VB ?
>
>
> Isn´t there any C sample that shows how ReadOPCItem()  is called ?
>
>
> regards
> Karl -Heinz 

[toc] | [prev] | [next] | [standalone]


#12082

From"Karl-Heinz" <invalid@invalid.invalid>
Date2018-10-23 21:07 +0200
Message-ID<g399t3Fkn9oU1@mid.individual.net>
In reply to#12081
Hi Gerhard,

I´ve just tried the Usual2Variant (). The result is what I expected. The
function initializes the _winvariant structure  - but that does not solve
the ReadOPCItem() Problem.


local d as usual
local x is _winvariant

   d := 1200067.56

  IF Usual2Variant( @d  , @x )

    MsgInfo ( AsString ( x.vt ) + CRLF + AsString ( x.uVariant.dblVal) )

       //   x.vt     contains  VT_R8
       //   x.uVariant.dblVal     contains  1200067.56

  ENDIF


regards
Karl-Heinz 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web