June 15, 2016
On Wednesday, 15 June 2016 at 08:24:41 UTC, John wrote:
> On Wednesday, 15 June 2016 at 08:21:06 UTC, John wrote:
>> OK, adding the return type to the signature should fix that. So:
>>
>>   private static Parameter getParameters(MethodImpl method)
>
> Sorry, I meant the getParameter methods should return be:
>
>   private static Parameter[] getParameters(MethodImpl method)
>
> and
>
>   private static Parameter[] getParameters(MethodImpl method, out Parameter returnParameter, bool getReturnParameter)

Thanks. When I ran it I got a d file! when I tried to use that d file I get undefined IID and IDispatch. I imagine these interfaces come from somewhere, probably built in?

Any ideas?
June 15, 2016
On Wednesday, 15 June 2016 at 15:12:06 UTC, thedeemon wrote:
> On Wednesday, 15 June 2016 at 07:01:30 UTC, Joerg Joergonson wrote:
>
>> It  seems idl2d from VD is not easily compilable?
>
> I don't remember problems with that, anyway here's the binary I used:
> http://stuff.thedeemon.com/idl2d.exe

It crashes when I use it ;/

core.exception.UnicodeException@src\rt\util\utf.d(290): invalid UTF-8 sequence

tbl2d did work and gave me a d file but I need to figure out what IID and IDispatch are.

June 15, 2016
On Wednesday, 15 June 2016 at 16:03:04 UTC, Jesse Phillips wrote:
> On Monday, 13 June 2016 at 01:22:33 UTC, Incognito wrote:
>> [...]
>
> There is also:
> https://github.com/JesseKPhillips/Juno-Windows-Class-Library
>
> It kind of provides similar highlevel options as the "Modern COM Programming in D."
>
> But I don't use it and have only be somewhat keeping it alive (I had some hiccups in supporting 64bit), so I haven't been working to improve the simplicity of interfacing to COM objects.
>
> It also includes definitions for accessing Windows COM objects which aren't needed when interfacing with your own or other COM objects. I'd like to have two libraries, Juno Library and Juno Windows Class Library.

I'll check it it out...
June 15, 2016
On Wednesday, 15 June 2016 at 16:45:39 UTC, Joerg Joergonson wrote:
> Thanks. When I ran it I got a d file! when I tried to use that d file I get undefined IID and IDispatch. I imagine these interfaces come from somewhere, probably built in?
>
> Any ideas?

Add the following after the module name:

  import core.sys.windows.com, core.sys.windows.oaidl;
June 15, 2016
On Wednesday, 15 June 2016 at 17:20:31 UTC, John wrote:
> On Wednesday, 15 June 2016 at 16:45:39 UTC, Joerg Joergonson wrote:
>> Thanks. When I ran it I got a d file! when I tried to use that d file I get undefined IID and IDispatch. I imagine these interfaces come from somewhere, probably built in?
>>
>> Any ideas?
>
> Add the following after the module name:
>
>   import core.sys.windows.com, core.sys.windows.oaidl;

Thanks. Should these not be added to the generated file?

Also, could you add to it the following:

const static GUID iid = Guid!("5DE90358-4D0B-4FA1-BA3E-C91BBA863F32");

inside the interface (Replace the string with the correct guid)?



This allows it to work with ComPtr which looks for the iid inside the interface, shouldn't hurt anything.

In any case, I haven't got ComPtr to work so...


GUID Guid(string str)()
{
    static assert(str.length==36, "Guid string must be 36 chars long");
    enum GUIDstring = "GUID(0x" ~ str[0..8] ~ ", 0x" ~ str[9..13] ~ ", 0x" ~ str[14..18] ~
        ", [0x" ~ str[19..21] ~ ", 0x" ~ str[21..23] ~ ", 0x" ~ str[24..26] ~ ", 0x" ~ str[26..28]
        ~ ", 0x" ~ str[28..30] ~ ", 0x" ~ str[30..32] ~ ", 0x" ~ str[32..34] ~ ", 0x" ~ str[34..36] ~ "])";
    return mixin(GUIDstring);
}


