Visual C++

This is a discussion on Visual C++ within the Windows Programming forums, part of the Platform Specific Boards category; Question?? In Visual C++ 6.0, shouldn't the compiler search subdirectories for specific header files and libraries. Situation: By default, VC++ ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    Visual C++

    Question??
    In Visual C++ 6.0, shouldn't the compiler search subdirectories for specific header files and libraries. Situation:

    By default, VC++ has the path of Visual Studio/Include directory in the header path for the compiler. I installed the core SDK and moved the include folder from SDK to the Include folder within Visual Studio. So it reads Visual Studio/Include/Include. I get an error that the header file included does not exist. The header file is in the 2nd Include folder. If I add the 2nd Include folder the the compiler path, it compiles. I get 102 errors but that is another problem. Trying to find out if the compiler searches subdirectories for header and library files?????

    Thanks
    Kendal

  2. #2
    NoDude
    Guest
    well if it didnt work in that sub directiry then uve answered ur own question ^_^

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    Is it SUPPOSED to work that way??????

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Consider typical includes for an opengl application:
    Code:
    #include <windows.h>
    #include <gl\gl.h>                       
    #include <gl\glu.h>
    ie you have to specify the relative path to the subdirectory OR add that path to the include path list in 'Tools->Options->Directories'.

    For your PSDK install, make sure that the new include and lib paths are first in the include and lib path lists as that is the order of search.

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    errors

    what would cause these 2 errors. I have installed the core SDK and thought it would include all the appropriate header files. All I did was add #include gdiplus.h to a working "hello world" program and get 102 errors. All errors take place in "gdiplusinit.h and gdiplusimaging.h. Here are 2 of the first errors I get.

    c:\program files\microsoft visual studio\vc98\include\include\gdiplusinit.h(32) :error C2065: 'ULONG_PTR' : undeclared identifier
    c:\program files\microsoft visual studio\vc98\include\include\gdiplusinit.h(32) : error C2065: 'token' : undeclared identifier

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    This works:
    Code:
    //Filename: src.cpp
    //Simple GDI+ example. Ken Fitlike
    #include <windows.h>             //include all the basics
    #include <gdiplus.h>             //requires linking with GdiPlus.lib
    
    ULONG_PTR gdiplusToken;
    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR lpCmdLine,int nCmdShow)
    {
    HWND    hwnd;
    MSG     Msg;     
    
    TCHAR chClassName[]=TEXT("SIMPLEWND");
    WNDCLASSEX wcx;   
    wcx.cbSize           = sizeof(WNDCLASSEX);              
    wcx.style            = CS_HREDRAW|CS_VREDRAW;           
    wcx.lpfnWndProc      = (WNDPROC)WndProc;                
    wcx.cbClsExtra       = 0;                               
    wcx.cbWndExtra       = 0;                              
    wcx.hInstance        = hInst;                       
    wcx.hIcon            =(HICON)LoadImage(0, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED);                         
    wcx.hCursor          =(HCURSOR)LoadImage(0, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);                         
    wcx.hbrBackground    =(HBRUSH)(COLOR_BTNFACE+1);       
    wcx.lpszMenuName     = NULL;                            
    wcx.lpszClassName    = chClassName;                     
    wcx.hIconSm          = NULL;                            
    //Register wnd
    if (!RegisterClassEx(&wcx))
        {
        //Registration failure
        MessageBox( NULL,
                    TEXT("Failed to register wnd class"),
                    TEXT("ERROR"),
                    MB_OK|MB_ICONERROR);
        return FALSE;
        }
    
    hwnd=CreateWindowEx(0,                                 
                        chClassName,                        
                        TEXT("Simple GDI+ Example"),              
                        WS_OVERLAPPEDWINDOW|WS_VISIBLE,     
                        GetSystemMetrics(SM_CXSCREEN)/4,    
                        GetSystemMetrics(SM_CYSCREEN)/4,    
                        GetSystemMetrics(SM_CXSCREEN)/2,    
                        GetSystemMetrics(SM_CYSCREEN)/2,    
                        NULL,                               
                        NULL,                               
                        hInst,                          
                        NULL);
    if (!hwnd)
        {
        //wnd creation failure
        MessageBox( NULL,
                    TEXT("Failed to create wnd"),
                    TEXT("ERROR"), 
                    MB_OK|MB_ICONERROR);
        return FALSE;
        }
    
    Gdiplus::GdiplusStartup(&gdiplusToken,&gdiplusStartupInput,NULL);	//init gdi+
    
    //start message loop
    while (GetMessage(&Msg,NULL,0,0)>0)
        {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
        }
    
    Gdiplus::GdiplusShutdown(gdiplusToken);	//release gdi+
    
    return Msg.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {
    switch (uMsg)
        {
        case WM_PAINT:
            {
            PAINTSTRUCT ps;
            WCHAR wcTxt[]=L"Simple GDI+";
            BeginPaint(hwnd,&ps);
                Gdiplus::Graphics *gs=new Gdiplus::Graphics(ps.hdc);
    			
                //create an underlined font
                Gdiplus::Font myFont(L"system",14,Gdiplus::FontStyleUnderline);
                Gdiplus::Font fntBlack(L"system",12);
                Gdiplus::PointF origin(100.0f, 100.0f);
                Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255,0,0,255));
    
                gs->DrawString(wcTxt,lstrlenW(wcTxt),&myFont,origin,&blackBrush);
                delete gs;
            EndPaint(hwnd,&ps);
            return 0;
            }
        case WM_DESTROY:
            PostQuitMessage(0); 
            return 0;
        default:
            return DefWindowProc(hwnd,uMsg,wParam,lParam);  
        }
    }
    If you can't get the the above code to work then your include/lib paths are screwed or you haven't added the gdiplus.lib to 'project->settings->link'.

    edit: tarting up code.
    Last edited by Ken Fitlike; 03-07-2003 at 07:17 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    Linker Errors

    Hello Again Everybody.
    It's me again. I have copy and pasted the code that Ken posted that includes the GDI+ header file and get a bunch of linker errors. I figure if I can figure out the problem causing these linker errors I can fix my other program linker errors. Here are some of the errors I am getting, all of them being "unresolved external symbol" errors:

    Code:
    Test.obj : error LNK2019: unresolved external symbol _GdiplusShutdown@4 referenced in function _WinMain@16
    Test.obj : error LNK2019: unresolved external symbol _GdiplusStartup@12 referenced in function _WinMain@16
    Test.obj : error LNK2019: unresolved external symbol _GdipFree@4 referenced in function "public: static void __cdecl Gdiplus::GdiplusBase::operator delete(void *)" (??3GdiplusBase@Gdiplus@@SAXPAX@Z)
    Test.obj : error LNK2019: unresolved external symbol _GdipAlloc@4 referenced in function "public: static void * __cdecl Gdiplus::GdiplusBase::operator new(unsigned int)" (??2GdiplusBase@Gdiplus@@SAPAXI@Z)
    Test.obj : error LNK2019: unresolved external symbol _GdipCreateSolidFill@8 referenced in function "public: __thiscall Gdiplus::SolidBrush::SolidBrush(class Gdiplus::Color const &)" (??0SolidBrush@Gdiplus@@QAE@ABVColor@1@@Z)
    Test.obj : error LNK2019: unresolved external symbol _GdipDeleteBrush@4 referenced in function "public: virtual __thiscall Gdiplus::Brush::~Brush(void)" (??1Brush@Gdiplus@@UAE@XZ)
    Test.obj : error LNK2019: unresolved external symbol _GdipCloneBrush@8 referenced in function "public: virtual class Gdiplus::Brush * __thiscall Gdiplus::Brush::Clone(void)const " (?Clone@Brush@Gdiplus@@UBEPAV12@XZ)
    Test.obj : error LNK2019: unresolved external symbol _GdipCreateFromHDC@8 referenced in function "public: __thiscall Gdiplus::Graphics::Graphics(struct HDC__ *)" (??0Graphics@Gdiplus@@QAE@PAUHDC__@@@Z)
    Test.obj : error LNK2019: unresolved external symbol _GdipDeleteGraphics@4 referenced in function "public: __thiscall Gdiplus::Graphics::~Graphics(void)" (??1Graphics@Gdiplus@@QAE@XZ)
    Test.obj : error LNK2019: unresolved external symbol _GdipDrawString@28 referenced in function "public: enum Gdiplus::Status __thiscall Gdiplus::Graphics::DrawString(unsigned short const *,int,class Gdiplus::Font const *,class Gdiplus::PointF const &,class Gdiplus::Brush const *)" (?DrawString@Graphics@Gdiplus@@QAE?AW4Status@2@PBGHPBVFont@2@ABVPointF@2@PBVBrush@2@@Z)
    Test.obj : error LNK2019: unresolved external symbol _GdipCreateFont@20 referenced in function "public: __thiscall Gdiplus::Font::Font(unsigned short const *,float,int,enum Gdiplus::Unit,class Gdiplus::FontCollection const *)" (??0Font@Gdiplus@@QAE@PBGMHW4Unit@1@PBVFontCollection@1@@Z)
    Test.obj : error LNK2019: unresolved external symbol _GdipCreateFontFamilyFromName@12 referenced in function "public: __thiscall Gdiplus::FontFamily::FontFamily(unsigned short const *,class Gdiplus::FontCollection const *)" (??0FontFamily@Gdiplus@@QAE@PBGPBVFontCollection@1@@Z)
    Test.obj : error LNK2019: unresolved external symbol _GdipGetGenericFontFamilySansSerif@4 referenced in function "public: static class Gdiplus::FontFamily const * __cdecl Gdiplus::FontFamily::GenericSansSerif(void)" (?GenericSansSerif@FontFamily@Gdiplus@@SAPBV12@XZ)
    Test.obj : error LNK2019: unresolved external symbol _GdipDeleteFontFamily@4 referenced in function "public: __thiscall Gdiplus::FontFamily::~FontFamily(void)" (??1FontFamily@Gdiplus@@QAE@XZ)
    Test.obj : error LNK2019: unresolved external symbol _GdipDeleteFont@4 referenced in function "public: __thiscall Gdiplus::Font::~Font(void)" (??1Font@Gdiplus@@QAE@XZ)
    .\Debug/Test.exe : fatal error LNK1120: 15 unresolved externals
    I have tried this with Visual C++ 6.0 and have even gone to Visual Studio .NET. The preceding errors come from the .NET build. The program compiles but the build returns the linker errors. I have made sure time and time again that the GDIPLUS.LIB and the GDIPLUS.H files do exist in the folders that I include in the path. I go to TOOLS->OPTIONS->C++DIRECTORIES under PROJECTS and set the appropriate library and include path for the GDIPLUS files. I set them first on top of that. I have tried everything I can think of and need some assistance if somebody can help PLEASE. Does anyone have any idea what could be causing these errors.

    Extremely thankful
    Kendal

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    As I said, "or you haven't added the gdiplus.lib to 'project->settings->link'."

    Just setting the search path is not enough; you must explicitly include the gdiplus.lib in the linker settings as described above. (it may be different for visual c++ .net but that's what you need to look for: a 'link' or 'linker' settings).

    For future reference, the reason that those kind of linker errors occur is because some library has not been included in the linker options for that particular project. The particular lib required for a particular function is usually listed in msdn under the description of that function.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #9
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    #pragma comment(lib, "gdiplus.lib")



    Geez, Mr. Fitlike - way to be super obscure and unhelpful with the library thing

  10. #10
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Originally posted by -KEN-
    #pragma comment(lib, "gdiplus.lib")



    Geez, Mr. Fitlike - way to be super obscure and unhelpful with the library thing
    Thanks, Real -Ken-, that would be also be a way to link the lib, though not one I like to use myself.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  11. #11
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    Thanks

    Thanks Ken Fitlike,

    You were partially right. I thought I had the gdiplus.lib added to all of the settings but I was missing one. I figured it out in 6 and .NET. Once I did get the library added, I was still getting the error. In order to fix it, I had to rearrange the order of my path includes. On my other programs I had rearrange the order of my include files. Anyway, you were right and I thank you. Now according to MSDN and displaying bitmaps, they give me an example like this:

    Graphics graphics(hdc);
    Image image("misc0001.tif");
    graphics.DrawImage(&image,0,0);

    Does this look right. It sort of resembles Java. Anyway, when I try it, it give me errors like

    error C2065: 'Graphics' : undeclared identifier
    error C2146: syntax error : missing ';' before identifier 'graphics'
    error C2065: 'graphics' : undeclared identifier
    error C2065: 'Image' : undeclared identifier
    error C2146: syntax error : missing ';' before identifier 'image'

    MSDN is pretty vague on their explanation, but they state that all of this is a part of GDIPlus.lib. I mad sure that the paths and the linker settings were exactly as above and got it to work without the above 3 lines but I get these new errors. I don't think that displaying an image in C++ can be that easy but that is just an example that MSDN gave. Once again I appreciate all of the help and advise given to me.

    Thanks a million
    Kendal

  12. #12
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    Image viewing

    If anybody is interested in an image viewing program in C++, here is one that I found that is pretty complete. It is located here: http://msdn.microsoft.com/msdnmag/is...c/default.aspx

    I have looked at the code and it does not look traditional. I was trying to find the entry point of the program so that I can get it to display my own opening image but have no luck. Anyway, here is an image program for anyone.

  13. #13
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227

    Re: Thanks

    Originally posted by gvector1

    Now according to MSDN and displaying bitmaps, they give me an example like this:

    Graphics graphics(hdc);
    Image image("misc0001.tif");
    graphics.DrawImage(&image,0,0);

    Does this look right. It sort of resembles Java. Anyway, when I try it, it give me errors like

    error C2065: 'Graphics' : undeclared identifier
    error C2146: syntax error : missing ';' before identifier 'graphics'
    error C2065: 'graphics' : undeclared identifier
    error C2065: 'Image' : undeclared identifier
    error C2146: syntax error : missing ';' before identifier 'image'
    Gdiplus class, functions etc are declared/defined within Gdiplus namespace.
    You'll probably find that msdn examples will have a 'using namespace Gdiplus' directive while in the example I posted earlier in this thread I have declared, for example, a pointer to a Graphics object like so:
    Code:
    Gdiplus::Graphics *gs
    .

    For simple examples it's ok to use the 'using namespace Gdiplus' or you can bring other objects into scope with eg.
    Code:
    using Gdiplus::Graphics;
    Graphics gs;
    Personally, I use full syntax; it removes any ambiguity (for me) regarding what is being declared and used.

  14. #14
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    I fully understand your reply and it makes sense, whenever I try your approach, I get an error message:

    error C2653: 'Gdiplus' : is not a class or namespace name

    when I know that it is. I checked the Gdiplus.h file to make sure.

  15. #15
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    It might be an idea to zip & attach your code/project (if it's not too big).

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 09:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21