help me using lib from Visual C++ 6

This is a discussion on help me using lib from Visual C++ 6 within the Windows Programming forums, part of the Platform Specific Boards category; I am starting myself in the use of microsoft's command-line lib... I made a simple lib which creates a window ...

  1. #1
    Former Member
    Join Date
    Oct 2001
    Posts
    955

    Unhappy help me using lib from Visual C++ 6

    I am starting myself in the use of microsoft's command-line lib...

    I made a simple lib which creates a window by using classes, it has an interesting member function: RegisterClass(try and guess what it does ).
    I want the user to use this function to register a single class, specifying the icon, if the hIcon is NULL, I want it to use the default icon, which is a resource.
    the part of the code is shown below:

    int cMyWindow::RegisterClass(LPCSTR ClassName,HICON hIcon)
    {
    WNDCLASSEX wc;
    int ret;
    this->cClassName = new(char[strlen(ClassName)+1]);
    strcpy(this->cClassName,ClassName);
    wc.cbClsExtra=0;
    wc.cbSize=sizeof(WNDCLASSEX);
    wc.cbWndExtra=0;
    wc.hbrBackground=(HBRUSH)(GetStockObject(BLACK_BRU SH));
    wc.hCursor=LoadCursor(NULL,IDC_ARROW);
    //THE INTERESTING STUFF STARTS HERE
    if(hIcon==NULL)
    {
    int id=IDI_ICON1;
    LPTSTR res=MAKEINTRESOURCE(id);
    wc.hIcon=LoadIcon(this->hInstance,res);
    ret=GetLastError();
    }
    else
    {
    wc.hIcon=hIcon;
    ret=GetLastError();
    }
    //THE INTERESTING STUFF ENDS HERE
    wc.hIconSm=NULL;
    wc.hInstance=this->hInstance;
    wc.lpfnWndProc=WndProc;
    wc.lpszClassName=ClassName;
    wc.lpszMenuName=NULL;
    wc.style=0;
    if(RegisterClassEx(&wc))
    {
    return 1;
    }
    else
    {
    throw cError("Class Registration failed\nError found in Line 160");
    return 0;
    }
    }

    the
    wc.hIcon=LoadIcon(this->hInstance,res);

    used to be
    wc.hIcon=LoadIcon(this->hInstance,MAKEINTRESOURCE(IDI_ICON1);

    but I split it up to see what happened!

    when i run it, it runs ok until the MAKEINTRESOURCE, it returns
    0x0000060, or something like that (i guess it works!)

    but the LoadIcon returns 0!

    when I call GetLastError, it returns 0 (Function success)

    I don't know what's going on here.

    the command line I use to create the lib is:
    lib /MACHINE:IX86 hello.obj hello.res

    so I don't think that the problem is that I am not linking the resource file!

    and, when I run the program which uses the lib, it works, but it doesn't show my icon, it shows the messy windows icon!

    Help me please
    Last edited by oskilian; 10-06-2001 at 02:57 PM.

  2. #2
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    c'mon, help me out here!

    Oskilian

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    72
    So may be the problem is that the resources are binded to the executable at the final link stage.

    instead of linking the .RES file with your lib - try to add it with your fineal executable or another approach is to build a dll instead of the lib. The dill can have own resources and you also can export all the things from your dll in the same fashion as from the lib.

  4. #4
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    thanks, I'll try the first one, the second one, no i dont want to be carrying a DLL, since lots of people are working on this project.

    Oskilian

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

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