AnsweredAssumed Answered

PI API pisn_getsnapshotx() return no value

Question asked by wentang on Feb 7, 2018
Latest reply on Apr 16, 2019 by wentang

I have an old VB 6 exe program and needs to be upgraded to VS 2008 VB exe program. My program uses PI API function



        piErr=pisn_getsnapshotx(PiPtNum, TagValue, iVal, sString, bSize, iStat, Flags, PiTimeS)

to get PI snapshot value.  When I called this function it will return piErr=-15010.  According to OSI website  //  "if the function returns –15010  indicating truncation of the data in bval, the bval buffer is filled with as much of the requested data as possible (bsize bytes). Also, bsize is set to the required buffer size."  I can see the return bsize is 4 or 6 (depend on the current string PI tag value) but the return sString is always blank.  (Note: On my old VB 6 program I can call pisn_getsnapshotx() twice and the 2nd call will give me the correct data, but for VS 2008 it will prompt a message of "An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll" on the 2nd call).


No problem for float32 PI tags for floating point value, only the string type PI tags.


My PIAPI32.vb declare function is:


Function pisn_getsnapshotx Lib "piapi32.dll" (ByVal PtNum As Integer, ByRef drVal As Double, _


          ByRef iVal As Integer, ByRef bVal As String, ByRef bSize As Integer, ByRef iStat As Integer, _


          ByRef Flags As Short, ByRef time0 As PiTimeStamp) As Integer


OSI original function:


'Declare Function pisn_getsnapshotx Lib "piapi32.dll" (ByVal PtNum&, ByVal drVal As Any, ByVal iVal&, _

'           ByVal bVal As Any, ByVal bSize&, ByVal iStat&, ByVal Flags%, _

'           ByVal time0 As PiTimeStamp) As Long



Note: VS 2008 it doesn't support data type of "Any".

Can someone help me in this matter?  Thanks.