....

also tried CoCreateInstance and getting error 80040154

Not sure if it works.

....

Changed the GUID to another one found in the registry(not the one at the top of the generated file) and it works. Both load photoshop


int main(string[] argv)
{

	//auto ps = ComPtr!_Application(CLSID_PS).require;
		
	//const auto CLSID_PS = Guid!("6DECC242-87EF-11cf-86B4-444553540000"); // PS 90.1 fails because of interface issue
	const auto CLSID_PS = Guid!("c09f153e-dff7-4eff-a570-af82c1a5a2a8");   // PS 90.0 works.
	


			
    auto hr = CoInitialize(null);
    auto iid = IID__Application;


    _Application* pUnk;

    hr = CoCreateInstance(&CLSID_PS, null, CLSCTX_ALL, &iid, cast(void**)&pUnk);
    if (FAILED(hr))
            throw new Exception("ASDF");

}

The photoshop.d file
http://www.filedropper.com/photoshop_1


So, I guess it works but how to access the methods? The photoshop file looks to have them listed but they are all commented out.

I suppose this is what ComPtr and other methods are used to help create the interface but none seem to work.






June 15, 2016
On Wednesday, 15 June 2016 at 06:09:33 UTC, thedeemon wrote:
> On Monday, 13 June 2016 at 17:38:41 UTC, Incognito wrote:
>
>> [...]
>
> There are ready tools idl2d:
> https://github.com/dlang/visuald/tree/master/c2d
>
> [...]

I can't seem to get ComPtr to work.


auto ps = ComPtr!_Application(CLSID_PS).require;

Where CLSID_PS is the Guid from the registry that seems to work with CoCreate. _Application was generated from tbl2d.


See my other post for a more(not much) complete description of the issues files.



June 15, 2016
On Wednesday, 15 June 2016 at 18:32:28 UTC, Joerg Joergonson wrote:
>>   import core.sys.windows.com, core.sys.windows.oaidl;
>
> Thanks. Should these not be added to the generated file?

The problem is that other type libraries will probably require other headers to be imported, and there's no way to work out which, so I've left that up to the user for now.

>
> Also, could you add to it the following:
>
> const static GUID iid = Guid!("5DE90358-4D0B-4FA1-BA3E-C91BBA863F32");
>
> inside the interface (Replace the string with the correct guid)?
>
>
>
> This allows it to work with ComPtr which looks for the iid inside the interface, shouldn't hurt anything.

I could add that as an option.

>
> In any case, I haven't got ComPtr to work so...
>
>
> GUID Guid(string str)()
> {
>     static assert(str.length==36, "Guid string must be 36 chars long");
>     enum GUIDstring = "GUID(0x" ~ str[0..8] ~ ", 0x" ~ str[9..13] ~ ", 0x" ~ str[14..18] ~
>         ", [0x" ~ str[19..21] ~ ", 0x" ~ str[21..23] ~ ", 0x" ~ str[24..26] ~ ", 0x" ~ str[26..28]
>         ~ ", 0x" ~ str[28..30] ~ ", 0x" ~ str[30..32] ~ ", 0x" ~ str[32..34] ~ ", 0x" ~ str[34..36] ~ "])";
>     return mixin(GUIDstring);
> }
>
>
> ....
>
> also tried CoCreateInstance and getting error 80040154
>
> Not sure if it works.
>
> ....
>
> Changed the GUID to another one found in the registry(not the one at the top of the generated file) and it works. Both load photoshop

Oops. The one at the top of the file is the type library's ID, not the class ID. I should just omit it if it causes confusion.

