GetFunction fails...but just in this code

Just starting out? Need help? Post your questions and find answers here.
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

GetFunction fails...but just in this code

Post by jacdelad »

I have a modified code of the TaskDialog-Code which worked fine until now. Now it doesn't work anymore, so I thought this would be a bug in 6.01 Beta 4, but the code from the forum still works. My code fails at line 77, when GetFunction is called (it returns 0). Can anybody tell my why?

Code: Select all

CompilerIf #PB_Compiler_IsMainFile
  EnableExplicit
CompilerEndIf

#TD_WARNING_ICON = -1
#TD_ERROR_ICON = -2
#TD_INFORMATION_ICON = -3
#TD_SHIELD_ICON = -4

#TDF_USE_COMMAND_LINKS           = $10   ;Commandlinks statt normale Buttons verwenden
#TDF_ENABLE_HYPERLINKS           = $1    ;Links automatisch anzeigen
#TDF_USE_HICON_MAIN              = $2    ;Eigenes Icon verwenden
#TDF_USE_HICON_FOOTER            = $4    ;Icon in den Footer verschieben (?)
#TDF_EXPAND_FOOTER_AREA          = $40   ;Erweiterter Text wird im Footer angezeigt
#TDF_EXPANDED_BY_DEFAULT         = $80
#TDF_VERIFICATION_FLAG_CHECKED   = $100
#TDF_SHOW_PROGRESS_BAR           = $200
#TDF_SHOW_MARQUEE_PROGRESS_BAR   = $400
#TDF_CALLBACK_TIMER              = $800  ;Callback-Funktion etwa alle 200ms aufrufen
#TDF_POSITION_RELATIVE_TO_WINDOW = $1000 ;Position relativ zu ParenthWnd
#TDF_NO_DEFAULT_RADIO_BUTTON     = $4000
#TDF_CAN_BE_MINIMIZED            = $8000

#TD_ICON_NONE                   = 0
#TD_ICON_SHIELD_COLORED_GREY    = 65527
#TD_ICON_SHIELD_OK_COLORED      = 65528
#TD_ICON_SHIELD_ERROR_COLORED   = 65529
#TD_ICON_SHIELD_WARNING_COLORED = 65530
#TD_ICON_SHIELD_COLORED         = 65531
#TD_ICON_SHIELD                 = 65532
#TD_ICON_SHIELD_QUESTION        = 65533
#TD_ICON_ERROR                  = 65534
#TD_ICON_QUESTION               = 65535

Structure TASKDIALOGCONFIG
  cbSize.l
  hwndParent.i
  hInstance.i
  dwFlags.l
  dwCommonButtons.l
  *pszWindowTitle
  StructureUnion
    hMainIcon.i
    *pszMainIcon
  EndStructureUnion
  *pszMainInstruction
  *pszContent
  cButtons.l
  *pButtons.TASKDIALOG_BUTTON
  nDefaultButton.l
  cRadioButtons.l
  *pRadioButtons.TASKDIALOG_BUTTON
  nDefaultRadioButton.l
  *pszVerificationText
  *pszExpandedInformation
  *pszExpandedControlText
  *pszCollapsedControlText
  StructureUnion
    hFooterIcon.i
    *pszFooterIcon
  EndStructureUnion
  *pszFooter
  *pfCallback
  *lpCallbackData
  cxWidth.l
EndStructure
Structure TASKDIALOG_BUTTON
  nButtonID.l
  *pszButtonText
EndStructure

Global fVerifyx, SelRadiox

