Transfer "String" from "native source code" to "Embeddid Wizard".

429 views
asked Nov 8, 2016 in GUI Development by StewardLin

Hi,

I meet a trouble for transfer "String" from "native source code" to "Embeddid Wizard", I made a simple sample as  following link.

http://ask.embedded-wizard.de/?qa=blob&qa_blobid=6293893886629025307

This trouble just happened on real machine only. please refer "UpdateString slot" of "Example::Application".

1. Please don't care "GetString(n_str);", this is needed in my project and working normal.

2. System will crash on "CopyString(v_str, n_str);", the cause is "var string v_str;" has not  allocate memory before used of my meaning.

I just want to show "STRING date" of "native code" on OSD, have you other easy ways for this request?

PS: following is subroutine of CopyString in native source code.

#define MAX_EmWi_STRING_LENGTH    255
void CopyString(char *cTarget, char *cSource) 
{
    unsigned int c_Cnt;
    
    for(c_Cnt = 0; cSource[c_Cnt] != 0x00; c_Cnt++)
    {
        if(c_Cnt >= MAX_EmWi_STRING_LENGTH)
            break;
        cTarget[c_Cnt] = cSource[c_Cnt];
    }
    cTarget[c_Cnt] = 0x00;
    printf("cSource = %s\n", cSource);
    printf("cTarget = %s\n", cTarget);
}

1 Answer

0 votes
answered Nov 8, 2016 by Manfred Schweyer
 
Best answer

The native code within your method UpdateString() is very dangerous (as you can see by the crash on the target...).

var string v_str;
native( v_str )
{
  char n_str[10];
  GetString(n_str);
  CopyString(v_str, n_str);  /* will cause a crash on target! */
}
this.testString = v_str;

Three different problems are within this implementation:

  1. The CopyString() method expects a character pointer (char*) but will get a XString.
  2. The string v_str is empty - you should never copy into this string by native code. (!!!)
  3. All strings within Embedded Wizard are UNICODE based (16bit) - you need to convert them from C string. 

Please let me refer to the article "How to exchange strings between GUI and a device?" which explains all these aspects in detail. The second chapter ("Transferring a string from native C code to the GUI") contains the necessary code snippets that you can use within your project.

I hope this answers your question.

commented Nov 9, 2016 by StewardLin
I understood, and your answer is helpful for me, thank you.

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...