>
>
> int main(string[] argv)
> {
>
> 	//auto ps = ComPtr!_Application(CLSID_PS).require;
> 		
> 	//const auto CLSID_PS = Guid!("6DECC242-87EF-11cf-86B4-444553540000"); // PS 90.1 fails because of interface issue
> 	const auto CLSID_PS = Guid!("c09f153e-dff7-4eff-a570-af82c1a5a2a8");   // PS 90.0 works.
> 	
>
>
> 			
>     auto hr = CoInitialize(null);
>     auto iid = IID__Application;
>
>
>     _Application* pUnk;
>
>     hr = CoCreateInstance(&CLSID_PS, null, CLSCTX_ALL, &iid, cast(void**)&pUnk);
>     if (FAILED(hr))
>             throw new Exception("ASDF");
>
> }
>
> The photoshop.d file
> http://www.filedropper.com/photoshop_1
>
>
> So, I guess it works but how to access the methods? The photoshop file looks to have them listed but they are all commented out.

They're commented out because Photoshop seems to have only provided a late-binding interface and you have to call them by name through IDispatch.Invoke. It's possible to wrap all that in normal D methods, and I'm working on it, but it won't be ready for a while.

June 15, 2016
On Wednesday, 15 June 2016 at 18:35:42 UTC, Joerg Joergonson wrote:
> On Wednesday, 15 June 2016 at 06:09:33 UTC, thedeemon wrote:
>> On Monday, 13 June 2016 at 17:38:41 UTC, Incognito wrote:
>>
>>> [...]
>>
>> There are ready tools idl2d:
>> https://github.com/dlang/visuald/tree/master/c2d
>>
>> [...]
>
> I can't seem to get ComPtr to work.
>
>
> auto ps = ComPtr!_Application(CLSID_PS).require;
>
> Where CLSID_PS is the Guid from the registry that seems to work with CoCreate. _Application was generated from tbl2d.
>
>
> See my other post for a more(not much) complete description of the issues files.

Ensure you are calling CoInitialize before anything else.
June 15, 2016
On Wednesday, 15 June 2016 at 19:21:51 UTC, John wrote:
> On Wednesday, 15 June 2016 at 18:32:28 UTC, Joerg Joergonson wrote:
>>>   import core.sys.windows.com, core.sys.windows.oaidl;
>>
>> Thanks. Should these not be added to the generated file?
>
> The problem is that other type libraries will probably require other headers to be imported, and there's no way to work out which, so I've left that up to the user for now.
>
>>
>> Also, could you add to it the following:
>>
>> const static GUID iid = Guid!("5DE90358-4D0B-4FA1-BA3E-C91BBA863F32");
>>
>> inside the interface (Replace the string with the correct guid)?
>>
>>
>>
>> This allows it to work with ComPtr which looks for the iid inside the interface, shouldn't hurt anything.
>
> I could add that as an option.
>
>>
>> In any case, I haven't got ComPtr to work so...
>>
>>
>> GUID Guid(string str)()
>> {
>>     static assert(str.length==36, "Guid string must be 36 chars long");
>>     enum GUIDstring = "GUID(0x" ~ str[0..8] ~ ", 0x" ~ str[9..13] ~ ", 0x" ~ str[14..18] ~
>>         ", [0x" ~ str[19..21] ~ ", 0x" ~ str[21..23] ~ ", 0x" ~ str[24..26] ~ ", 0x" ~ str[26..28]
>>         ~ ", 0x" ~ str[28..30] ~ ", 0x" ~ str[30..32] ~ ", 0x" ~ str[32..34] ~ ", 0x" ~ str[34..36] ~ "])";
>>     return mixin(GUIDstring);
>> }
>>
>>
>> ....
>>
>> also tried CoCreateInstance and getting error 80040154
>>
>> Not sure if it works.
>>
>> ....
>>
>> Changed the GUID to another one found in the registry(not the one at the top of the generated file) and it works. Both load photoshop
>
> Oops. The one at the top of the file is the type library's ID, not the class ID. I should just omit it if it causes confusion.
>
>>
>>
>> int main(string[] argv)
>> {
>>
>> 	//auto ps = ComPtr!_Application(CLSID_PS).require;
>> 		
>> 	//const auto CLSID_PS = Guid!("6DECC242-87EF-11cf-86B4-444553540000"); // PS 90.1 fails because of interface issue
>> 	const auto CLSID_PS = Guid!("c09f153e-dff7-4eff-a570-af82c1a5a2a8");   // PS 90.0 works.
>> 	
>>
>>
>> 			
>>     auto hr = CoInitialize(null);
>>     auto iid = IID__Application;
>>
>>
>>     _Application* pUnk;
>>
>>     hr = CoCreateInstance(&CLSID_PS, null, CLSCTX_ALL, &iid, cast(void**)&pUnk);
>>     if (FAILED(hr))
>>             throw new Exception("ASDF");
>>
>> }
>>
>> The photoshop.d file
>> http://www.filedropper.com/photoshop_1
>>
>>
>> So, I guess it works but how to access the methods? The photoshop file looks to have them listed but they are all commented out.
>
> They're commented out because Photoshop seems to have only provided a late-binding interface and you have to call them by name through IDispatch.Invoke. It's possible to wrap all that in normal D methods, and I'm working on it, but it won't be ready for a while.


