LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C++ from C xmp.h function call: XpmCreatePixmapFromData (https://www.linuxquestions.org/questions/programming-9/c-from-c-xmp-h-function-call-xpmcreatepixmapfromdata-4175627528/)

BW-userx 04-12-2018 11:25 AM

C++ from C xmp.h function call: XpmCreatePixmapFromData
 
I am writing this little dockapp in C++ converting what I can from C using the, if you've heard of it, wmgeneral.c file to help create the dockapp window.

within it are a bunch of hand written functions that where using
Code:

char *something = "whatever";
getting,
Code:

ISO C++ forbids converting a string constant to 'char*'
so I changed everything to
Code:

char const *something = " whatever";
starting from the xpm file and modding it to this within the file.
Code:

static char const * bgmask_xpm[] = {

now I have an outside function call coming from xmp.h called.
Code:

FUNC(XpmCreatePixmapFromData, int, (Display *display,
                                        Drawable d,
                                        char **data,
                                        Pixmap *pixmap_return,
                                        Pixmap *shapemask_return,
                                        XpmAttributes *attributes));

https://github.com/winlibs/libxpm/bl...lude/X11/xpm.h

how do I get that function to conform from a char **data to a char const **data without having to re-code their code?

I'm getting this
Code:


/home/userx/C++Projects/wmslideshow/wmgeneral.cpp|178|error: invalid conversion from 'const char**' to 'char**' [-fpermissive]|
/usr/include/X11/xpm.h|292|note:  initializing argument 3 of 'int XpmCreatePixmapFromData(Display*, Drawable, char**, Pixmap*, Pixmap*, XpmAttributes*)'|

which is the last error I got to get rid of before I can move on with this little endeavor.



( though I seen it pop open the header in codeblocks to show me what it's talking about. -- MAYBE just edit that one add const into its definition and cross my fingers? ;) )

BW-userx 04-12-2018 11:45 AM

UPDATE: casting didn't work...
Code:

err = XpmCreatePixmapFromData(display, Root, (char **)pixmap_bytes, &(wmgen->pixmap), &(wmgen->mask), &(wmgen->attributes));
Code:

||=== Build: Debug in wmslideshow (compiler: GNU GCC Compiler) ===|
||error: ld returned 1 exit status|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|


norobro 04-12-2018 11:46 AM

Here you go: http://en.cppreference.com/w/cpp/language/const_cast

BW-userx 04-12-2018 12:46 PM

Quote:

Originally Posted by norobro (Post 5842416)

I'm assuming this is correct, I got a good compile, with a seg fault, that shows progress. :D
Code:

static void GetXPM(XpmIcon *wmgen, char const *pixmap_bytes[]) {

    XWindowAttributes  attributes;
    int                err;

    char **pixmapy = const_cast<char **>(pixmap_bytes);

  // For the colormap
    XGetWindowAttributes(display, Root, &attributes);

    wmgen->attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);

    err = XpmCreatePixmapFromData(display, Root, pixmapy /*  pixmap_bytes */, &(wmgen->pixmap), &(wmgen->mask), &(wmgen->attributes));

    if (err != XpmSuccess) {
        fprintf(stderr, "Not enough free colorcells.\n");
        exit(1);
    }
}

just got to weed out the seg fault now. Hopefully its nothing to do with the changes I made to the char to const char.

BW-userx 04-12-2018 12:57 PM

Got it! onward and upwards...


All times are GMT -5. The time now is 08:53 PM.