Re: Accessing COM Objects
On Friday, 17 June 2016 at 08:09:42 UTC, John wrote: On Wednesday, 15 June 2016 at 21:06:01 UTC, Joerg Joergonson wrote: 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? The problem is Photoshop hasn't provided an interface with methods that can be called directly. They don't exist on the interface, hence them being commented out. It's a mechanism known as late binding (everything is done at runtime rather than compile time). You need to ask the interface for the method's ID, marshal the parameters into a specific format, and then "invoke" the method using that ID. And you're not going to like it. Here's an example just to call the "Load" method: // Initialize the Photoshop class instance IDispatch psApp; auto iid = IID__Application; auto clsid = CLSID_Application; assert(SUCCEEDED(CoCreateInstance(, null, CLSCTX_ALL, , cast(void**; scope(exit) psApp.Release(); // Get the ID of the Load method auto methodName = "Load"w.ptr; auto dispId = DISPID_UNKNOWN; iid = IID_NULL; assert(SUCCEEDED(psApp.GetIDsOfNames(, , 1, 0, ))); // Put the parameters into the expected format VARIANT fileName = { vt: VARENUM.VT_BSTR, bstrVal: SysAllocString("ps.psd"w.ptr) }; scope(exit) VariantClear(); DISPPARAMS params = { rgvarg: , cArgs: 1 }; // Finally call the method assert(SUCCEEDED(psApp.Invoke(dispId, , 0, DISPATCH_METHOD, , null, null, null))); tlb2d only outputs the late-bound methods as a hint to the user so they know the names of the methods and the expected parameters (well, it saves looking them up in OleView). Had Photoshop supplied a compile-time binding, you could have just called psApp.Load(fileName) like you tried. It's possible to wrap that ugly mess above in less verbose code using native D types, and the Juno COM library mentioned earlier enabled that, but the code is quite ancient (and is part of and depends on a larger library). I've been slowly working on a more modern library. You'd be able to just write this: auto psApp = makeReference!"Photoshop.Application"(); psApp.Load("ps.psd"); But I don't know when it'll be ready. So, I was playing around with this method and was able to get things to work. Have you been able to automate this properly? Seems like if we have the interface and methods, we can create an implementation that automates the above marshaling and stuff automatically using reflection? e.g., give interface _Application : IDispatch { ... /*[id(0x4C64536C)]*/ void Load(BSTR Document); ... /*[id(0x71756974)]*/ void Quit(); ... } it shouldn't be too hard to generate a class like Generated code: class PSAppication : _Application { ... void Load(BSTR Document) { // The invoking and marshaling code automatically generated // } ... void Quit() { // The invoking and marshaling code automatically generated // } ... } ? I assume this is what you said you were working on, more or less? Would be awesome if you already had this up and running! If not, I guess I'll try to implement something like it ;/ If you haven't worked on this, I have a few questions for ya: 1. Do we have to cocreateinit every time or can we just do it once? Seems like it could be a major performance issue if we have to call it each time? 2. Marshaling the paramters seems like it could be tricky as we would have to know each case? Scanning the photoshop idl file suggests there are many different parameter and return types(strings, ints, VARIANT_BOOL, com interfaces, enum, etc). A few are easy to handle and you showed how to handle strings, but some of the others I wouldn't know how to do. 3. Does the juno code handle this well enough to copy and paste most of the labor? 4. Any pitfalls to worry about? Thanks.
Re: Accessing COM Objects
On Friday, 17 June 2016 at 08:09:42 UTC, John wrote: On Wednesday, 15 June 2016 at 21:06:01 UTC, Joerg Joergonson wrote: [...] The problem is Photoshop hasn't provided an interface with methods that can be called directly. They don't exist on the interface, hence them being commented out. It's a mechanism known as late binding (everything is done at runtime rather than compile time). You need to ask the interface for the method's ID, marshal the parameters into a specific format, and then "invoke" the method using that ID. [...] Any news on this? I'd like to do some photoshop programming in D too but it seems like a mess?!?
Re: Comparing Instances of Classes
On Friday, 10 March 2017 at 20:27:09 UTC, Meta wrote: On Friday, 10 March 2017 at 17:08:42 UTC, Whatsthisnow wrote: I guess i am just too used to the java way of x.equals(object) which at the source is exactly 'return this == object' Java would return false here too, though, if it actually did `this == object` in its default compare method. If I remember correctly, comparing two objects with == in Java compares their addresses, not their contents. I must be losing my mind then
Re: DMD win32.mak error
On Saturday, 11 March 2017 at 00:34:03 UTC, Paul D Anderson wrote: On Friday, 10 March 2017 at 22:04:23 UTC, Paul D Anderson wrote: While building DMD -- "make -fwin32.mak release" -- I received the following error message: echo "2.073.2" > verstr.h Error: don't know how to make '../res/default_ddoc_theme/ddoc' --- error level 1 I'm guessing it might be a build configuration problem on my end, but what is the problem? Paul I see John Colvin has already filed a bug report (issue 17165) addressing this. Apparently the missing file is available on GitHub. I copied the missing file John referenced to my src/dmd file but this did not have any effect. I've created a bug report (17253) addressing this problem. Paul
Re: DMD + Dynamic Library.
On Wednesday, 8 March 2017 at 18:21:35 UTC, Damien Gibson wrote: On Wednesday, 8 March 2017 at 06:28:47 UTC, Jerry wrote: You have to use "export" for any symbol to be visible from a dll. On Windows by default nothing is exported. Would "export" and "export extern(D):" not be the same? Im confuseled.. You have to use extern (C) { import std.stdio; export{ void dllprint() { writeln("\nmydll.dll read ok!!!\n"); } int Myadd(int x, int y) { return x + y; } } }
Re: DMD win32.mak error
On Friday, 10 March 2017 at 22:04:23 UTC, Paul D Anderson wrote: While building DMD -- "make -fwin32.mak release" -- I received the following error message: echo "2.073.2" > verstr.h Error: don't know how to make '../res/default_ddoc_theme/ddoc' --- error level 1 I'm guessing it might be a build configuration problem on my end, but what is the problem? Paul I see John Colvin has already filed a bug report (issue 17165) addressing this. Apparently the missing file is available on GitHub.
DMD win32.mak error
While building DMD -- "make -fwin32.mak release" -- I received the following error message: echo "2.073.2" > verstr.h Error: don't know how to make '../res/default_ddoc_theme/ddoc' --- error level 1 I'm guessing it might be a build configuration problem on my end, but what is the problem? Paul
Re: TLS
On Friday, 10 March 2017 at 19:24:29 UTC, bauss wrote: Mark your variables with __gshared. I would say shred, but it has some restrictions to it, where __gshared is the equivalent to global variables in C. immutable variables are also not put in TLS.
Re: Comparing Instances of Classes
On Friday, 10 March 2017 at 17:08:42 UTC, Whatsthisnow wrote: I guess i am just too used to the java way of x.equals(object) which at the source is exactly 'return this == object' Java would return false here too, though, if it actually did `this == object` in its default compare method. If I remember correctly, comparing two objects with == in Java compares their addresses, not their contents.
Re: Comparing Instances of Classes
On 03/10/2017 08:22 AM, DRex wrote: Error: function app.A.opEquals does not override any function, did you mean to override 'object.Object.opEquals'? My A class appears exactly as mentioned in your comment... FWIW, here's some other info: http://ddili.org/ders/d.en/object.html#ix_object.opEquals Ali
Re: TLS
On Friday, 10 March 2017 at 07:33:44 UTC, M-exe wrote: On Friday, 10 March 2017 at 07:17:22 UTC, rikki cattermole wrote: D does not support Windows XP. If you absolutely require it, you will have to contact Walter about support. Let me care about it ;) I just need help with the TLS :) Mark your variables with __gshared. I would say shred, but it has some restrictions to it, where __gshared is the equivalent to global variables in C.
Re: Comparing Instances of Classes
On Friday, 10 March 2017 at 16:47:47 UTC, Adam D. Ruppe wrote: On Friday, 10 March 2017 at 16:36:17 UTC, DRex wrote: I'm fairly new to D, but this seems to be quite a pain in the rear for a simple comparison of instances of classes...really odd that comparing instances of classes in D requires that messing around when D seems all about simplifying things... There often is no sensible default comparison for class contents (now structs on the other hand do have a default comparison that usually works, but structs don't have to worry about polymorphism), so you just need to specify what fields actually matter to your code... I guess i am just too used to the java way of x.equals(object) which at the source is exactly 'return this == object'
Re: Comparing Instances of Classes
On Friday, 10 March 2017 at 16:36:17 UTC, DRex wrote: I'm fairly new to D, but this seems to be quite a pain in the rear for a simple comparison of instances of classes...really odd that comparing instances of classes in D requires that messing around when D seems all about simplifying things... There often is no sensible default comparison for class contents (now structs on the other hand do have a default comparison that usually works, but structs don't have to worry about polymorphism), so you just need to specify what fields actually matter to your code...
Re: Comparing Instances of Classes
On Friday, 10 March 2017 at 16:30:00 UTC, Adam D. Ruppe wrote: On Friday, 10 March 2017 at 16:22:18 UTC, DRex wrote: Error: function app.A.opEquals does not override any function, did you mean to override 'object.Object.opEquals'? Oh sorry, maybe I messed up the const. Try: override bool opEquals(A rhs) { ... } and if the compiler still complains change the A to Object and cast it inside (but I'm pretty sure that will work, I think it is just const it is picky about) Thanks. I'm fairly new to D, but this seems to be quite a pain in the rear for a simple comparison of instances of classes...really odd that comparing instances of classes in D requires that messing around when D seems all about simplifying things...
Re: Comparing Instances of Classes
On Friday, 10 March 2017 at 16:22:18 UTC, DRex wrote: Error: function app.A.opEquals does not override any function, did you mean to override 'object.Object.opEquals'? Oh sorry, maybe I messed up the const. Try: override bool opEquals(A rhs) { ... } and if the compiler still complains change the A to Object and cast it inside (but I'm pretty sure that will work, I think it is just const it is picky about)
Re: Comparing Instances of Classes
On Friday, 10 March 2017 at 16:13:21 UTC, Adam D. Ruppe wrote: On Friday, 10 March 2017 at 16:08:05 UTC, DRex wrote: Am I missing something here? Yeah, you need to implement a custom equality operator. class A { int member; override bool opEquals(const A rhs) { return this.member == rhs.member; // and other members that need to be equal } } The default opEquals sees if they are the same *instance* (same as `a is b`), and does not look at contents. You need to define that yourself. I tried the above class A, and now the compiler fails with the following error: Error: function app.A.opEquals does not override any function, did you mean to override 'object.Object.opEquals'? My A class appears exactly as mentioned in your comment...
Re: Comparing Instances of Classes
On Friday, 10 March 2017 at 16:08:05 UTC, DRex wrote: Am I missing something here? Yeah, you need to implement a custom equality operator. class A { int member; override bool opEquals(const A rhs) { return this.member == rhs.member; // and other members that need to be equal } } The default opEquals sees if they are the same *instance* (same as `a is b`), and does not look at contents. You need to define that yourself.
Comparing Instances of Classes
Hi, I am trying to compare two instances of a class. I created a test program to try this, but every method I use to compare the instances always returns false. this is my code to test comparison class A { this() { } } void main() { A a = new A(); A a2 = new A(); writeln(equals(a, a2)); } bool equals(Object obj1, Object obj2) { return (obj1 is obj2); } I have tried 'a is a2', I have tried 'a1 == a2' and many other ways (including opEquals from object.d) among other things and every single time the comparison returns false. The comparison always fails and never returns true. I am trying to do something like Object.equals(Object o) in java, but so far, no success. Am I missing something here?
Re: Where do you test syntax of D regexp online?
On Friday, 10 March 2017 at 14:36:48 UTC, Suliman wrote: On Thursday, 9 March 2017 at 16:47:18 UTC, Adam D. Ruppe wrote: On Thursday, 9 March 2017 at 16:40:13 UTC, Suliman wrote: How should I write to file result without \r\n\ symbols? auto x = content.matchFirst(bigCodeBlock); File f = File("foo.txt", "w"); f.write(x); Just f.write(x[0]); to write out the whole hit instead of the collection of references. What can be wrong with this regexp? https://regex101.com/r/8e7nPL/3 it's crush D compiler, and I can't find out why I need simply select parts from one first-level # to another. like: #header some text and some code ^ first matching #header2 some text2 and some code2 ^ second matching
Re: Where do you test syntax of D regexp online?
On Thursday, 9 March 2017 at 16:47:18 UTC, Adam D. Ruppe wrote: On Thursday, 9 March 2017 at 16:40:13 UTC, Suliman wrote: How should I write to file result without \r\n\ symbols? auto x = content.matchFirst(bigCodeBlock); File f = File("foo.txt", "w"); f.write(x); Just f.write(x[0]); to write out the whole hit instead of the collection of references. What can be wrong with this regexp? https://regex101.com/r/8e7nPL/3 it's crush D compiler, and I can't find out why
How to write document for methods under static if?
Example: /** test type */ struct A(bool T) { static if (T) { /// Case 1 int ok(){ return 1; } } else { /// case 2 int notok(){ return 1; } } /// Other int other() { return 0; } } /// unittest { A!true x; A!false y; } In documents generated by ddoc, only case 1 is included. In documents generated by ddox, none of the cases is included. What's the proper way to write document in this case?