Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I keep running into a nasty compiler error telling me that I am doing something seriously wrong.
The error I get is: error MIDL2025 : syntax error : expecting a type specification near "tagDevice". The following struct is defined in the IDL which definitely has something to do with it as the same compiles (and works) without any problem from a regular .h / .cpp file.

typedef struct tagDevice
{
    tagDevice()
    {
        DeviceName = NULL;
        DeviceId  = -1;
    }

    BSTR    DeviceName;
    int     DeviceId;
}Device;


Remove the constructor and it all compiles OK but I don't want to have to initialize the values manually each and every time.

Anybody got an idea of how I can get this to work?
Posted

1 solution

It's generally a good idea not to have a constructor on a structure anyway and treat it like plain old data. I do believe COM expects C-style structs which do not support constructors, so that may explain the error you're seeing.
 
Share this answer
 
Comments
Addy Tas 21-Dec-11 2:26am    
It seems that your answer is the only answer and therefore must be the acceptable answer. Normally I don't add constructors to structs but in this case it seemed that as the struct is already used all over the place and the BSTR DeviceName is causing a mem leak I figured that init the value might already help, then on destruction free the mem. Guess I have to do this manually all over the place.

Anyway; thanks for the answer.Cheers, AT
Albert Holguin 21-Dec-11 10:10am    
I think it works fine in C++ (constructors in structures), but when using it with COM it won't work.
Albert Holguin 21-Dec-11 10:12am    
You can always make an initialization function somewhere that you call... make it a global C-style function or make it a static in a class so you can call it independent of the class instance.
Addy Tas 21-Dec-11 13:27pm    
Hi, I already figured out that it would come down to something like that. The nasty part of this is that I wanted to have a destructor that automatcally cleaned up the allocated mem when it goes out of scope or is deleted.
So once and a while i get so used to the comfort of C++ ( or better yet c#) that i can't figure out why we had to do everything manually in the (not so) distant past.

Thanks, AT
Amir Mahfoozi 17-Jan-12 0:33am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900