Newbie question: COM programming and linking to Windows libraries

Jarrett Billingsley jarrett.billingsley at gmail.com
Wed Mar 11 14:45:49 PDT 2009


On Wed, Mar 11, 2009 at 5:31 PM, Patrick Kristiansen
<patrick.kristiansen at gmail.com> wrote:
>  Apparently, one of the first things to do is call CoInitialize(...), and this is where my problem arises.

That's funny, I've never had to call it when using DirectX interfaces.
 Maybe it's something peculiar to DirectX?

> CoInitialize is located in ole32.lib, but in the Tango distribution of DMD, there is no ole32.lib included. I thought, since I have the Windows SDK (x64) installed, that I could just link directly to the ole32.lib included there.
>
> Now, this is probably obvious to some people - but not to me. Why doesn't this work? Why does OPTLINK fail and tell me that the format of the .lib file is wrong? Is it because Digital Mars compilers produce .lib files in a different format?

That's exactly the reason.  DM uses the OMF format, an old object
format that MS compilers used to generate before they switched to
COFF.  Of course they've been using COFF since something like VC5 or
VC6, so none of the object files that MS distributes are compatible
with DM compilers anymore.  Also, DM compilers do only generate 32-bit
objects and executables, though the object file format discrepancy has
always been a problem.

You should be able to generate an OMF import library for ole32 from
the ole32.dll in windows\system32 (or wherever that is on Win64).  You
can use the DM implib utility (contained in the BUP here:
http://ftp.digitalmars.com/bup.zip) to do so.  Something like:

implib /system ole32.lib ole32.dll

should do it.


More information about the Digitalmars-d-learn mailing list