none
Problem Including <windows.h> in C++ CLR Project

    Question

  • Hello

    I have a problem with including #include <windows.h> in C++ CLR project, it just give me 53 error all in the same file objidl.h which i did not build it (Build by Microsoft) like :

    Error 4 error C2872: 'IDataObject' : ambiguous symbol C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\objidl.h 7408

    Error 5 error C3699: '*' : cannot use this indirection on type 'IDataObject' C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\objidl.h 7408

    Error 38 error C2872: 'IDropTarget' : ambiguous symbol c:\program files\microsoft visual studio 8\vc\platformsdk\include\oleidl.h 4408

    and like this...

    So I try to use the same include in anther new CLR form project, but the surprise was no error when i try to build solution, the code work perfectly... So i understand that the problem is in my old project like somethings wrong in properties but i check it all it is the same like the new project properties which include work on...

    Please any information could help me,and let it work in my old project, it is too big i cannot start from the begin, Please Help

    I use Visual Studio 2005 .net pro Edition
    Framework 2.0

    Thank you



    Wednesday, December 06, 2006 4:19 PM

Answers

  • If you add using namespace System::Windows::Forms; before including <windows.h> Visual C++ will be confused because IDataObject is also a managed interface in System::Windows::Forms. You can relegate windows.h declarations to a lower namespace:
     inamespace Win32{#include <windows.h> };and reference windows.h symbols with the Win32 namespace prefix, or move all using statements from .h to .cpp and add a namespace prefix when an ambiguous symbol is used.
    Wednesday, December 06, 2006 9:09 PM

All replies

  • If you add using namespace System::Windows::Forms; before including <windows.h> Visual C++ will be confused because IDataObject is also a managed interface in System::Windows::Forms. You can relegate windows.h declarations to a lower namespace:
     inamespace Win32{#include <windows.h> };and reference windows.h symbols with the Win32 namespace prefix, or move all using statements from .h to .cpp and add a namespace prefix when an ambiguous symbol is used.
    Wednesday, December 06, 2006 9:09 PM
  • Hi,
         I am facing a similar problem for which you have given a solution. But in my case it doesn't work.
    I have replaced the line of code
    #include <windows.h> with using inamespace Win32{#include <windows.h>};

          It now gives another set of errors.


    Eg:  The statement should start with a whitespace


    Regards,
    SG





    Jr. Software Programmer
    Thursday, August 07, 2008 12:26 PM