AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Menu wrapper library
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Drugwash



Joined: 08 Sep 2008
Posts: 608
Location: Ploiesti, RO

PostPosted: Thu Feb 05, 2009 1:25 am    Post subject: Reply with quote

That's better. Smile
1. -1074331648 0 0
2. -1074303292 0 0
HeapAlloc seems to be OK.
Back to top
View user's profile Send private message Yahoo Messenger
animeaime



Joined: 04 Nov 2008
Posts: 1046

PostPosted: Thu Feb 05, 2009 1:44 am    Post subject: Reply with quote

Drugwash wrote:
I've squeezed the DllCallDebugger in the Class script and guess what: it started spitting error [b]-4 one after another.
Code:
Class_Alloc(size)
{
    static AlreadyDone, HeapAlloc, ProcessHeap

    if (!AlreadyDone)
    {
        AlreadyDone := true
        HeapAlloc := Class_LoadDllFunction("Kernel32", "HeapAlloc")
DllCallDebugger()

        ProcessHeap := DllCall("GetProcessHeap")
    }



So, maybe I don't understand DllCallDebugger well enough. What does it do and what error does it report? You said that -4 started being spit out, was it spit out above?

Since the last code works, caching the DllAddresses shouldn't be the problems, so that's good. Maybe if you can explain DllCallDebugger to me and tell me what it returns and what it means, hopefully I can figure this out. Like you said, a dll call is probably to blame, but the entire code spits out dll calls left and right to provide the functionality, so the needle in a haystack analogy comes to mind. However, if you have patience I'm sure we can find that needle.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
animeaime



Joined: 04 Nov 2008
Posts: 1046

PostPosted: Thu Feb 05, 2009 1:54 am    Post subject: Reply with quote

Ok, since Menu_getMenuSize returns a blank, that means that there is a problem, and it's a simple enough function to disect.

Code:
#NoEnv ;Must be specified to work - tried to find out why, no luck
#Include MenuLibraryTestSetup.ahk

hMenu := MI_GetMenuHandle("tray")

MsgBox, % hMenu . " " . ErrorLevel . " " . A_LastError

MsgBox, % DllCall("GetMenuItemCount", "uint", hMenu)
MsgBox, % ErrorLevel . " " . A_LastError


Now, the other way to do it (as is in the code)

Code:
#NoEnv ;Must be specified to work - tried to find out why, no luck
#Include MenuLibraryTestSetup.ahk

hMenu := MI_GetMenuHandle("tray")

MsgBox, % hMenu . " " . ErrorLevel . " " . A_LastError

GetMenuItemCount := Menu_LoadDllFunction("User32", "GetMenuItemCount")

MsgBox, % GetMenuItemCount . " " . ErrorLevel . " " . A_LastError

MsgBox, % DllCall(GetMenuItemCount, "uint", hMenu)
MsgBox, % ErrorLevel . " " . A_LastError

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
Drugwash



Joined: 08 Sep 2008
Posts: 608
Location: Ploiesti, RO

PostPosted: Thu Feb 05, 2009 2:12 am    Post subject: Reply with quote

Got my fingers in too many pies at this time. Smile

First code:
1. 3352 0 0
2. 10
3. 0 0

Second code:
1. 1768 0 0
2. -1077926661 0 0
3. <blank>
4. -4 0

Guess third one is not right.

DllCallDebugger should simply show a message box whenever the result of a DllCall is non-zero (which is usually a sign of something going wrong) and apparently also shows the script log.
I believe the function should be called after each DllCall or at least in places where a failure is suspected. I only inserted the call after the first DllCall in Class.ahk.
Back to top
View user's profile Send private message Yahoo Messenger
animeaime



Joined: 04 Nov 2008
Posts: 1046

PostPosted: Thu Feb 05, 2009 2:19 am    Post subject: Reply with quote

Yeah, that's the problem. Both codes should output the size. The second (which is what's used in the code) outputs a blank. Let me search the docs for the function to find out why. However, at least now the problem is found! Since the menu size is blank, the error cheking in the code prevents the move (because it thinks the original menu is empty).

So, I'll look that up and get back to you.

Hold on...-4.... that means you don't have the function in the dll...hmmm...

Try this. Maybe...just maybe, it's because it's a signed value and that's where the problem is.

