brunomusw Posted July 17, 2009 Share Posted July 17, 2009 I´m using a DLL and Autoit Library (I create the library, BB) that acess this DLL and on my program a receive a signed variable from the BB library, but sometimes I want use this value as signed or unsigned, how I declare a unsigned variable on Autoit? Regards, Brunomusw Link to comment Share on other sites More sharing options...
BrettF Posted July 18, 2009 Share Posted July 18, 2009 Maybe you should start reading...Cheers,Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
brunomusw Posted July 20, 2009 Author Share Posted July 20, 2009 (edited) Thanks Brett, I´ve read this already and it not help. Let´s example this. I have a return value from a function, that´s a signed char, but sometimes I need to interpret it as unsigned char. Reading "Language Reference" there is no way to do it. Regards, Brunomusw Edited July 20, 2009 by brunomusw Link to comment Share on other sites More sharing options...
Ascend4nt Posted July 20, 2009 Share Posted July 20, 2009 (edited) Look into the Abs() function and using the - symbol to switch to signed (or reverse the sign) $iVal=Abs($iVal) ; Remove any sign $iVal= -$iVal ; Make negative or positive (depending on initial value) $iVal *= -1 ; also does the trick.. One thing you need to know - Anything with the 63rd bit set will become negative. Also, anything coming out of a Bit*() operation with the 31st bit set, or returns from DLLCall()'s with *signed* values will be sign-extended. *edit: I should note that, when I talk about the 'nth bit set, I'm talking from a base index of 0, so the 63rd bit is really the top bit of a 64-bit #. Edited July 20, 2009 by Ascend4nt My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
brunomusw Posted July 21, 2009 Author Share Posted July 21, 2009 Thanks guys... But I the way that I see is by calculus. Once the computer uses 2´s complements and I´m receving a byte, when I want that it be an unsigned I will need to + 256. func() returns -100. Reading it as unsigned it will be = -100 + 256 = 156. Regards, Brunomusw Link to comment Share on other sites More sharing options...
Ascend4nt Posted July 22, 2009 Share Posted July 22, 2009 (edited) You're not making a whole lotta sense because you aren't providing any code demonstrating how you are getting the data or interpreting it. A DLLCall allows unsigned values to be returned you know, like 'ubyte'.. However, just for kicks - if you are talking about simply converting a negative 1-byte value to its binary positive equivalent (not its positive absolute value), you can do this: $iChar=-5 $uChar=Number(BinaryMid($iChar,1,1)) MsgBox(0,"Transforming the sign bit","Original value:"&$iChar&@CRLF&"Value reconsidered without a sign bit:"&$uChar&@CRLF) Note that the above ASSUMES you are using just one character (signed value maximum range: -128 to 127). To do words, dwords, or qwords you'll need a different approach.. Edited July 22, 2009 by Ascend4nt My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
brunomusw Posted July 22, 2009 Author Share Posted July 22, 2009 You're not making a whole lotta sense because you aren't providing any code demonstrating how you are getting the data or interpreting it. A DLLCall allows unsigned values to be returned you know, like 'ubyte'.. However, just for kicks - if you are talking about simply converting a negative 1-byte value to its binary positive equivalent (not its positive absolute value), you can do this: $iChar=-5 $uChar=Number(BinaryMid($iChar,1,1)) MsgBox(0,"Transforming the sign bit","Original value:"&$iChar&@CRLF&"Value reconsidered without a sign bit:"&$uChar&@CRLF) Note that the above ASSUMES you are using just one character (signed value maximum range: -128 to 127). To do words, dwords, or qwords you'll need a different approach.. That's what I mean, your code is another solution, but the on the sameway that doing calculus it's a trick. Actually We did it on the DLL, and just to add we found some bug over there. If $sign = 0 Then ;unsigned $ret = DllCall($dll, "byte", "ReadByteComP") ElseIf $sign = 1 Then ;signed $ret = DllCall($dll, "int", "ReadByteComP") EndIf Using the ubyte and byte both are giving unsigned byte. How to report it? Regards, Brunomusw Link to comment Share on other sites More sharing options...
Ascend4nt Posted July 22, 2009 Share Posted July 22, 2009 Hmm, your code doesn't make sense. Why are you calling the same function returning a byte and an integer? And I don't see any 'ubyte' or 'uint' return types there. Still, now you're telling me that its always returning an unsigned value?? I thought the original problem was that it was giving you a signed value that you wanted to convert to unsigned. If you have access to the DLL code - look closely at how the value is being returned. If it's a byte that's being returned, the DLL code should either sign-extend or zero-extend that value to 32-bits (or 64 in x64 mode) if you're trying to grab it as an int. Otherwise, 'byte' should return signed when the upper bit is set (a value >127 positive will set the upper bit, and of course if it's treated as a signed value, any negative # will have that upper bit set). For a quick example (this isn't a DLLCall, but it shows what 'byte' returns when set with a value with the upper bit set): $stStruct=DllStructCreate("byte") DllStructSetData($stStruct,1,129) MsgBox(0,"DLLStruct test","Value 129 read back from DLL Structure:"&DllStructGetData($stStruct,1)) I think you need to further explore this before reporting it as a bug. To report it, it should be something the AutoIT developers can replicate themselves. If you have a special DLL that isn't standard then you won't be likely to get support unless you also provide the DLL code (at least the relevant parts). If you still think you have a legitimate bug, and can have it replicated by the AutoIT developers, then by all means click on 'Bug Reports and Feature Requests' on the main Forum Index. (be sure to read the notes there 1st) My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
martin Posted July 22, 2009 Share Posted July 22, 2009 Thanks guys... But I the way that I see is by calculus.Once the computer uses 2´s complements and I´m receving a byte, when I want that it be an unsigned I will need to + 256.func() returns -100.Reading it as unsigned it will be = -100 + 256 = 156.Regards,BrunomuswI think you need to create 2 structs in the same area of memory, or a union. $stB = dllstructcreate("byte")$stU = dllstructcreate("ubyte",dllstructgetptr($stB)When you get the return byte from your dll save it in $StB. DllStructSetDat($stB,1,$result)If you want to read it as an unsigned byte read it from $stU. DllStructGetData($stU,1) Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
brunomusw Posted July 23, 2009 Author Share Posted July 23, 2009 I think you need to create 2 structs in the same area of memory, or a union. $stB = dllstructcreate("byte")$stU = dllstructcreate("ubyte",dllstructgetptr($stB)When you get the return byte from your dll save it in $StB. DllStructSetDat($stB,1,$result)If you want to read it as an unsigned byte read it from $stU. DllStructGetData($stU,1)Thanks Martin, it´s worked.But, why using the DllCall didn´t work?Regards,Brunomusw Link to comment Share on other sites More sharing options...
trancexx Posted July 23, 2009 Share Posted July 23, 2009 Thanks Martin, it´s worked.But, why using the DllCall didn´t work?Regards,BrunomuswDid you read Ascend4nt's post? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
brunomusw Posted July 24, 2009 Author Share Posted July 24, 2009 Sorry Ascend4nt's, that's what I was looking for, is like the Martin's code. Create an Struct for signed and unsigned to receive the values from the DLL. But why the DLLCall didn't work? $ret = DllCall($dll, "byte", "ReadByteComP") $ret = DllCall($dll, "ubyte", "ReadByteComP") Regards, Brunomusw Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now