TypeLib2AHK - Convert COM Type libraries to AHK code

Post your working scripts, libraries and tools
cpriest
Posts: 19
Joined: 17 Sep 2017, 08:06

Re: TypeLib2AHK - Convert COM Type libraries to AHK code

08 Oct 2017, 10:12

Was there any particular reason for shifting the function parameters and inserting pInterface? I noticed it creates big problems with byref parameters and removed it. Seems to have no ill effect...


Yes, this was because pInterface was not actually the interface, it was the 2nd argument (because it's an object method, the first, hidden parameter is assigned to this. Therefore "this" is actually pInterface in all cases.

For some reason your original code and my adaptation of your example only seems to receive a single event and then nothing more. Do you have any idea why that could be?


If you've removed the shifting, that's probably why. The 2nd post I made had a much simpler way to get the job done.

If you're only receiving one event, is it possible that you're not holding a reference to the sub-class? That would cause the class to self-delete, possibly clear the vtable. The program might or might-not crash but the events wouldn't come through properly.
Elgin
Posts: 96
Joined: 30 Sep 2013, 09:19

Re: TypeLib2AHK - Convert COM Type libraries to AHK code

08 Oct 2017, 10:56

If you've removed the shifting, that's probably why. The 2nd post I made had a much simpler way to get the job done.


Nope, it's not. I only get one event from your first code and simplified code with the shifting, as well as from mine without shifting.

In any case there needs to be a solution without the parameter shifting.
Stuff like this:

Code: [Select all] [Download] GeSHi © Codebox Plus

	_GetPatternProvider(patternId, byref pRetVal)

will simply fail when you shift the parameters as the byref gets garbled up.
cpriest
Posts: 19
Joined: 17 Sep 2017, 08:06

Re: TypeLib2AHK - Convert COM Type libraries to AHK code

08 Oct 2017, 11:15

Isn't ByRef similar/same to ppRetVal?

Actually, in this particular case, no parameter forwarding would be necessary really, it's just that this == pInterface, so it could be like this (I think):

Code: [Select all] [Download] GeSHi © Codebox Plus

_GetPatternProvider(patternId, byRef pRetVal) {
if (!IsObject(this))
return ComObjImpl.ObjMap[this]._GetPatternProvider(patternId, pRetVal)

NumPut(pImplementor, pRetVal+0)
return 0x00 ; S_OK
}


But in other situations, where parameter shifting is necessary, wouldn't this work just as well?

Code: [Select all] [Download] GeSHi © Codebox Plus

_GetPatternProvider(patternId, ppRetVal) {
if (!IsObject(this))
return ComObjImpl.ObjMap[this]._GetPatternProvider(patternId, ppRetVal)

; Would need to treat ppRetVal as a pointer-pointer
NumPut(pImplementor, (*pRetVal))
return 0x00 ; S_OK
}


No expert, but I think that would be right...

Elgin wrote:I gave your code a quick test and it only seems to run in 64bit but not in 32. Any idea what might cause this? I'd like to support both if possible.

On this topic, did you get it working with 32 bit? I tried everything I could think of but could not get it to work, by the end I was just trying random things but I think it has to do w/ UPtr/UInt in 32 bit code with all the various calls, etc.
cpriest
Posts: 19
Joined: 17 Sep 2017, 08:06

Re: TypeLib2AHK - Convert COM Type libraries to AHK code

08 Oct 2017, 11:17

cpriest wrote:
Elgin wrote:I gave your code a quick test and it only seems to run in 64bit but not in 32. Any idea what might cause this? I'd like to support both if possible.

On this topic, did you get it working with 32 bit? I tried everything I could think of but could not get it to work, by the end I was just trying random things but I think it has to do w/ UPtr/UInt in 32-bit code with all the various calls, etc.


Come to think of it, if we had debugging symbols for AutoHotKey it might help to be able to trace with Visual Studio what/where it's going wrong.
Elgin
Posts: 96
Joined: 30 Sep 2013, 09:19

Re: TypeLib2AHK - Convert COM Type libraries to AHK code

13 Oct 2017, 05:13

I've done a good bit of reading... the byref is only really necessary in very few cases, e.g. when integers are passed as FIN/FOUT parameters, as the most commonly used types are handled as byref by AHK anyway. So I removed most byrefs and also removed the implementation code for interfaces that extend IDispatch as those are also handled natively by AHK. I still need to decide if I'll just add a warning for the byref or make the parameters before those also byref for good measure...

I've updated the test branch accordingly with the parameter shifting back in place.

But: I still only get a single event back from the test code and had no luck with 32bit.
Do the events work for you now?
cpriest
Posts: 19
Joined: 17 Sep 2017, 08:06

Re: TypeLib2AHK - Convert COM Type libraries to AHK code

14 Oct 2017, 09:46

Yeah, they're working for me. Can you post the code you're using? (I haven't tried it yet with the new export, but maybe I can spot where the problem is)
Elgin
Posts: 96
Joined: 30 Sep 2013, 09:19

Re: TypeLib2AHK - Convert COM Type libraries to AHK code

15 Oct 2017, 05:23

The test code is in the test branch on Github (uiaeventhandlertest.ahk).
cpriest
Posts: 19
Joined: 17 Sep 2017, 08:06

Re: TypeLib2AHK - Convert COM Type libraries to AHK code

15 Oct 2017, 08:29

So currently I get the created events every time, the destroyed events are not consistent but I have gotten them. Here's a trace of whats happening with my version. Still looking through your code, but thought this might help:

Note that in this log for every 'notepad' I created I also closed (but no destroyed event), but I'm getting destroyed events for the alt-tab window

Spoiler
cpriest
Posts: 19
Joined: 17 Sep 2017, 08:06

Re: TypeLib2AHK - Convert COM Type libraries to AHK code

15 Oct 2017, 09:06

Looking at the code I noticed this isn't right:

https://github.com/Elgin1/TypeLib2AHK/b ... e.ahk#L177

It should be:
NumPut(0, ppvObject+0, "Ptr")

I think that may be the problem.
Elgin
Posts: 96
Joined: 30 Sep 2013, 09:19

Re: TypeLib2AHK - Convert COM Type libraries to AHK code

15 Oct 2017, 14:18

That made it better, but it still crashes after a few (2-4) events, so there must be something else...

Could you please post your working code? Then I can compare it and hopefully work out the kinks.
cpriest
Posts: 19
Joined: 17 Sep 2017, 08:06

Re: TypeLib2AHK - Convert COM Type libraries to AHK code

15 Oct 2017, 20:18

Yes, though mine uses some things from my own library that may not be available, most notably OutputDebug() function, which is mostly a wrapper for OutputDebug % Format...

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



For the most part, you can ignore commented out code, it is/was something I am/was playing with.
User avatar
king-of-hearts
Posts: 6
Joined: 01 Oct 2017, 06:29

Re: TypeLib2AHK - Convert COM Type libraries to AHK code

Today, 07:19

Fantastic!! Great work!

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 11 guests