Code:
#NoEnv ;Must be specified to work - tried to find out why, no luck
#Include MenuLibraryTestSetup.ahk

hMenu := MI_GetMenuHandle("tray")

MsgBox, % hMenu . " " . ErrorLevel . " " . A_LastError

GetMenuItemCount := Menu_LoadDllFunction2("User32", "GetMenuItemCount")

MsgBox, % GetMenuItemCount . " " . ErrorLevel . " " . A_LastError

MsgBox, % DllCall(GetMenuItemCount, "uint", hMenu)
MsgBox, % ErrorLevel . " " . A_LastError

Menu_LoadDllFunction2(ThisFile, ThisFunction)
{
    ;note: this is not my code, and sadly I have forgotten who wrote it
    ;contact me and I'll add your name here to give proper credit
    if !(hModule := DllCall("GetModuleHandle", "uint", &ThisFile, "uint"))
    {
        hModule := DllCall("LoadLibrary", "uint", &ThisFile, "uint")
    }

    return DllCall("GetProcAddress", "uint", hModule, "uint", &ThisFunction, "uint")
}

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
Drugwash



Joined: 08 Sep 2008
Posts: 608
Location: Ploiesti, RO

PostPosted: Thu Feb 05, 2009 2:53 am    Post subject: Reply with quote

Sorry for the late reply, I've been following another thread and got carried away. Embarassed
Results:
1. 1868 0 0
2. 3217040635 0 0
3. 10
4. 0 0

I never liked signed integers and I guess the code can read my heart. Smile
Back to top
View user's profile Send private message Yahoo Messenger
animeaime



Joined: 04 Nov 2008
Posts: 1046

PostPosted: Thu Feb 05, 2009 2:55 am    Post subject: Reply with quote

no prob, thanks for all your help.

so that works! So running it with signed ints doesn't, but with unsigned ints it does?? If so, yeah! if that's it, I'll update the code to return uints when the return should be unsigned, and upload.

Can you run the two again? The one that failed before, and the ond that worked in the same script? Just want to make sure that that is the problem.

Code:
#NoEnv ;Must be specified to work - tried to find out why, no luck
#Include MenuLibraryTestSetup.ahk

MsgBox, % "Signed"

hMenu := MI_GetMenuHandle("tray")

MsgBox, % hMenu . " " . ErrorLevel . " " . A_LastError

GetMenuItemCount := Menu_LoadDllFunction("User32", "GetMenuItemCount")

MsgBox, % GetMenuItemCount . " " . ErrorLevel . " " . A_LastError

MsgBox, % DllCall(GetMenuItemCount, "uint", hMenu)
MsgBox, % ErrorLevel . " " . A_LastError

MsgBox, % "Unsigned"

hMenu := MI_GetMenuHandle("tray")

MsgBox, % hMenu . " " . ErrorLevel . " " . A_LastError

GetMenuItemCount := Menu_LoadDllFunction2("User32", "GetMenuItemCount")

MsgBox, % GetMenuItemCount . " " . ErrorLevel . " " . A_LastError

MsgBox, % DllCall(GetMenuItemCount, "uint", hMenu)
MsgBox, % ErrorLevel . " " . A_LastError

Menu_LoadDllFunction2(ThisFile, ThisFunction)
{
    ;note: this is not my code, and sadly I have forgotten who wrote it
    ;contact me and I'll add your name here to give proper credit
    if !(hModule := DllCall("GetModuleHandle", "uint", &ThisFile, "uint"))
    {
        hModule := DllCall("LoadLibrary", "uint", &ThisFile, "uint")
    }

    return DllCall("GetProcAddress", "uint", hModule, "uint", &ThisFunction, "uint")
}

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Last edited by animeaime on Thu Feb 05, 2009 3:29 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Drugwash



Joined: 08 Sep 2008
Posts: 608
Location: Ploiesti, RO

PostPosted: Thu Feb 05, 2009 3:05 am    Post subject: Reply with quote

New tricks? You got me used to numbers. Very Happy

Signed
3032 0 0
-1077926661 0 0
<blank>
-4 0

Unsigned
3032 0 0
3217040635 0 0
10
0 0


Signed Int malfunction confirmed.
Back to top
View user's profile Send private message Yahoo Messenger
animeaime



Joined: 04 Nov 2008
Posts: 1046

