Solved TD-23246: 32 bit TD gets negative number from external function returning HANDLE

Post found bugs and possible workarounds.
Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 275
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

TD-23246: 32 bit TD gets negative number from external function returning HANDLE

Post by Dave Rabelink » 10 Mar 2017, 08:00

Just to inform about an internal change to TD 7.0 (x86 and x64) concerning the HANDLE external datatype.

Using this datatype, it could be that API functions return negative numbers where in earlier TD versions they are always positive numbers.

Example:

Declaration

Code: Select all

Function: CreateDCA
   Description:
   Export Ordinal: 0
   Returns
      Number: HANDLE
   Parameters
      ...

TD code

Code: Select all

Set nScreenDC = CreateDCA( 'DISPLAY', STRING_Null, STRING_Null, STRING_Null)
If nScreenDC > 0
     ! Perform actions
Else
     ! Error

The code above assumes that the API function returns only positive numbers when succeeded.
But TD 7.0 may also return negative numbers. In this case the code above will fail.

I have seen some code actually checking the HANDLE values on several API functions like this.
Most API functions will return NULL or 0 when failing. So the TD code was not implemented correctly according to the API description.

So beware of this internal change in TD70 and make sure (old) code is using the correct checks on the values.

See sample.
Run it in TD 6.3 or other lower TD version and run it in TD 7.0.
Press the Execute button multiple times to see that in TD 7.0 the value could be negative.
This was not the case in earlier TD versions.

PS
Using LPVOID in the API declaration (instead of HANDLE) will return positive numbers always, which will keep the old code working.
But I recommend to change the code and keep using HANDLE. Always try to have the exact same datatype declaration as described for the API function).

CreateDC_Sample.zip
You do not have the required permissions to view the files attached to this post.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 275
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: TD-23246: 32 bit TD gets negative number from external function returning HANDLE

Post by Dave Rabelink » 10 Mar 2017, 08:01

Mike Vandine OpenText support wrote:Hi,

The defect that you've reported in this ticket has been fixed with the TD 7.0 Update 1 release.

OTCS Ticket 2865962 : TD-23246: x64 : WinApi HANDLE vs LPVOID

You can pick up this release from the OpenText Knowledge Center:

https://knowledge.opentext.com/knowledg ... n/62156116

You will find the release notes in the same location.

I will be closing this ticket. If you find that you still have a problem after installing this release, a new ticket can be opened.

Regards,

Mike Vandine
OpenText Support Team
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Return to “Bug Reports”

Who is online

Users browsing this forum: Ccbot [Crawler] and 0 guests