views:

137

answers:

1

Hi all,

I have been having a prolonged encounter with the beast known as COM Interop...

I am currently trying to generate a .tlb from a .idl file generated by the OLE/COM Object Viewer. However when trying to run Midl.exe to compile it I get an error:

.\Sim.API.IDL(236) : error MIDL2025 : syntax error : expecting a type s
pecification near "ImportFileStatus"

My .idl file is more that 1000 lines long so I don't particularly want to post it here however, I believe the Part of interest is:

typedef [uuid(980B172E-19C1-389A-BB74-29A54737C5B4), version(1.0)    ,
  custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "Sim.API.ImportFileResult")    
 ]
 struct tagImportFileResult {

  ImportFileStatus _status;

  LPSTR _message;
 } ImportFileResult;

Then Several lines later...

 typedef [uuid(A4B9A0FF-A2D4-3EC5-AB7E-69311B9122C8), version(1.0)    ,
  custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "Sim.API.ImportFileStatus")    
 ]
 enum {
  ImportFileStatus_Success = 0,
  ImportFileStatus_VersionMismatch = 1,
  ImportFileStatus_Failure = 2
 } ImportFileStatus;

I have a Feeling that these should be revered in order to fix the Type specification error. However if I do this I get a new problem.

midl\oleaut32.dll : warning MIDL2368 : error generating type library, ignored :
Could not set UUID : tagImportFileResult (0x800288C6)

I am pretty unfamiliar with the idl format and with the use of midl.exe, perhaps there is something blatantly wrong with what I am doing?

As always any help would be greatly appreciated :)

+2  A: 

You are correct, swapping the declarations is required to keep MIDL happy. OleView.exe indeed won't generate declarations in the original order. I think it groups them by kind, the way the type lib is organized.

The message you are getting is just a warning, not an error. It is caused by having an alias for the structure name that's different. You can safely ignore it because code won't use the "tagImportFileResult" identifier. But you can get rid of it by making the tag name the same as the typedef name:

typedef [..] 
   struct ImportFileResult {
   //...
} ImportFileResult;

Here's a KB article on the subject.

Hans Passant
Thanks Hans, I would never have noticed that the second error was simply a warning :P. Incidentally is there a better way to generate IDL's that does not change the order? Also do you know any other useful resources for COM Interop? Thanks again!
Jambobond
Sure, just ask the original author for his .idl file. You'll get one out of two possible responses: "no problem!" or "are you kidding, this is copyrighted software, your license expressly forbids you doing this!". Or you'll never hear anything back, not unlikely given its probable age.
Hans Passant
Actually I am the original author ^^ or at least my company is, Long story but this is basically to get around the 'propput' rather than 'propputref' Issue when using Object Properties. So I have to generate and register the original .dll with Regasm and then edit the .IDL to replace propputref with propput and finally rebuild the tlb with Midl. FUN!!!! :P
Jambobond

related questions