scila1996 Posted November 5, 2015 Posted November 5, 2015 i Have a C Codeunion { int a; byte b; } test_union; int main { test_union _var; _var.a = 256; _var.b = 2; }=> Result of _var.a => 258I'm try with DllStructCreate with this wayLocal $_union = DllStructCreate("byte[4]") Local $_test_union = DllStructCreate("int a;int b", DllStructGetPtr($_union)) DllStructSetData($_test_union, 1, 256) DllStructSetData($_test_union, 2, 2) MsgBox(64, "", DllStructGetData($_test_union, "a"))=> result is : 256 ? How do i create a union with data organize like C ? Please help me ! Thank you for reply
jchd Posted November 5, 2015 Posted November 5, 2015 You're playing with firearms here: $_test_union is twice as large as $_union.Anyway, this is the counterpart of your C example:Local $_union = DllStructCreate("byte[4]") Local $_test_union = DllStructCreate("int a", DllStructGetPtr($_union)) DllStructSetData($_test_union, 1, 256) DllStructSetData($_union, 1, 2, 1) MsgBox(64, "", DllStructGetData($_test_union, "a")) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
scila1996 Posted November 6, 2015 Author Posted November 6, 2015 You're playing with firearms here: $_test_union is twice as large as $_union.Anyway, this is the counterpart of your C example:Local $_union = DllStructCreate("byte[4]") Local $_test_union = DllStructCreate("int a", DllStructGetPtr($_union)) DllStructSetData($_test_union, 1, 256) DllStructSetData($_union, 1, 2, 1) MsgBox(64, "", DllStructGetData($_test_union, "a")) How to get data of int b ?
scila1996 Posted November 6, 2015 Author Posted November 6, 2015 (edited) How to i create union with element is struct ? Exampletypedef union _ULARGE_INTEGER { struct { DWORD LowPart; DWORD HighPart; }; struct { DWORD LowPart; DWORD HighPart; } u; ULONGLONG QuadPart; } ULARGE_INTEGER, *PULARGE_INTEGER; Edited November 6, 2015 by scila1996
jchd Posted November 6, 2015 Posted November 6, 2015 The struct u is pointless.Simply like this:Local $_union = DllStructCreate("long[2]") Local $_test_union = DllStructCreate("int64 a", DllStructGetPtr($_union)) DllStructSetData($_union, 1, 0x12345678, 1) DllStructSetData($_union, 1, 0x99999999, 2) MsgBox(64, "", Hex(DllStructGetData($_union, 1, 1), 8)) MsgBox(64, "", Hex(DllStructGetData($_union, 1, 2), 8)) MsgBox(64, "", Hex(DllStructGetData($_test_union, "a"), 16)) MsgBox(64, "", DllStructGetData($_test_union, "a")) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
JohnOne Posted November 6, 2015 Posted November 6, 2015 How to get data of int b ?I'm not 100% on this, but quite sure that you are missing the point of union.I believe it's that it will be one variable stored in it, either the byte or the int, not both.So because it can be an int, and an int is larger than byte, it has to at least the size of int.Don't take that as definite, I've been known to be wrong. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
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