1.3k views
in GUI Development by

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
by
 
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.

by
I understood, and your answer is helpful for me, thank you.

Ask Embedded Wizard - Archive

Welcome to the Ask Embedded Wizard archive. This community forum served us well for many years, but we've evolved our support approach!

Your resources:

The Embedded Wizard Online Documentation provides comprehensive documentation, tutorials, examples and ready-to-use software packages.

For dedicated assistance, explore our Embedded Wizard Product Support.

You can still browse the valuable discussions from our community history here.

Embedded Wizard Website | Privacy Policy | Imprint

...