How do I fix LNK2022 error when building a C++ unmanaged application in VS2008 using /clr option to enable mixed mode

I have a unmanaged C++ application that builds just fine in Visual Studio 2003.  I migrated this application to VS 2008 and have set the /clr option to enable mixed mode (managed and unmanaged) for future development.  After getting rid of several error messages, I am now left with one:  error

stdafx.obj : LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (CCommDlgWrapper): (0x02000356)

which I just cannot figure out.  I've searched the net and from what I understand it is most likely due to some badly designed structs and that the file mentioned in the error (stdafx.obj?) should be opened in Ildasm to figure out the duplicate struct information.  However, opening this file in Ildasm returnes no information.

Any help would be greatly appreciated
steinstein01Software developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I recently ran into this with a converted project, and it was very painful to fix.  I ended up having to review all the cpp files it complained about and redo the #include statements to make sure headers were not included twice and were in the correct order.  In your case concentrate on the header defining CCommDlgWrapper.

I, too, was not helped by ildasm.

In another case (I recently converted a host of old projects) it was fixed by simply doing a Rebuild All.

I realize this does not help you directly, but I don't think there's a quick-and-easy way out of it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
steinstein01Software developerAuthor Commented:
Thanks for your reply.  Unfortunately, Rebuild All does not help in my case.  And the "funny" thing is, I have no idea where CCommDlgWrapper is coming from or where to even find that file.   But I'll take your advice and work on the "include" and I'll post how it goes.  Thanks again.
steinstein01Software developerAuthor Commented:
Yes, the solution was in the #include stuff.  I had some warnings during compilation regarding #include "ado.h" and #include "adox.h" being skipped in predefined headers - these were not in the StdAfx.h file.  So I just took a chance and put these two #include in the StdAfx.h file and that did it.
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Are you using any #imports?  That ...Wrapper thing sounds familiar but it's been way too long since I did any MFC/ATL programming and I can't remember...
I'll have to make a note of that one for future reference as well.  I wish I could find a good explanation of what is different in te newer compilers (2005 and 2008 have this issue when converting 2003 apps) that causes this problem as it is a pain in the neck to track down.

I'm glad you were able to figure it out without too much pain.
I was getting this error because of multiple defined  Dllmain functions, especially if you are also using MFC and managed code. Removing these solved the problem
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.