Ok, I've tried things like uncommenting

	Document Open(BSTR Document, VARIANT As, VARIANT AsSmartObject);
	void Load(BSTR Document);

	/*[id(0x70537673)]*/ BSTR get_ScriptingVersion();
  /*[id(0x70464D4D)]*/ double get_FreeMemory();
  /*[id(0x76657273)]*/ BSTR get_Version();
and everything crashes with bad reference.



If I try ComPtr, same thing



	const auto CLSID_PS = Guid!("c09f153e-dff7-4eff-a570-af82c1a5a2a8");   // PS 90.0 works.
	
	

			
    auto hr = CoInitialize(null);
    auto iid = IID__Application;

 	auto ps = cast(_Application)(ComPtr!_Application(CLSID_PS).require);

    _Application pUnk;
	
    hr = CoCreateInstance(&CLSID_PS, null, CLSCTX_ALL, &iid, cast(void**)&pUnk);
    if (FAILED(hr))
            throw new Exception("ASDF");

	auto ptr = cast(wchar*)alloca(wchar.sizeof * 1000);
	
	auto fn = `ps.psd`;
	for(auto i = 0; i < fn.length; i++)
	{
		ptr[i] = fn[i];
	}

	writeln(ps.get_FreeMemory());
	
	pUnk.Load(ptr);



My thinking is that CoCreateinstance is suppose to give us a pointer to the interface so we can use it, if all this stuff is crashing does that mean the interface is invalid or not being assigned properly or is there far more to it than this?



(
June 17, 2016
On Wednesday, 15 June 2016 at 21:06:01 UTC, Joerg Joergonson wrote:
> Ok, I've tried things like uncommenting
>
> 	Document Open(BSTR Document, VARIANT As, VARIANT AsSmartObject);
> 	void Load(BSTR Document);
>
> 	/*[id(0x70537673)]*/ BSTR get_ScriptingVersion();
>   /*[id(0x70464D4D)]*/ double get_FreeMemory();
>   /*[id(0x76657273)]*/ BSTR get_Version();
> and everything crashes with bad reference.
>...
> My thinking is that CoCreateinstance is suppose to give us a pointer to the interface so we can use it, if all this stuff is crashing does that mean the interface is invalid or not being assigned properly or is there far more to it than this?

First of all, you can't just comment/uncomment parts of COM interface descriptions. Each COM interface has some specific layout of its functions, and if you list them in wrong order or skip some of them the virtual methods table gets completely screwed up, so you think you call one method but end up calling another, because you intended to call method #12 and instead called method #4. COM interface definitions in D must match their definitions in IDL exactly. One omission of a method, one mistake in its type, and you're fucked.