fbpx
Welcome, Guest
Username: Password: Remember me
Visual Objects

Please use this forum to post questions about Visual Objects and Vulcan.NET
  • Page:
  • 1

TOPIC: DWORD(@ptrVal) VS DWORD(_CAST, ptrVal)

DWORD(@ptrVal) VS DWORD(_CAST, ptrVal) 1 month 23 hours ago #12888

  Jamal's Avatar Topic Author Jamal Offline Posts: 195
I had an access violation resulting from using DWORD(ptrVal) because I did not cast the ptrVal to DWORD using _CAST.
While the CLVO group I saw using the address of ptrVal like DWORD(@ptrVal) which also works. So, is it the same as DWORD(_CAST, ptrVal) ?
My quick test below shows the same result. Is one better than the other?
function start()
LOCAL y as ptr	
			
		y := 0x00000004     
		
		? "y: ", y 
		
		? "dword(@y)", dword(@y)
		? "dword(_cast, y)", dword(_cast, y)   
		
		wait  		
		
return nil

Please Log in or Create an account to join the conversation.

DWORD(@ptrVal) VS DWORD(_CAST, ptrVal) 1 month 22 hours ago #12889

  robert's Avatar robert Offline Posts: 1499
Jamal,
? DWORD(ptrVal)
is using the ptrVal and tells the compiler that it is a pointer to a location where a dword is stored. That would be the same as
LOCAL pDword AS DWORD PTR
pDword:= y
? pDword[1]
Of course this will crash when y has the value 0x00000004 , because that is usually an invalid memory location.
All the other examples will simply take the 32 bits from the PTR and will tell the compiler to use them as a DWORD.

I am not sure where you need this, but this kind of casting is considered "dangerous" and will only work in a 32 bit environment because the size of a PTR is the same as the size of a DWORD. In a 64 bits environment (if you would compile this in X# with AnyCPU) this will not be allowed.

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

DWORD(@ptrVal) VS DWORD(_CAST, ptrVal) 1 month 21 hours ago #12892

  Jamal's Avatar Topic Author Jamal Offline Posts: 195
Robert,

For this I am strictly using VO and I am checking the success or failure of the win32 function ShellExecute() which returns a PTR result.

Of course, I would not use ShellExecute() function with X# or other .NET languages since there are better functions.

Thanks for the info.

Jamal

Please Log in or Create an account to join the conversation.

  • Page:
  • 1