[resolved] ones again C++ to PB

Just starting out? Need help? Post your questions and find answers here.
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

[resolved] ones again C++ to PB

Post by nicolaus »

Hello,

i have one more times a problem with translate a C++ code to PB.
I import functions from a *.lib

My translation shows like this:

original C++ *.h:

Code: Select all

..
SimConnect_Text(HANDLE hSimConnect, SIMCONNECT_TEXT_TYPE type, float fTimeSeconds, SIMCONNECT_CLIENT_EVENT_ID EventID, DWORD cbUnitSize, void * pDataSet);
..
my PB code to include the function:

Code: Select all

Import "SimConnect.lib"
...
SimConnect_Text(hSimConnect.l, type.l, fTimeSeconds.f, EventID.l, cbUnitSize.l, *pDataSet.l)
...
EndImport
Now the C++ Program code:

Code: Select all

static const char szTitle[] = "Facilities Data";
.....
SimConnect_Text(hSimConnect, SIMCONNECT_TEXT_TYPE_SCROLL_RED, 15, 0, sizeof(szTitle), (void*)szTitle);
....
and my PB code:

Code: Select all

Global Dim MyText.s(0)
MyText(0) = "Facilities Data"
....
SimConnect_Text(SC_handle, #SIMCONNECT_TEXT_TYPE_SCROLL_RED, 0.0, #EVENT_TEXT_1, Len(MyText(0)), @MyText())
It works but the string in the arry dont shows right. See the image to know what i mean:
Image

And here is the doku for the Function "SimConnect_Text()"
The SimConnect_Text function is used to display a text menu, or scrolling or static text, on the screen.

Syntax
HRESULT SimConnect_Text(
HANDLE hSimConnect,
SIMCONNECT_TEXT_TYPE type,
float fTimeSeconds,
SIMCONNECT_CLIENT_EVENT_ID EventID,
DWORD cbUnitSize,
void* pDataSet
);


Parameters
hSimConnect
[in] Handle to a SimConnect object.
type
[in] One member of the SIMCONNECT_TEXT_TYPE enumeration type.
fTimeSeconds
[in] The timeout value for the text or menu, in seconds. If zero is entered, the text or menu will not timeout. For text only, this timeout value can be overridden if there are other text requests waiting in the queue (see the Remarks below). If the timeout requested exceeds the minimum display time, and another text request is waiting, the timeout value is overridden and the text will only be displayed for the minimum display time. The default minimum display time is two seconds for static text and 10 seconds for scrolling text. These can be changed in the [SimConnect] section of FSX.cfg file using the TextMinPrintTimeSeconds and TextMinScrollTimeSeconds settings.
EventID
[in] Specifies the client defined event ID, which will be returned along with the SIMCONNECT_TEXT_RESULT (in the dwData parameter) of a SIMCONNECT_RECV_EVENT structure.
cbUnitSize
[in] Specifies the size of pDataSet in bytes.
pDataSet
[in] Specifies the array of string data for the menu or text. For text simply enter the string, for a menu the format of the string is a list of null-terminated string entries, with the menu title and prompt as the first two entries, for example: "Title\0Prompt\0Menu item 1\0Menu item 2\0", with a maximum of ten menu items. If an empty string is sent in pDataSet along with an EventID that matches a menu or text in the queue (see Remarks below), that entry will be removed from the queue, with the SIMCONNECT_TEXT_RESULT_REMOVED event being returned to the client. If a new set of menu items, or new text string, is sent with an EventID that matches an entry in the queue, that entry will be replaced in the queue, with the SIMCONNECT_TEXT_RESULT_REPLACED event being returned to the client. The entry will not lose its place in the queue. This change will take place even if the text or menu is being rendered on the screen.

Return Values
The function returns an HRESULT. Possible values include, but are not limited to, those in the following table.
I hope you can help me.

Thanks,
Nico
Last edited by nicolaus on Sat May 31, 2008 9:41 am, edited 1 time in total.
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

Can any one help me?
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

Looks like for a simple text operation you only need to pass the string pointer, not the address of the array. Have you tried using @MyText$(0) instead of @MyText$()?
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

tinman wrote:Looks like for a simple text operation you only need to pass the string pointer, not the address of the array. Have you tried using @MyText$(0) instead of @MyText$()?
Yes i have test to use @MyText$(0) instead of @MyText$() and also i have test to use a pointer of a string but if´i use one of this it shows non.
Only if i use the @MyText() version it shows this crasy chars what you can see in the screenshot at my first post.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

you can test this:

Code: Select all

Define szTitle.s{15} = "Facilities Data"

@szTitle
greetings
Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

In the C++ code szTitle is the same as doing @MyText$(0) - it is the address of the first character in the string.

Are you using Unicode? It looks like it may only work with ASCII?
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

in rare cases a variable is needed :

Code: Select all

Global Dim MyText.s(0) 
MyText(0) = "Facilities Data" 
.... 
pDataset=@MyText()
SimConnect_Text(SC_handle, #SIMCONNECT_TEXT_TYPE_SCROLL_RED, 0.0, #EVENT_TEXT_1, Len(MyText(0)), pDataset) 
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

tinman wrote:In the C++ code szTitle is the same as doing @MyText$(0) - it is the address of the first character in the string.

Are you using Unicode? It looks like it may only work with ASCII?
Ok but why this code works in C++?

Code: Select all

static const char szTitle[] = "Facilities Data"; 
..... 
SimConnect_Text(hSimConnect, SIMCONNECT_TEXT_TYPE_SCROLL_RED, 15, 0, sizeof(szTitle), (void*)szTitle); 
and shows the string not only the first char like "F"?
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

ABBKlaus wrote:in rare cases a variable is needed :

Code: Select all

Global Dim MyText.s(0) 
MyText(0) = "Facilities Data" 
.... 
pDataset=@MyText()
SimConnect_Text(SC_handle, #SIMCONNECT_TEXT_TYPE_SCROLL_RED, 0.0, #EVENT_TEXT_1, Len(MyText(0)), pDataset) 
the result with your code is the same like my with @MyText(). If i use a normal variable from type string and filled with a string and use it in the function like this "myvar" or "*myvar" it shows nothing.

If any of you have installed the Microsoft Flight Simulator X than i can give you the full scourse and you can see what i mean.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Why can't you answer the unicode question?
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

Trond wrote:Why can't you answer the unicode question?
I have test it with unicode and with ASCII but nothing works :cry:
I can´t finde the point where is the problem.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Have you tried...

Code: Select all

Global Dim MyText.s(0) 
MyText(0) = "Facilities Data" 
.... 
SimConnect_Text(SC_handle, #SIMCONNECT_TEXT_TYPE_SCROLL_RED, 0.0, #EVENT_TEXT_1, Len(MyText(0)), MyText(0)) 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

What value does 'sizeof(szTitle)' return in C++ ? You might want to check if all the arguments really are long/float (4 bytes).. Also check which calling convention is used by the lib.
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

Sparkie wrote:Have you tried...

Code: Select all

Global Dim MyText.s(0) 
MyText(0) = "Facilities Data" 
.... 
SimConnect_Text(SC_handle, #SIMCONNECT_TEXT_TYPE_SCROLL_RED, 0.0, #EVENT_TEXT_1, Len(MyText(0)), MyText(0)) 
This one cant work, MyText(0) returns a string and the param must have a pointer (long).
See my first post and the help for the function what i have post.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

I think there is a UDT or Structure "pDataSet" defined?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply