1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C++ Bitmaps

Discussion in 'Gauges' started by TurbofanDude, 4/5/12.

  1. TurbofanDude

    TurbofanDude

    Joined:
    3/3/11
    Messages:
    48
    Country:
    unitedstates
    Hey guys,

    I have written a gauge for FSX (in this case, the base of an altitude gauge), and I followed the same procedure I have for gauges in the past (that worked). Now, I am having an inexplicable access violation error loading the gauge from within FSX. I have tried using GAUGE_HEADER_FS700 and GAUGE_HEADER_FS1000 (using NULL in place of callbacks and serialization data in the latter), and both times, what happens is this:

    When using FsPanelStudio to place the gauge, it recognizes that it is an FSX gauge, and reads the gauge table to identify that !altitude points to the altitude guage. As soon as I click on it, FsPanelStudio freezes, and if I select it from withing FSX, FSX crashed with an unhandled exception either in user32.dll or ntdll.dll. There are no compiler errors, except for an Intellisense "Expected a declaration" warning in the .rc file (which was not present in VS2010/VC++ 2010, but is in VS11). I have tried using a different bitmap, and I have tried compiling it with VS2010 as well (to no avail).

    If anyone else has had this issue before, please let me know how you fixed it. I have read the FSX SDK samples several times, and read the Dragonfly Gauge Tutorial as a guide, and I have checked my code several times. I will publish that actual code later if neccesary, just wondering if there is something obvious I overlooked.

    Thanks ahead of time,
  2. Naruto-kun

    Naruto-kun

    Joined:
    24/6/10
    Messages:
    625
    Country:
    southafrica
    I have found VS2008 to be a bit more stable for FSX stuff than the newer versions....
  3. taguilo

    taguilo Resource contributor

    Joined:
    20/10/06
    Messages:
    1,067
    Country:
    argentina
    Would be great that you post all (or part if it is too big) of the code in the .rc file, the main .cpp (and) the one where macros FS700etc and MAKE_STATIC, etc are located.

    Tom
  4. TurbofanDude

    TurbofanDude

    Joined:
    3/3/11
    Messages:
    48
    Country:
    unitedstates
    I have edited out certain sections, as the project is secret.


    ---------ers_FILE.rc-----------------------------
    ALTITUDE_BACKGROUND BITMAP DISCARDABLE "res\\ALTITUDE_BACKGROUND.BMP"
    ------------------------------------------------


    ----------altitude.cpp----------------------------
    char altitude_gauge_name[] = GAUGE_NAME;
    extern PELEMENT_HEADER altitude_list;
    extern MOUSERECT altitude_mouse_rect[];

    GAUGE_HEADER_FS700(GAUGE_W,altitude_gauge_name,&altitude_list,altitude_mouse_rect,0,0,0,0);

    MAKE_STATIC(alt_back,ALTITUDE_BACKGROUND,NULL,NULL,IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE,0,0,0)

    PELEMENT_HEADER altitude_list = &alt_back.header;

    MOUSE_BEGIN(altitude_mouse_rect,NULL,0,0)
    MOUSE_END

    #undef GAUGE_NAME
    #undef GAUGEHDR_VAR_NAME
    #undef GAUGE_W
    --------------------------------------------------------------


    -------------ers_FILE.cpp---------------------------------
    #include "inc\\gauges.h"
    #include "ers_FILE.h"

    //Altitude Gauge
    #define GAUGE_NAME "altitude"
    #define GAUGEHDR_VAR_NAME gaugehdr_altitude
    #define GAUGE_W 100

    #include "gauges\altitude.cpp"




    GAUGE_TABLE_BEGIN()
    GAUGE_TABLE_ENTRY(&gaugehdr_altitude)
    GAUGE_TABLE_END()
    --------------------------------------------------------


    --------------------------ers_FILE.h----------------------

    #define VERSION_MAJOR 1
    #define VERSION_MINOR 0
    #define VERSION_BUILD 0

    // magic to get the preprocessor to do what we want
    #define lita(arg) #arg
    #define xlita(arg) lita(arg)
    #define cat3(w,x,z) w##.##x##.##z##\000
    #define xcat3(w,x,z) cat3(w,x,z)
    #define VERSION_STRING xlita(xcat3(VERSION_MAJOR,VERSION_MINOR,VERSION_BUILD))

    #ifndef VS_VERSION_INFO
    #define VS_VERSION_INFO 0x0001
    #endif

    #define ALTITUDE_BACKGROUND 0x1000
    -------------------------------------------------------------
  5. taguilo

    taguilo Resource contributor

    Joined:
    20/10/06
    Messages:
    1,067
    Country:
    argentina
    Did you include

    #include "ers_FILE.h"

    in the .rc file? Otherwise ALTITUDE_BACKGROUND bitmap's physical location wouldn't be associated with 0x1000 address.

    Appart from that, I can't find anything wrong with your code.


    Tom
  6. TurbofanDude

    TurbofanDude

    Joined:
    3/3/11
    Messages:
    48
    Country:
    unitedstates
    Yes, I did include the header. You just confirmed my fears my friend. Either VS11 is compiling wrong, or my FSX is screwed up.
  7. mgh

    mgh

    Joined:
    15/1/10
    Messages:
    1,107
    Country:
    unitedkingdom
    A very remote possibility, but has your new bitmap the same nunber of bits/pixel as previous ones that were OK?
  8. TurbofanDude

    TurbofanDude

    Joined:
    3/3/11
    Messages:
    48
    Country:
    unitedstates
    Here's the weird part - it worked on one of my other dev's computers. Just not mine; I am unsure of the reason, but it is definitively something on my side (the other dev did indeed see the bitmap).
  9. Naruto-kun

    Naruto-kun

    Joined:
    24/6/10
    Messages:
    625
    Country:
    southafrica
    overall though GDI+ is a better way to go when it comes to C++ gauges....
  10. WarpD

    WarpD

    Joined:
    9/12/07
    Messages:
    530
    Country:
    us-ohio
    Not always.
  11. virtuali

    virtuali

    Joined:
    8/8/05
    Messages:
    210
    Country:
    switzerland
    Always.

    If you know how to use it *properly*, which means avoiding the functions that looks easy to use (which are usually slower) and use the more low-level functions that are harder and looks on paper more "complex", but are usually faster, and also if you skip GDI+ for some things that can be done with regular GDI and are way faster with it (like clearing the screen).

    There's nothing that can't be done with GDI+, including analog gauges with a custom bitmap background and vector needles drawn with GDI+ on top of them.
  12. WarpD

    WarpD

    Joined:
    9/12/07
    Messages:
    530
    Country:
    us-ohio
    Oh, I agree you can do it "all" with GDI+... I disagree that it's always the best choice.
  13. virtuali

    virtuali

    Joined:
    8/8/05
    Messages:
    210
    Country:
    switzerland
    It's always the best choice, provided you know exactly how GDI+ works (have you profiled all of the API, including the low-level functions ? ) and what functions should be used in any situation and what functions should never be used.

    So yes, I agree that, for someone without all the above information, it might not always be the best choice...

Share This Page