digitalmars.D - COM typelibs in D
- James Dunne (18/18) Dec 19 2004 Hello everyone,
- James Dunne (7/7) Dec 20 2004 Nobody does COM programming in D? Not that I'm surprised or anything ;)...
- J C Calvarese (11/19) Dec 20 2004 I've tried to use some COM objects in the past, but it's clear I don't
- James Dunne (9/28) Dec 20 2004 Justin,
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (7/12) Dec 23 2004 Hi, IIRC the vtable of a D object is COM compatible. If you create a cla...
- Jason Jasmin (5/13) Dec 21 2004 It's been a while since I've worked with COM, but IIRC there are some
- James Dunne (8/21) Dec 21 2004 I didn't know what I was looking for. I just took a random stab at why ...
- Andrey Taranov (34/46) Dec 23 2004 No, that's not all you're looking for. VB works with so-called *dual*
- J C Calvarese (4/6) Dec 24 2004 Try using:
- J C Calvarese (13/21) Dec 20 2004 I'm not sure this is any help for what you're trying to do, but the
Hello everyone, Anyone know anything about using Windows COM objects in D? I've seen the examples included with the compiler, and they are somewhat helpful, but I'm not going to use COM to communicate between two D programs. I need to write a D COM object to interface with VB6 and VBA (mainly for Excel). VB needs a typelib to work with in order to create any COM object, something the D example programs don't give you. I've had experience with Visual C++ and developing COM objects which work with VB6 and VBA, but its all done with ATL, MFC, MIDL, and a lot of terrible hackish compiler magic. Maintaining my C++ code for this COM object is a nightmare. It'd be much easier (and cleaner) to tackle this in D! I was wondering if there exists an easy way to generate typelibs for D COM objects? P.S. - Also, what are the rammifications of the garbage collector on COM objects?? If I pass something off to VB to use, will the garbage collector yank it back and make VB puke profusely? Regards, James Dunne
Dec 19 2004
Nobody does COM programming in D? Not that I'm surprised or anything ;). Also, a solution NOT involving the MSVC build tools would be welcome. Perhaps I'll try and debunk the TLB file format? Then somehow stuff it as a resource in the DLL? Gotta read up on this stuff. Please, if anyone's got anything, let me know :) Regards, James Dunne
Dec 20 2004
James Dunne wrote:Nobody does COM programming in D? Not that I'm surprised or anything ;). Also, a solution NOT involving the MSVC build tools would be welcome. Perhaps I'll try and debunk the TLB file format? Then somehow stuff it as a resource in the DLL? Gotta read up on this stuff. Please, if anyone's got anything, let me know :) Regards, James DunneI've tried to use some COM objects in the past, but it's clear I don't know what I'm doing. :( I get the impression that you're trying to create your own new COM object (perhaps in an ActiveX-style). I have no idea how you'd do that, but I did find a link to a program that apparently will show what an existing .tlb contains: http://www.cheztabor.com/tlb2xml/ (I haven't tested it.) Interesting, but not necessarily useful. -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Dec 20 2004
Justin, Thanks for your replies, but none of those seem entirely useful for my problem. I'm interested in creating a COM object from scratch with a type library (tlb) inside it. MSVC does this automatically with the class wizards and application wizards, but it's all done with MFC and ATL. A good example of what I want to do is the dserver example program in the dmd/examples folder of the D compiler release. It links the COM object as a windows DLL, but doesn't include the type library. In article <cq822p$1gig$1 digitaldaemon.com>, J C Calvarese says...James Dunne wrote:Nobody does COM programming in D? Not that I'm surprised or anything ;). Also, a solution NOT involving the MSVC build tools would be welcome. Perhaps I'll try and debunk the TLB file format? Then somehow stuff it as a resource in the DLL? Gotta read up on this stuff. Please, if anyone's got anything, let me know :) Regards, James DunneI've tried to use some COM objects in the past, but it's clear I don't know what I'm doing. :( I get the impression that you're trying to create your own new COM object (perhaps in an ActiveX-style). I have no idea how you'd do that, but I did find a link to a program that apparently will show what an existing .tlb contains: http://www.cheztabor.com/tlb2xml/ (I haven't tested it.) Interesting, but not necessarily useful. -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Dec 20 2004
On Tue, 21 Dec 2004 04:20:28 +0000 (UTC), James Dunne <jdunne4 bradley.edu> wrote:Thanks for your replies, but none of those seem entirely useful for my problem. I'm interested in creating a COM object from scratch with a type library (tlb) inside it. MSVC does this automatically with the class wizards and application wizards, but it's all done with MFC and ATL.Hi, IIRC the vtable of a D object is COM compatible. If you create a class that has the COM object's functions in the same order as in the COM object implementation you need to create an instance and than can access it via the class interface. Sorry, no code. But I think that's how the process can work. Robert
Dec 23 2004
James Dunne wrote:Nobody does COM programming in D? Not that I'm surprised or anything ;). Also, a solution NOT involving the MSVC build tools would be welcome. Perhaps I'll try and debunk the TLB file format? Then somehow stuff it as a resource in the DLL? Gotta read up on this stuff. Please, if anyone's got anything, let me know :) Regards, James DunneIt's been a while since I've worked with COM, but IIRC there are some Win32 API calls which can create a TLB. Fairly cryptic stuff, but I do remember seeing something which looked like it would create TLB's. Jason
Dec 21 2004
I didn't know what I was looking for. I just took a random stab at why VB wasn't liking to call my COM object. Turns out VB works with COM objects that implement the IDispatch interface, which is all I need instead. IUnknown is defined in phobos, but IDispatch isn't. Anyone got an IDispatch interface coded for D? That'd be awesome! In article <cq98i0$2uq1$1 digitaldaemon.com>, Jason Jasmin says...James Dunne wrote:Regards, James DunneNobody does COM programming in D? Not that I'm surprised or anything ;). Also, a solution NOT involving the MSVC build tools would be welcome. Perhaps I'll try and debunk the TLB file format? Then somehow stuff it as a resource in the DLL? Gotta read up on this stuff. Please, if anyone's got anything, let me know :) Regards, James DunneIt's been a while since I've worked with COM, but IIRC there are some Win32 API calls which can create a TLB. Fairly cryptic stuff, but I do remember seeing something which looked like it would create TLB's. Jason
Dec 21 2004
James Dunne wrote:I didn't know what I was looking for. I just took a random stab at why VB wasn't liking to call my COM object. Turns out VB works with COM objects that implement the IDispatch interface, which is all I need instead. IUnknown is defined in phobos, but IDispatch isn't.No, that's not all you're looking for. VB works with so-called *dual* interfaces, that is, implemented both directly and via IDispatch. Here's a quote from Platform SDK, IDL Reference:The [dual] attribute identifies an interface that exposes properties and methods through IDispatch and directly through the VTBL.But VB can also work with plain interfaces as well. The difference is not too simple to explain, so I'll give just a few points: * when you declare an object like Dim obj As Object, and when you create it with CreateObject("progid") -- VB accesses the object through IDispatch; * when you declare an object like Dim myfoo As Foo and create it with Set myfoo = New Foo -- VB doesn't use IDispatch at all, it accesses Foo vtbl directly; * calls through IDispatch are dynamic binding: methods are called by ID (as if they were called by name); * calls through vtbl (as you all understand) are direct calls down to native code level, this is static binding; * VB uses typelibs only when it doesn't use IDispatch. I.e. only for static binding (and for IntelliSense also). So if you are not satisfied with a dynamic only bindings to your interfaces, you still need a typelib. Typelibs are created by compiling an interface definition written in Microsoft variant of IDL (interface definition language). The compiler is called MIDL and is included in the SDK. And the first thing to try is to make an IDL definition for your D COM-classes. By the way, the resulting binary typelib can be stored in the .exe as a resource, and it is indeed a common and recommended practice. Another way of creating a typelib is to use type building interfaces of COM itself. Here is another quote:Object browsers, compilers, and similar tools access type libraries through the interfaces ITypeLib, ITypeLib2, ITypeInfo, ITypeInfo2 and ITypeComp. Type library tools (such as MIDL) can be created using the interfaces ICreateTypeLib, ICreateTypeLib2, ICreateTypeInfo and ICreateTypeInfo2.But if you go this way, you should mind the VB requirements: a minival COM interface usable from VB is inherited from IDispatch, which is inherited from IUnknown. So the start of vtbl (and the typelib interface description) should contain all the IUnknown and IDispatch methods. I hope this is all understandable enough... Regards, Andrey
Dec 23 2004
In article <cqb7vk$1un9$1 digitaldaemon.com>, James Dunne says...IUnknown is defined in phobos, but IDispatch isn't. Anyone got an IDispatch interface coded for D? That'd be awesome!Try using: http://svn.dsource.org/svn/projects/core32/trunk/core32/win32/com/OAIDL.d jcc7
Dec 24 2004
James Dunne wrote:Hello everyone, Anyone know anything about using Windows COM objects in D? I've seen the examples included with the compiler, and they are somewhat helpful, but I'm not going to use COM to communicate between two D programs. I need to write a D COM object to interface with VB6 and VBA (mainly for Excel).I'm not sure this is any help for what you're trying to do, but the L8night project at dsource (http://www.dsource.org/projects/l8night/) has an example of an embedded IE browser using MSHTMHST. http://svn.dsource.org/svn/projects/l8night/trunk/l8night/dfc/examples/browser/main.d In order to see it in action, you'll need to download both L8night and Core32 and set up the paths in the batch files to match your system. http://svn.dsource.org/svn/projects/core32/downloads/core32_2004.12.20.zip http://svn.dsource.org/svn/projects/l8night/downloads/l8night_2004.12.20.zipI was wondering if there exists an easy way to generate typelibs for D COM objects?There probably is, but I don't know what it is. -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Dec 20 2004