Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Calling Windows API

From: rotenca::telvia::it at: 13-Dec-2004 20:12

Patrick Philipot wrote:
>RPT> st: make struct! [ >RPT> VolumeNameBuffer [string!] >RPT> FileSystemNameBuffer [string!] >RPT> ] reduce [VNB: make string! 100 FSNB: make string! 100] >RPT> GetVolumeInfo "C:\" VNB 20 0 0 0 FSNB 20 > >Thanks Romano > >Very strange indeed. And I don't get why it's working. It seems that >Rebol is doing a lot of things behind my back. >
The fact is that a string! in a struct! is used by rebol like a C string (0 terminated). So st/FileSystemNameBuffer return a rebol string which ends at the first 0. But the problem is that you cannot pass st/FileSystemNameBuffer to GetVolumeInfo because st/FileSystemNameBuffer is indeed a Rebol string! copy of the C string in the struct. So I use this workaround: reduce [VNB: make string! 100 FSNB: make string! 100] where I get in FNSB a pointer to the C string and then pass that pointer to GetVolumeInfo: GetVolumeInfo "C:\" VNB 20 0 0 0 FSNB 20 You must think that st/FileSystemNameBuffer is a pointer to the same memory area pointed by FNSB, the difference is that when Rebol uses the first, it makes a copy of that memory only until the first 0; when Rebol uses the second, it reads it until the string! length (which is 0 until you insert something in it, so it is always "" in our example). So: probe st/FileSystemNameBuffer ; "NTFS" probe FSNB ; "" also if they share the same memory storage area. -- Ciao Romano Paolo Tenca