Jump to content
Sign in to follow this  
dragonflightdesign

Problem with Compiling C++ Gauge

Recommended Posts

Guest VAPilot

After programming XML for the last couple of years, I thought I might try my hand at C++. I have downloaded Dai Griffiths Gauge Creation Tutorial Rev.23, and after reading it, thought I would try and do a simple airpseed gauge, one background, one needle. After looking at code in the Gauge Creation Tutorial, and looking at the SDK, I have worked out where all the files go, ie master source, header, bitmaps etc. I have then wrote the code I think will work and compiled it. As I expected I had a few errors, which after looking for a fair few hours I mave manages to iron out all of them except two, and I can not work out why I get them.The Code://B307 Airspeedchar airspeed_gauge_name[] = GAUGE_NAME;extern PELEMENT_HEADER airspeed_list;extern MOUSERECT airspeed_mouse_rect[];GAUGE_CALLBACK airspeed_update;GAUGE_HEADER_FS700 ( GAUGE_W, airspeed_gauge_name, &airspeed_list, airspeed_mouse_rect, airspeed_update, 0, 0, 0 );FAILURE_RECORD airspeed_fail[] = { {FAIL_SYSTEM_ELECTRICAL_PANELS, FAIL_ACTION_ZERO}, {FAIL_NONE, FAIL_ACTION_NONE}};#define GAUGE_MIN_AIRSPEED 0#define GAUGE_MAX_AIRSPEED 250NONLINEARITY airspeed_nonlinearity[] = { {{125, 29}, 00.000000, 0}, {{150, 40}, 30.000000, 0}, {{195, 74}, 50.000000, 0}, {{199, 170}, 100.000000, 0}, {{157, 208}, 120.000000, 0}, {{94, 211}, 150.000000, 0}, {{47, 171}, 200.000000, 0}, {{36, 123}, 220.000000, 0}, {{49, 82}, 230.000000, 0}, {{104, 40}, 250.000000, 0}, };NEEDLE_UPDATE_CALLBACK airspeed_src_cb;MODULE_VAR curr_airspeed = {AIRSPEED};double airspeed_ret = 0;FLOAT64 FSAPI airspeed_src_cb (PELEMENT_NEEDLE pelement){ lookup_var(&curr_airspeed); airspeed_ret = curr_airspeed.var_value.n; if ( airspeed_ret > GAUGE_MAX_AIRSPEED ) airspeed_ret = GAUGE_MAX_AIRSPEED; if ( airspeed_ret < GAUGE_MIN_AIRSPEED ) airspeed_ret = GAUGE_MIN_AIRSPEED; return airspeed_ret;}MAKE_NEEDLE( airspeed_needle, AIRSPEED_NEEDLE, &airspeed_list, airspeed_fail, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE| anti_alias | bright, 0, 125,125, 97,16, MODULE_VAR_NONE, airspeed_src_cb, airspeed_nonlinearity, 6 ) PELEMENT_HEADER airspeed_list[] = { (PELEMENT_HEADER) &airspeed_list, NULL };MAKE_STATIC( airspeed_background, AIRSPEED_BACKGROUND, &airspeed_list, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | bright | anti_alias, 0, 0,0 )PELEMENT_HEADER airspeed_list = &airspeed_background.header;MOUSE_BEGIN( airspeed_mouse_rect, HELPID_GAUGE_AIRSPEED, 0, 0 ) MOUSE_END#undef GAUGE_NAME#undef GAUGEHDR_VAR_NAME#undef GAUGE_WThe Errors:B307.obj : error LNK2001: unresolved external symbol _airspeed_update@12C:Documents and SettingsRussell HowardMy DocumentsGaugesB307B307DebugB307.dll : fatal error LNK1120: 1 unresolved externalsI have tried compiling a couple of Dai Griffiths source codes, to see if I have set up the compiler up correctly, and they worked just fine in the compiler and FS9, but for the life of me I can not see why this does not work.nearly forgot; I am using Microsoft Visual C++ 2008 express edition for compilingThanks in advance for any help.Russell

Share this post


Link to post
Share on other sites