PostPosted: Thu Feb 05, 2009 3:11 am    Post subject: Reply with quote

Awesome!!! That's an easy fix then. I'm hunting through the code to update all necessary occurances (and going to cache the remaining dll calls since we know it works fine for you). I'll make a post after I'm done.

Thank you so much for your help.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
animeaime



Joined: 04 Nov 2008
Posts: 1046

PostPosted: Thu Feb 05, 2009 3:50 am    Post subject: Reply with quote

Ok, it's up. I added some small optimizations by caching the remaining of the dll calls. Also, there was a bug that the code would return an error when trying to remove a "standard menu" item, this is now fixed. You can now remove items from the "standard menu". Also, there was another typo of a bug in Menu_Default that I fixed.

You can download the updated version here.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
Drugwash



Joined: 08 Sep 2008
Posts: 608
Location: Ploiesti, RO

PostPosted: Thu Feb 05, 2009 4:15 am    Post subject: Reply with quote

I wanted to keep it contained and only post testing results but... you changed things at the last moment.
#Include %A_ScriptDir%\..\Menu.ahk
#Include %A_ScriptDir%\..\MenuItem.ahk
#Include %A_ScriptDir%\..\Class.ahk
#Include %A_ScriptDir%\..\MenuLibraryTemplate.ahk


Those files are not there, not in the structure distributed in the zip at least. Personally I copied them to the lib subfolder in AHK but as they're distributed altogether you may as well use:
#Include Menu.ahk
#Include MenuItem.ahk
#Include Class.ahk
#Include MenuLibraryTemplate.ahk

or comment all of them while they're in lib (as I did now). Unless you're planning on changing distribution structure, that is.

This apart, it appears to work fine now. Only thing left is to remove the isChecked? 8 message box. Smile

Thank you so much for fixing this 9x issue; believe me, few people around would've done that. You have my respect! Wink
Back to top
View user's profile Send private message Yahoo Messenger
animeaime



Joined: 04 Nov 2008
Posts: 1046

PostPosted: Thu Feb 05, 2009 4:19 am    Post subject: Reply with quote

Sorry, I used that for bug testing...I'll remove them and upload it again Sad
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
animeaime



Joined: 04 Nov 2008
Posts: 1046

PostPosted: Thu Feb 05, 2009 4:26 am    Post subject: Reply with quote

Ok, sorry about that, I removed those lines.

No, the structure is the same as before. When I put the compatablity to Win98 on AHK, it doesn't include the files in the library, so I manually included them. The structure remained the same: Menu.ahk, MenuItem.ahk, Class.ahk, and MenuLibraryTemplate.ahk all go in the library folder for easy inclusion.

Also, the MsgBox is intentional - to show the Menu_isChecked function, you can delete it without any side-effects. I didn't know a better way to show that feature. There was a post about how to see if a menu item was checked, and I said I would include a function in my menu wrapper.

I'm glad it works. Thank you so much for your help.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
animeaime



Joined: 04 Nov 2008
Posts: 1046

PostPosted: Thu Feb 05, 2009 4:34 am    Post subject: Reply with quote

Just thought of this.

As a note, the Test files can appear in any folder - as long as MenuLibraryTest.ahk and MenuLibrarySetup.ahk are in the same folder. This allows you to include the menu functionality from your own scripts - wherever they may be. Also, by using these files as a model, you can keep your project-specific menu functions in one file, separate from your project, to allow easy modification to the Menu / MenuItem object struture. Also, you can either have a separate file for your menu setup (what MenuLibraryTest is), and include it into your project, or add in the menu setup into your code. Just trying to keep your options open so that this library doesn't restrict your programming style or needs.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
Drugwash



Joined: 08 Sep 2008
Posts: 608
Location: Ploiesti, RO

PostPosted: Thu Feb 05, 2009 4:36 am    Post subject: Reply with quote

It's OK, either way. Was just thinking of users that may not be familiar with the lib structure and would get the same error, so having the script modules in a straight-away usable structure right after unpacking would save confusion and board posts. Smile

Since the message box is intentional, everything should be fine now. If only I had the drive to work on all the half-baked projects I started and never finished...

Anyway, I'm glad it works too and hopefully it will be of use for many people. Thank you for your work and patience! Smile
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 2 of 6

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group