digitalmars.D.learn - extern(Windows) on XPCOM
- Li Jie (86/86) Apr 12 2007 I want to call XPCOM and write XPCOM component with D, but I have some p...
- Chris Nicholson-Sauls (7/111) Apr 12 2007 I would think a merge of options 3. and 4. would be good. Ie, add eithe...
- Li Jie (14/125) Apr 21 2007 My friend, h_rain has found a simple way, rename nsISupports to IUnknown...
I want to call XPCOM and write XPCOM component with D, but I have some problems. This is COM object virtual table structure: And this is XPCOM object virtual table: extern(Windows) only compatible COM, because it added an offset, XPCOM do not need this. When call QueryInterface, it really call AddRef. And I tried extern(C++) and extern(Pascal), no changes. I think that there are 4 solutions: 1. Don't use interface, replace with struct, C style: QueryInterface; Ugly! but it can works. 2. Modify XPCOM interface, remove QueryInterface method: QueryInterface; It can works, replace nsISupports.QueryInterface with MyQueryInterface. But I can't write XPCOM component with D, because no QueryInterface in interface. 3. Hack DMD: Change to: And add pointer to IUnknown: I don't know whether it can work. 4. Hack DMD, add extern(XPCOM), I think it's very difficult to do. Any ideas?
Apr 12 2007
Li Jie wrote:I want to call XPCOM and write XPCOM component with D, but I have some problems. This is COM object virtual table structure: And this is XPCOM object virtual table: extern(Windows) only compatible COM, because it added an offset, XPCOM do not need this. When call QueryInterface, it really call AddRef. And I tried extern(C++) and extern(Pascal), no changes. I think that there are 4 solutions: 1. Don't use interface, replace with struct, C style: QueryInterface; Ugly! but it can works. 2. Modify XPCOM interface, remove QueryInterface method: QueryInterface; It can works, replace nsISupports.QueryInterface with MyQueryInterface. But I can't write XPCOM component with D, because no QueryInterface in interface. 3. Hack DMD: Change to: And add pointer to IUnknown: I don't know whether it can work. 4. Hack DMD, add extern(XPCOM), I think it's very difficult to do. Any ideas?I would think a merge of options 3. and 4. would be good. Ie, add either a second interface (IXPUnknown perhaps) or an extern(XPCOM), and modify DMD's InterfaceDeclaration::vtblOffset to know about the special case. It'd be Walter's choice, and I'm not so sure XPCOM would be anywhere near the top of his priority list. *ponder ponder* -- Chris Nicholson-Sauls
Apr 12 2007
Chris Nicholson-Sauls дµ½:Li Jie wrote:My friend, h_rain has found a simple way, rename nsISupports to IUnknown, like this: --------------------------------------- extern(Windows) interface IUnknown { // some methods } alias IUnknown nsISupports; extern(Windows) interface nsIFile : nsISupports { // some methods } --------------------------------------- It works fine, and it is beautiful.I want to call XPCOM and write XPCOM component with D, but I have some problems. This is COM object virtual table structure: And this is XPCOM object virtual table: extern(Windows) only compatible COM, because it added an offset, XPCOM do not need this. When call QueryInterface, it really call AddRef. And I tried extern(C++) and extern(Pascal), no changes. I think that there are 4 solutions: 1. Don't use interface, replace with struct, C style: QueryInterface; Ugly! but it can works. 2. Modify XPCOM interface, remove QueryInterface method: QueryInterface; It can works, replace nsISupports.QueryInterface with MyQueryInterface. But I can't write XPCOM component with D, because no QueryInterface in interface. 3. Hack DMD: Change to: And add pointer to IUnknown: I don't know whether it can work. 4. Hack DMD, add extern(XPCOM), I think it's very difficult to do. Any ideas?I would think a merge of options 3. and 4. would be good. Ie, add either a second interface (IXPUnknown perhaps) or an extern(XPCOM), and modify DMD's InterfaceDeclaration::vtblOffset to know about the special case. It'd be Walter's choice, and I'm not so sure XPCOM would be anywhere near the top of his priority list.
Apr 21 2007