COM Expertise needed: COM Callbacks

Nierjerson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Apr 23 17:55:45 PDT 2017


Still trying to get the com automation code working. This is a 
general issue with COM programming as I do not have the 
experience to solve the problem.

There are two files at:

http://s000.tinyupload.com/index.php?file_id=33201858563271816000

Gen.d is the automatically generated COM wrapper in D for 
photoshop.

main.d is the test code.

You'll need windows and photoshop to make use of the code.

The idea is simple. Set the RGBColor foreground color using one 
of the COM methods in cSolidColor. We can set the color using 
Red, Green, or Blue and doubles and it works because one can pass 
a simple type without any marshaling.

But if one wants to set all three using the RGBColor inteface, it 
requires more work; and this is where I'm stuck at.

What I have done is create a simple router that brings all the 
work in to main.d.

The first method is `void RGB(icRGBColor, cSolidColor)` and it 
simply attempts to invoke PS's SolidColor's RGB method to have it 
set the colors.

When we call this method, it passes our interface that we want 
photoshop to use as to get at the colors and set them.

The second method(s) is basically in icRGBColor. This class is 
suppose to represent the callback interface. Photoshop is suppose 
to call these methods to get the colors and such.


The idea is that we pass our icRGBColor instance to invoke which 
informs PS that we want to set the color using the 
interface(rather than say a double). PS then calls the 
appropriate methods on the interface to do what it needs to 
do(e.g., Red() to get the red value to set).

At least I believe that is how it goes.

When we call the invoke function eventually the QueryInterface is 
called, which is good because this means that PS(or COM) must 
have called it and this is probably what it is suppose to do.

the problem is, that the code crashes and I can't get it past 
that obstacle. What I'd like to do is get to the point where we 
can get PS to set the colors using that interface(icRGBColor). 
Right now I just have dummy returns and have it print to the 
console when the method is called, which is good enough for 
getting the kinks worked out.

Anyone that basically has more of a clue than I do mind giving it 
a look over and see if they can figure out how to get it to work. 
It's relatively simple. Only main.d really needs to be messed 
with and that's just about 50 lines of code(and only a few are 
actually relevant(icRGBColor.QueryInterface, RGB() and a few of 
the lines at the end of main).

Once this is figured out I should have a near complete automation 
of COM in D. This allows one to simply run the tool on the .idl 
file and it will generate a D file with all the machinery to use 
the COM back end.



Thanks.





More information about the Digitalmars-d-learn mailing list