Posted: 01 Dec 2012, 15:17
Sorry for the incomplete posting header: "Need help for GetEvtPChar" 
I need an explanation for something I didn't understand.
I made this implementation (read a string from a pin and echo the result to a pin)
I tested a little bit with my implementation and it failed. A problem occurs. I write a string to the text field "asdfasdf" and everything works fine. In the output textfield the text ist "asdfasdf". Then I write "asdf" into the text field and in the output "asdf" should be echoed, but it shows "2" or "3" or something like that. Tested it with "a", "as", "asd" and so on. The echoed string is correct after "asdff". What happens here? Something strange! After some tests, I found out, that the problem has something to do with the reading of the input pin (GetEvtPChar), not with the output pin. Here's the line which reads the string from the pin:
the definition of GetEvtPChar in the header is:
and PCHAR is defined as
PCHAR! So this normally means, the we have here a terminated char array. But stop, Usine is developed in Delphi (don't know where I get this info
and Delphi uses the Pascal string type and in C++ there is also a Pascal like string type available. This could be a reason, cause in the first bytes of such a string the length of the string is coded and this can leads to troubles if you use the string as a C-String type. I tried:
and "wonder wonder..." the problems disapears and my code works fine. But using the std::string as input here
won't work. I must use
I get a Pascal string, but I must send a C-Type string???? Mmh... I didn't understand this. Looks like a not clear implementation of the interface or I'm on a wrong path. Can someone give me an hint
Thanks.
Peter
P.S.: Yes, I know the simple way
but I try to understand the SDK...
I need an explanation for something I didn't understand.
I made this implementation (read a string from a pin and echo the result to a pin)
Code: Select all
if (Message->lParam == MSG_CHANGE)
{
PCHAR pcharTheInputString = pSerialInfoModule->GetEvtPChar( pSerialInfoModule->m_txtfExampleIn );
int lengthOfInputString = pSerialInfoModule->GetEvtSize(pSerialInfoModule->m_txtfExampleIn);
pSerialInfoModule->SetEvtSize(pSerialInfoModule->m_txtfExampleOut, lengthOfInputString);
pSerialInfoModule->SetEvtPChar(pSerialInfoModule->m_txtfExampleOut, pcharTheInputString);
}Code: Select all
PCHAR pcharTheInputString = pSerialInfoModule->GetEvtPChar( pSerialInfoModule->m_txtfExampleIn );Code: Select all
PCHAR GetEvtPChar( TEVT* ev )Code: Select all
typedef CHAR *PCHAR, *LPCH, *PCH;Code: Select all
std::string strTheInputString = pSerialInfoModule->GetEvtPChar( pSerialInfoModule->m_txtfExampleIn );
PCHAR pcharTheInputString = (PCHAR) strTheInputString.c_str();Code: Select all
pSerialInfoModule->SetEvtPChar(pSerialInfoModule->m_txtfExampleOut, strTheInputString);Code: Select all
PCHAR pcharTheInputString = (PCHAR) strTheInputString.c_str();
pSerialInfoModule->SetEvtPChar(pSerialInfoModule->m_txtfExampleOut, pcharTheInputString);Thanks.
Peter
P.S.: Yes, I know the simple way
Code: Select all
pSerialInfoModule->CopyEvt( pSerialInfoModule->m_txtfExampleIn,pSerialInfoModule->m_txtfExampleOut );