Page 1 of 2

[resolved] ones again C++ to PB

Posted: Sun May 25, 2008 6:48 pm
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

Posted: Mon May 26, 2008 8:49 pm
by nicolaus
Can any one help me?

Posted: Mon May 26, 2008 9:43 pm
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$()?

Posted: Mon May 26, 2008 10:03 pm
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.

Posted: Mon May 26, 2008 10:13 pm
by ts-soft
you can test this:

Code: Select all

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

@szTitle
greetings
Thomas

Posted: Mon May 26, 2008 10:13 pm
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?

Posted: Mon May 26, 2008 10:20 pm
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) 

Posted: Tue May 27, 2008 1:03 pm
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"?

Posted: Tue May 27, 2008 1:08 pm
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.

Posted: Tue May 27, 2008 1:12 pm
by Trond
Why can't you answer the unicode question?

Posted: Tue May 27, 2008 4:14 pm
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.

Posted: Tue May 27, 2008 4:29 pm
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)) 

Posted: Tue May 27, 2008 4:36 pm
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.

Posted: Tue May 27, 2008 6:26 pm
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.

Posted: Tue May 27, 2008 6:33 pm
by ts-soft
I think there is a UDT or Structure "pDataSet" defined?