passing HWND to STL map

This is a discussion on passing HWND to STL map within the C++ Programming forums, part of the General Programming Boards category; Hi, I知 trying to pass a HWND type to a STL map container. I知 using like a void * to ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    2

    passing HWND to STL map

    Hi,

    I知 trying to pass a HWND type to a STL map container.
    I知 using like a void * to pass that parameter.
    I致e coded like this,

    Code:
          Void fun (HWND hOwner, LPCTSTR str, HWND hValue)
         {
           map<const void*, std::string, void *> m1;
           m1.insert(make_pair(hOwner,str),hValue);    //Line 2
        }
    I知 getting a compile time error ( Error Code C2664) in line 2.
    Kindly guide me how to implement this.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I知 getting a compile time error ( Error Code C2664) in line 2.
    Great. And the error is?

    >Kindly guide me how to implement this.
    Well, you're calling the wrong function and any decent reference will show you how to fix it. I'm sure the error tells you this, but you neglected to post it, so the only way I know is by knowing std::map's member functions. You see, it's hard to answer questions without sufficient information. You simply lucked out and got a helper who knows exactly what your problem is at a glance. That's unlikely to be a regular occurrence.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    2

    passing HWND to STL map

    Hi,

    I didn't post the error message because, it had a very lengthy description.
    So, hope the error number would be better to represent it.
    And you are right that my explanations are not clear to help a person to understand the scenario.

    My requirement is to store two values of type HWND and a string value in a map. The key should be a paired value of a HWND 1 and a string, the value type is HWND 2. I tried to do this using a void* pointer. But I got a compiler error about the improper conversion.

    Could you kindly guide me how to do a type cast for HWND type to store it in STL map?

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    If you want the key to be a paired value of HWND and string, you should define the map as:
    Code:
    std::map<std::pair<HWND, std::string>, std::string>
    You could also create your own struct to pair the key together instead of std::pair.

    There is no need to typecast HWND to store it in a map. It will work just as it is.

    To insert, you will need to use make_pair twice. Once to pair the HWND and string to form the key, and then again to pair that result with the string value.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 05:23 AM
  3. My first "real" windows app
    By JoshR in forum Windows Programming
    Replies: 2
    Last Post: 07-28-2005, 07:40 AM
  4. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 06:48 PM

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