SDK Question Conflict with Terminal MFD Input Box

JMW

Aspiring Addon Developer
Joined
Aug 5, 2008
Messages
611
Reaction score
52
Points
43
Location
Happy Wherever
Hi All,

I have a little problem that can't solve myself.........

In an autopilot, I select a base to land at via
Code:
case OAPI_KEY_M:  // Base Box
                {
			HUD2 = 1;
			oapiSetHUDMode (HUD_DOCKING);
						
			oapiOpenInputBox("Enter Base Name", InputTarget, 0, 15, (void*)this) ;
                			  
					return true;
                }

Code:
bool InputTarget(void *id, char *bstr, void *user_data)



This "*bstr" is changed by "Base = bstr; " and printed to HUD in:

Code:
bool ShuttlePB::clbkDrawHUD (int mode, const HUDPAINTSPEC *hps, oapi::Sketchpad *skp)

Code:
Base = _strupr(Base);
		
		len = sprintf_s(buffer,"%s",Base);
		skp->SetTextColor(0x00ff00);
		skp->Text(0, 170, buffer,  len);

		len = sprintf_s(buffer,"Pad:%02.02d",padNum);
		skp->Text(46, 160, buffer,  len);
	
Base = _strlwr(Base);

But then, if I use Terminal MFD, as soon as the "Input" box is opened, the "Base" data inputted previously disappears and any imputed data is printed instead in HUD. (It does not interfere with the operation of the autopilot though)

How can I get the print of the string entered in my Input box to be protected?
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
The `Base` is declared in your class as a pointer to char, right?

The pointer points to an internal character buffer of Orbiter's input box. It isn't a copy of the string. That buffer will change every time you use Orbiter's input box, in any place, any module.

Use `strcpy` or `strcpy_s` function to copy the string from the input box buffer to your own character buffer in the class, or convert it to std::string object (which will copy the character buffer contents).
 

JMW

Aspiring Addon Developer
Joined
Aug 5, 2008
Messages
611
Reaction score
52
Points
43
Location
Happy Wherever
Ok.
I've tried
Code:
bool InputTarget(void *id, char *bstr, void *user_data)
{.................
strcpy(Base,bstr);
.......................
return true;}

Is that in the right place? (Please excuse my elementary knowledge)
Scenario crashes on initializing Input Box ----
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Code:
bool InputTarget(void *id, char *bstr, void *user_data)
{.................
strcpy(Base,bstr);
.......................
return true;}

Is that in the right place?

If Base is:
Code:
char * Base;
and it wasn't given an address to a `char []` variable, then it's a wrong way to do it.



Untested example, but try making `Base` a string object:
Code:
#include <string>

// {...}

class YourClass : public ClassBeingExtended {
public:
// {...}
    std::string Base;
// {...}
}

bool InputTarget (void *id, char *bstr, void *user_data) {
// {...}
    ((YourClass *)user_data)->Base = bstr;
// {...}
    return true;
}

bool YourClass::clbkDrawHUD (int mode, const HUDPAINTSPEC *hps, oapi::Sketchpad *skp) {
// {...}
    skp->Text (0, 170, Base.c_str (), Base.size ());
// {...}
}

If you want in upper case, then copy contents of the `Base.c_str ()` to `buffer` first, convert the `buffer` to upper case, and use `buffer` instead of `Base.c_str ()` while calling the Text function.
 

JMW

Aspiring Addon Developer
Joined
Aug 5, 2008
Messages
611
Reaction score
52
Points
43
Location
Happy Wherever
Thank you Orb - it works perfectly!

While you're on, could you havea look athttp://www.orbiter-forum.com/showthread.php?t=27378.
I still haven't managed to get this working yet.
(Getting dragged out to shop right now, but will be back on later.)
:cheers:

---------- Post added at 04:04 PM ---------- Previous post was at 09:55 AM ----------

Hmm....
I was a little optimistic ref my abilities...

Trying to
copy contents of the `Base.c_str ()` to `buffer` first,
what term do I use to do this?
Is it straightforward after this, or will I need some different terms than before?
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Trying to
copy contents of the `Base.c_str ()` to `buffer` first,
what term do I use to do this?
Code:
strcpy (buffer, Base.c_str ());
or
Code:
strcpy_s (buffer, sizeof (buffer), Base.c_str ());
 

JMW

Aspiring Addon Developer
Joined
Aug 5, 2008
Messages
611
Reaction score
52
Points
43
Location
Happy Wherever
doesn't like my
Code:
_strupr
to convert to upper case anymore??????
gives
error C2440: '=' : cannot convert from 'char *' to 'char [256]'
 
Last edited:

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Try without assigning value returned from _strupr anywhere.

The _strupr conversion is done in place. The returned pointer value is the same as passed to the function.
 
Top