Change this:GAUGE_CALLBACK airspeed_update;GAUGE_HEADER_FS700 ( GAUGE_W, airspeed_gauge_name, &airspeed_list, airspeed_mouse_rect, airspeed_update, 0, 0, 0 );to this:GAUGE_HEADER_FS700 ( GAUGE_W, airspeed_gauge_name, &airspeed_list, airspeed_mouse_rect, NULL, 0, 0, 0 );You declare the GAUGE_CALLBACK function but don't define it or use it. Remove the reference in the GAUGE_HEADER and you should be good to go.Doug

Share this post


Link to post
Share on other sites
Guest VAPilot

Thanks Doug the gauge now compiles without errors or warnings, but when I load the panel with the gauge in it, FS9 crashes to desktop. I am guessing that I have not assigned something correctly. Time to look through the code again.Russell

Share this post


Link to post
Share on other sites

This line:"PELEMENT_HEADER airspeed_list[] = { (PELEMENT_HEADER) &airspeed_list,NULL };"Doesn't make much sense to me, to be honest. In all gauges I've written it would be:PELEMENT_HEADER airspeed_list = &airspeed_needle.header;I'm honestly unclear why you're defining it as you are. You're typecasting a PELEMENT_HEADER as a PELEMENT_HEADER (redundant)... and you're passing a pointer to airspeed_list AS airspeed_list.


Ed Wilson

Mindstar Aviation
My Playland - I69

Share this post


Link to post
Share on other sites
Guest VAPilot

Thanks for the reply ED. PELEMENT_HEADER was my problem. After looking at the code again last night, I altered it to PELEMENT_HEADER airspeed_plist1[] = { (PELEMENT_HEADER) &airspeed_needle, NULL }; I then put &airspeed_plist1, as the gauge draw number for MAKE_STATIC, rebuilt it, and now I have my first C++ gauge working in FS9.

Share this post


Link to post
Share on other sites

Right... still think you're being "silly" with the typecast. You can avoid making the compiler do all that work just by passing exactly what it wants. ;) It also makes the code less confusing... since typecasting implies the pointer you're passing is NOT what you claim it is... despite the fact it is indeed.Clarity of code is something I strenuously stress to most anyone I work with.


Ed Wilson

Mindstar Aviation
My Playland - I69

Share this post


Link to post
Share on other sites

I agree with Ed. KISS and clarity are best practices... ;)MAKE_NEEDLE( airspeed_needle, AIRSPEED_NEEDLE, NULL, // final element in plist airspeed_fail, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | anti_alias | bright, 0, 125,125, 97,16, MODULE_VAR_NONE, airspeed_src_cb, airspeed_nonlinearity, 6 )PELEMENT_HEADER airspeed_list = &airspeed_list;MAKE_STATIC( airspeed_background, AIRSPEED_BACKGROUND, &airspeed_list, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | bright | anti_alias, 0, 0,0)PELEMENT_HEADER airspeed_list = &airspeed_background.header;I'm assuming that you have custom #defines for "anti_alias" and "bright" since they aren't part of the SDK's gauges.h file.Most folks use BIT7 instead of IMAGE_BILINEAR_COLOR, which is of course the same thing.Dai Griffiths added this #define which makes its purpose more clear:// added for backward compability:#define IMAGE_ANTI_ALIAS IMAGE_BILINEAR_COLOR


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites
Guest VAPilot

The Display Priority was confusing me a little. I have reread Dai Griffiths explaination on Display Priority and Plist and with the comments and example code being shown, I undersatnd it much better.Thanks for taking the time to post, it is much appreciated.I am off to alter the airspeed gauge, and think about the next project to try. Thanks againRussell

Share this post


Link to post
Share on other sites

>The Display Priority was confusing me a little. I have reread>Dai Griffiths explaination on Display Priority and Plist and>with the comments and example code being shown, I undersatnd>it much better.>>Thanks for taking the time to post, it is much appreciated.Ah, I see that you must have used Dai's dragonflight.h file in which he has created some additional #define(s) for simplicity.It (programming) can be a lot of fun. It can also cause premature graying and excessive curl in your eyebrows... ;)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

> Ah, I see that you must have used Dai's dragonflight.h file in which he has created some additional #define(s) for simplicity.= laziness :)-Dai

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...