jaberwacky Posted October 3, 2010 Share Posted October 3, 2010 (edited) Here's a function for loading a GUID string into a _GUID struct. Currently only accepts GUID strings formatted like this: 6B29FC40-CA47-1067-B31D-00DD010662DA. Hope it's usefull. expandcollapse popupCreateGUIDStruct("D16A55E8-1059-11D2-8FFD-00A0C9A06D32") ConsoleWrite("@ERROR: " & @error & @LF) CreateGUIDStruct("D16A55E8-1059-11D2-8FFD-00A0C9A06D325") ConsoleWrite("@ERROR: " & @error & @LF) CreateGUIDStruct('') ConsoleWrite("@ERROR: " & @error & @LF) CreateGUIDStruct(' ') ConsoleWrite("@ERROR: " & @error & @LF) ; = Function ========================================================================================================== ; Name .....: CreateGUIDStruct ; Syntax ...: CreateGUIDStruct($GUIDstr) ; Param(s) .: $GUIDstr -- String containing a GUID. Cannot be longer or shorter than 36 characters. ; Success ..: A _GUID struct containing the GUID string. ; Fail .....: 1 & @error: -1: String was formatted incorrectly. ; Desc. ....: http://msdn.microsoft.com/en-us/library/aa373931%28VS.85%29.aspx Func CreateGUIDStruct(Const $GUIDstr) Switch (IsString($GUIDstr)) And ($GUIDstr <> '') And ($GUIDstr <> ' ') And (StringLen($GUIDstr) = 36) Case 1 Local Const $tmpGUIDstr = StringStripWS($GUIDstr, 8) Local Const $GUIDArr = StringSplit($tmpGUIDstr, '-', 2) Local Const $dllGUID = DllStructCreate("dword Data1; word Data2; word Data3; byte Data4[8]") If StringLen($GUIDArr[0]) = 8 Then DllStructSetData($dllGUID, "Data1", $GUIDArr[0]) Else Return SetError(-1, 0, 1) EndIf If StringLen($GUIDArr[1]) = 4 Then DllStructSetData($dllGUID, "Data2", $GUIDArr[1]) Else Return SetError(-1, 0, 1) EndIf If StringLen($GUIDArr[2]) = 4 Then DllStructSetData($dllGUID, "Data3", $GUIDArr[2]) Else Return SetError(-1, 0, 1) EndIf If StringLen($GUIDArr[3]) = 4 Then DllStructSetData($dllGUID, "Data4", StringLeft($GUIDArr[3], 2), 1) DllStructSetData($dllGUID, "Data4", StringRight($GUIDArr[3], 2), 2) Else Return SetError(-1, 0, 1) EndIf If StringLen($GUIDArr[4]) = 12 Then DllStructSetData($dllGUID, "Data4", StringLeft($GUIDArr[4], 2), 3) DllStructSetData($dllGUID, "Data4", StringTrimLeft(StringTrimRight($GUIDArr[4], 2), 8), 4) DllStructSetData($dllGUID, "Data4", StringTrimLeft(StringTrimRight($GUIDArr[4], 4), 6), 5) DllStructSetData($dllGUID, "Data4", StringTrimLeft(StringTrimRight($GUIDArr[4], 6), 4), 6) DllStructSetData($dllGUID, "Data4", StringTrimLeft(StringTrimRight($GUIDArr[4], 8), 2), 7) DllStructSetData($dllGUID, "Data4", StringRight($GUIDArr[4], 2), 8) Else Return SetError(-1, 0, 1) EndIf Return $dllGUID Case 0 Return SetError(-1, 0, 1) EndSwitch EndFunc ;==>CreateGUIDStruct Edited October 3, 2010 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
ProgAndy Posted October 3, 2010 Share Posted October 3, 2010 not bad, but what about _WinAPI_GUIDFromString ? *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
jaberwacky Posted October 3, 2010 Author Share Posted October 3, 2010 not bad, but what about _WinAPI_GUIDFromString ?Oh gosh, you know what, I saw that but I have no idea what's meant by binary form. So _WinAPI_GUIDFromString() does the same thing as my function? Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
ProgAndy Posted October 3, 2010 Share Posted October 3, 2010 (edited) Oh gosh, you know what, I saw that but I have no idea what's meant by binary form. So _WinAPI_GUIDFromString() does the same thing as my function? Yes, but I did create a custom function for objbase (sort of predecessor of AutoItObject), too (in the meantime it has been replaced ) #include<WinAPI.au3> $tGUID = _WinAPI_GUIDFromString("{6B29FC40-CA47-1067-B31D-00DD010662DA}") MsgBox(0, 'Result: $tagGUID', _ StringFormat("%04X-%02X-%02X-%s", _ DllStructGetData($tGUID, 1), _ DllStructGetData($tGUID, 2), _ DllStructGetData($tGUID, 3), _ Hex(DllStructGetData($tGUID, 4)) _ ) _ ) Edited October 3, 2010 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
trancexx Posted October 3, 2010 Share Posted October 3, 2010 No, this is bad. jaberwocky6669 what are you returning from the function? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
jaberwacky Posted October 3, 2010 Author Share Posted October 3, 2010 No, this is bad. jaberwocky6669 what are you returning from the function?A ptr to the struct? Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
jaberwacky Posted October 3, 2010 Author Share Posted October 3, 2010 (edited) #include <WinAPI.au3> $tGUID = _WinAPI_GUIDFromString("{6B29FC40-CA47-1067-B31D-00DD010662DA}") MsgBox(0, 'Result: $tagGUID', _ StringFormat("%04X-%02X-%02X-%s", _ DllStructGetData($tGUID, 1), _ DllStructGetData($tGUID, 2), _ DllStructGetData($tGUID, 3), _ Hex(DllStructGetData($tGUID, 4)) _ ) _ ) OK, I see. I'll pack my bags and be out by this afternoon. Trancexx, why is it bad to return a ptr to a struct from a function? Edited October 3, 2010 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
ProgAndy Posted October 3, 2010 Share Posted October 3, 2010 (edited) This creates a string from data taken from a struct right?Right. PS: Your function won't work. You return the pointer to the struct, but the struct is a local variable, so it will be released when he funciton returns. You have to return the whole struct. Edited October 3, 2010 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
jaberwacky Posted October 3, 2010 Author Share Posted October 3, 2010 (edited) Right. PS: Your function won't work. You return the pointer to the struct, but the struct is a local variable, so it will be released when he funciton returns. You have to return the whole struct. But if the struct is still destroyed when the function returns it doesn't matter either way. Unless I am returning a copy of the struct? Ha, I'm beginning to think that I should have posted this in the help section! So all of my code boils down to this: Func _WinAPI_GUIDFromString($sGUID) Local $tagGUID = "dword Data1; word Data2; word Data3; byte Data4[8]" Local $tGUID = DllStructCreate($tagGUID) Local $pGUID = DllStructGetPtr($tGUID) DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "ptr", $pGUID) If @error Then Return SetError(@error, @extended, 0) Return $tGUID EndFunc ;==>_WinAPI_GUIDFromString Edited October 3, 2010 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? 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