Procedure Task_DialogIndirect(tdlgx)
  Protected ClickedButtonx,Libef=OpenLibrary(#PB_Any,"comctl32.dll"),*Task_Dialog_Func
  If Libef
    *Task_Dialog_Func = GetFunction(Libef, "TaskDialogIndirect")
    Debug *Task_Dialog_Func
    If *Task_Dialog_Func
      CallFunctionFast(*Task_Dialog_Func, tdlgx, @ClickedButtonx, @SelRadiox, @fVerifyx)
    EndIf
  EndIf
  CloseLibrary(Libef)
  If ClickedButtonx<1000
    ProcedureReturn 0
  Else
    ProcedureReturn ClickedButtonx-1000
  EndIf
EndProcedure

Global Dim TD_Buttons.TASKDIALOG_BUTTON(8)
Define tdcount
For tdcount=0 To ArraySize(TD_Buttons())
  TD_Buttons(tdcount)\nButtonID=tdcount+1001
Next
Global Dim TD_RADIOButtons.TASKDIALOG_BUTTON(8)
For tdcount=0 To ArraySize(TD_RADIOButtons())
  TD_RADIOButtons(tdcount)\nButtonID=tdcount+1001
Next

Procedure TaskDialog(title.s,flags,icon,headline.s,text.s,bCount,defbutton,rcount,defradio,checkbox.s,expando.s,expand.s,collapse.s,footericon,footer.s,Parent=0)
  Protected tdlg.TASKDIALOGCONFIG
  tdlg\cbSize = SizeOf(tdlg)
  tdlg\hwndParent = Parent;#Null
  tdlg\hInstance = #Null
  tdlg\dwFlags = flags
  tdlg\dwCommonButtons = #Null
  tdlg\pszWindowTitle = @title
  tdlg\hMainIcon = icon
  tdlg\pszMainInstruction = @headline
  tdlg\pszContent = @text
  tdlg\cButtons = bCount
  tdlg\pButtons = @TD_Buttons(0)\nButtonID
  tdlg\cRadioButtons = rcount
  tdlg\pRadioButtons = @TD_RADIOButtons(0)\nButtonID
  tdlg\nDefaultButton = defbutton
  tdlg\nDefaultRadioButton = defradio
  tdlg\pszVerificationText = @checkbox
  tdlg\pszExpandedInformation = @Expando
  tdlg\pszExpandedControlText = @expand
  tdlg\pszCollapsedControlText = @collapse
  tdlg\hFooterIcon = footericon
  tdlg\pszFooter = @footer
  tdlg\pfCallback = #Null
  ProcedureReturn Task_DialogIndirect(tdlg)
EndProcedure

If #PB_Compiler_IsMainFile
  Define eintext.s,enttext.s,backtext.s,ClickedButton
  eintext.s="iTAC einfügen"+#LF$+"Fügt alle erforderlichen Daten für die iTAC-Anbindung ein. Erstellt außerdem eine Pre-Datei, die aber manuell angepasst werden muss."
  TD_Buttons(0)\pszButtonText = @eintext
  enttext.s="iTAC entfernen"+#LF$+"Entfernt alle iTAC-relevanten Daten und stellt den Normalzustand mit DMC wieder her."
  TD_Buttons(1)\pszButtonText = @enttext
  backtext.s="Zurück"+#LF$+"Keine Änderungen vornehmen"
  TD_Buttons(2)\pszButtonText = @backtext
  TD_RADIOButtons(0)\pszButtonText = @"Radio 1"
  TD_RADIOButtons(1)\pszButtonText = @"Radio 2"
  TD_RADIOButtons(2)\pszButtonText = @"Radio 3"
  ClickedButton = TaskDialog("iTAC-Optionen",#TDF_USE_COMMAND_LINKS|#TDF_EXPAND_FOOTER_AREA,#TD_ICON_SHIELD_OK_COLORED,"Wählen Sie eine iTAC-Option aus:","Der iTAC kann eingefügt oder entfernt werden.",3,3,0,0,"","","","",0,"")
  ;fVerifyx      -> Checkbox gecheckt
  ;SelRadiox     -> Gewählter Radiobutton (1. Index ist 1)
  ;ClickedButton -> Gewählter Button (1. Index ist 1)
EndIf
Also, the original code, which still works (and is not so different from my one): viewtopic.php?p=355016#p355016

The most interesting part for me is, that the GetFunction-line is identical to the one in the original. Also loading the library works fine.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: GetFunction fails...but just in this code

Post by Paul »

Um, just tried your code using 6.01 B4 x64 on Windows 10 Home and it worked fine. Tried both ASM and C backend.
Line 77 does not return 0 (returns 140728349698768 on my system)
Image Image
User avatar
mk-soft
Always Here
Always Here
Posts: 6324
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: GetFunction fails...but just in this code

Post by mk-soft »

Works fine here with
- Windows 10
- PB v6.00 LTS

check your comctl32.dll version (min v6.0)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: GetFunction fails...but just in this code

Post by jacdelad »

Ok, strange. Thanks for testing. So it has to be something with my computer.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: GetFunction fails...but just in this code

Post by jacdelad »

So, I exprimented a bit and found out, that I could find the needed function via ExamineLibraryFunctions() in the original posts code, but not in my one. I assume, I'm somehow loading different versions of the DLL, but why? And can I get the path from where the DLL was loaded?
Also ExamineLibraryFunctions() delivers a lot of repetitions when reading LibraryFunctionName(). These names are not returned when also reading the addresses:

Code: Select all

OpenLibrary(0, "comctl32.dll")
If ExamineLibraryFunctions(0)
  While NextLibraryFunction()
    Debug LibraryFunctionName()+": "+Str(LibraryFunctionAddress())
    ;vs.
    ;Debug LibraryFunctionName()
  Wend
EndIf
Is this normal? Or am I doing something horribly wrong?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
mk-soft
Always Here
Always Here
Posts: 6324
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: GetFunction fails...but just in this code

Post by mk-soft »

There are probably a lot of (internal non-public) functions without names in this DLL.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: GetFunction fails...but just in this code

Post by luis »

jacdelad wrote: Wed Mar 01, 2023 4:35 pm And can I get the path from where the DLL was loaded?

Code: Select all

OpenLibrary(0, "comctl32.dll")

handle = LibraryID(0)

buf$ = Space(256)
       
Debug GetModuleFileName_(handle, @buf$, 256)

Debug buf$

In my case

Code: Select all

 
C:\WINDOWS\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.1110_none_a8625c1886757984\comctl32.dll

C:\WINDOWS\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.1110_none_60b5254171f9507e\comctl32.dll
"Have you tried turning it off and on again ?"
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: GetFunction fails...but just in this code

Post by jacdelad »

Thanks luis. Your code debugs me a 5.82-version, which should be wrong?!

Also, including it into the posted code always returns empty strings. Also, GetLastError_() delivers
ERROR_MOD_NOT_FOUND
126 (0x7E)
The specified module could not be found.
...regardless of using the working or the nonworking code.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
mk-soft
Always Here
Always Here
Posts: 6324
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: GetFunction fails...but just in this code

Post by mk-soft »

Work here with
- PB v6.00, v6.01 Beta4
- Windows 10, 21H2
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: GetFunction fails...but just in this code

Post by luis »

My snippet returns an empty string (and GetModuleFileName() returns ZERO I suppose ???) even after the PB's OpenLibrary() succeeded ? Is this correct ?

And GetLastError() returns ERROR_MOD_NOT_FOUND immediately after PB's OpenLibrary() succeeded ?
"Have you tried turning it off and on again ?"
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: GetFunction fails...but just in this code

Post by jacdelad »

No, your snippet works, but including into my code doesn't work.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: GetFunction fails...but just in this code

Post by luis »

jacdelad wrote: Wed Mar 01, 2023 9:04 pm No, your snippet works, but including into my code doesn't work.
Yes, I was asking if that's how it behaves inside your code. Is it as I described it ?
"Have you tried turning it off and on again ?"
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: GetFunction fails...but just in this code

Post by jacdelad »

Yes.

I'm sorry, I have to quit soon for today, so I will be online in 18 hours from now.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: GetFunction fails...but just in this code

Post by luis »

OK, maybe you can try replacing the PB OpenLibrary with the LoadLibrary API and see if it changes anything.
Because this looks pretty insane to me.

Also I found this: https://learn.microsoft.com/en-us/answe ... ew=1031288
It's complicated. The Common Controls library is an OS component. The version you're looking at is the last version (5.82) that was developed before the new CC library came into being. If an app uses the CC library then this is the version it'll get.

However starting with v6 it is now a side-by-side binary. Therefore the actual file resides under the WinSxS folder. If an app needs to use the v6+ version then it must have an app manifest. That is discussed here. If an app uses a manifest then ultimately it will use the SxS version in this folder. If there is no manifest then it is pre-6 and uses the last version which is 5.82.
What that would mean for you, if anything, I'm not sure.
"Have you tried turning it off and on again ?"
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: GetFunction fails...but just in this code

Post by jacdelad »

Afaik the TaskDialog was introduced with 6.00 (aka Windows Vista). So this seems to be wrong anyway.
I'll try the API later, I've got some work to do before.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply