mike1950r Posted June 8, 2023 Share Posted June 8, 2023 Hello, I'm using an object in different functions. The object is created with: $objVideo = ObjCreate("wmplayer.ocx") Now I want to use this object in another function and tried: $objVideo = ObjGet("wmplayer.ocx") But this is not working. How can I use the same object in different function without giving the object variable as parameter in function name such as: Func NextFunction($objVideo) Thanks for assistance. Cheers mike Link to comment Share on other sites More sharing options...
Danp2 Posted June 8, 2023 Share Posted June 8, 2023 I think you've got the syntax wrong. Try this -- $objVideo = ObjGet("", "wmplayer.ocx") Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
KaFu Posted June 8, 2023 Share Posted June 8, 2023 Define $objVideo as Global at the beginning of your script. Global $objVideo = ObjCreate("wmplayer.ocx") ; Outside of functions OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
mike1950r Posted June 8, 2023 Author Share Posted June 8, 2023 2 hours ago, Danp2 said: I think you've got the syntax wrong. Try this -- $objVideo = ObjGet("", "wmplayer.ocx") Thanks Danp2. This would have been my prefered solution, but unfortunately it does not work. Cheers mike Link to comment Share on other sites More sharing options...
mike1950r Posted June 8, 2023 Author Share Posted June 8, 2023 1 hour ago, KaFu said: Define $objVideo as Global at the beginning of your script. Global $objVideo = ObjCreate("wmplayer.ocx") ; Outside of functions Thanks Kafu, this works. Although I do not like very much to work with Global variables, cause my functions are in libraries. Cheers mike Link to comment Share on other sites More sharing options...
KaFu Posted June 8, 2023 Share Posted June 8, 2023 If it's an "include" library you can also define the Global variable at the top of the include file itself. GDIPlus.au3 does something similar with $__g_hGDIPDll. Aalso you could test the variable with isobj() at the beginning of the single functions, and throw an error when false. mike1950r 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Solution mike1950r Posted June 8, 2023 Author Solution Share Posted June 8, 2023 Thanks KaFu, my fear was, that this is double declared, when the library is loaded. I found a solution for me putting this on top of the library: If Not IsDeclared("objGlo_Video") Then Global $objGlo_Video EndIf object verification works fine now. Thanks mike 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