i did 1 code for give me the menu position. but i'm getting problems compare the LPSTR or LPCSTR with string :(

int GetMenuPosition(HMENU menu, string caption)
    {
        int i=0;
        for(i=0; i<GetMenuItemCount(menu)-1;i++)
        {
            MENUITEMINFO  s= {0};
            s.cbSize=sizeof(MENUITEMINFO );
            s.fMask=MIIM_STRING;
            s.cch=strlen(strCaption.c_str());
            //s.dwTypeData=(LPSTR)strCaption.c_str();
            GetMenuItemInfo (menu,i, true, &s);
            string b=static_cast<char*>(s.dwTypeData);

            if(b==caption)
                 break;
        }
        MessageBox(NULL,to_string(i).c_str(),"menuposition", MB_OK);
        return i;
    }

can anyone explain to me?

What is the error you are getting? An LPSTR is just a char* and a LPCSTR is a const char*. Since std::string has operaotr==(std::string, const char*) you should be able to get rid of line 12 and change line 14 to if (caption == s.dwTypeData)

int GetMenuPosition(HMENU menu, string caption)
    {
        int i=0;
        for(i=0; i<GetMenuItemCount(menu)-1;i++)
        {
            MENUITEMINFO  s= {0};
            s.cbSize=sizeof(MENUITEMINFO );
            s.fMask=MIIM_STRING;
            s.cch=strlen(strCaption.c_str());
            GetMenuItemInfo (menu,i, true, &s);

            if(caption == s.dwTypeData)
                 break;
        }
        MessageBox(NULL,to_string(i).c_str(),"menuposition", MB_OK);
        return i;
    }

a memory error.
'the program stops responding' and the OS closes the program

What is the value of s.cch after you call GetMenuItemInfo()?

see these code too:

 Set(string text)
        {
            char d[255];
            MENUITEMINFO  s;
            s.cbSize=sizeof(MENUITEMINFO );
            s.fMask=MIIM_STRING;
            s.dwTypeData=(LPSTR)text.c_str();
            if(primeiromenu==true)//these menu handle is tested
            {
               SetMenuItemInfo (mnuBar,GetMenuPosition(mnuBar,strCaption), true, &s);
            }
            else if(ispopup==true)
                SetMenuItemInfo (MenuPopup,GetMenuPosition(MenuPopup,strCaption), true, &s);
            else
                SetMenuItemInfo (MenuHandle,ID, false, &s);
            DrawMenuBar(Mainwindow);
            strCaption=text;
        }

(primeiro -> first)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.