text input dialog box encoding problem
Copy link to clipboard
Copied
Dear AE fellows,
I'm trying to implement a text input dialog box in c++ plugin.
I use the easiest option. Namely, I implement it via inclusion of javascript code.
I consulted with the following discussion:
Here is my script:
std::string script = "var text = prompt('Enter your text ', "");";
And here is my attempt to handle it:
AEGP_MemHandle nameH = NULL;
suites.UtilitySuite6()->AEGP_ExecuteScript(NULL, script.c_str(), true, &nameH, NULL);
AEGP_MemSize size = 0;
A_UTF16Char* nameP = NULL;
suites.MemorySuite1()->AEGP_LockMemHandle(nameH, (void**)&nameP);
suites.MemorySuite1()->AEGP_GetMemHandleSize(nameH, &size);
int len = size;
A_UTF16Char* res2 = (nameP + (len / 2));
std::vector<unsigned char> utf8result;
utf8::utf16to8(nameP, res2, back_inserter(utf8result));
std::string resStr(utf8result.begin(), utf8result.end());
suites.MemorySuite1()->AEGP_UnlockMemHandle(nameH);
suites.MemorySuite1()->AEGP_FreeMemHandle(nameH);
However, when I execute the plugin and save the result (resStr) of my simplest input (letter "a") into a separate text file I obtain chinese symbols and letter d (!):
湵敤楦敮d
Could you explain what I missed?
May be I use a very difficult method to obtain the result?
Yaroslav.
Copy link to clipboard
Copied
I managed to find the solution (with the help of my collleauge).
There were one mistake and one peculiar finding. First of all, the mistake:
In java script code, instead of var text =... one should put:
std::string script = "prompt('Enter your text ', "");";
Here is the correct code which get the user input string and stores it as std::string
AEGP_MemHandle nameHandle = NULL;
suites.UtilitySuite5()->AEGP_ExecuteScript(NULL, script.c_str(), true, &nameHandle, NULL);
AEGP_MemSize size = 0;
A_UTF16Char* namePointer = NULL;
suites.MemorySuite1()->AEGP_LockMemHandle(nameHandle, (void**)&namePointer);
suites.MemorySuite1()->AEGP_GetMemHandleSize(nameHandle, &size);
char* res3 = (char*)namePointer;
std::string res4(res3); // the final std::string
suites.MemorySuite1()->AEGP_UnlockMemHandle(nameHandle);
suites.MemorySuite1()->AEGP_FreeMemHandle(nameHandle);
What we found incredible was that despite the fact that A_UTF16Char* obviously refers to 16char encoding.
we figured out that AE methods treated the data stored in A_UTF16Char* namePointer as ordinary (8 bit) char.
Does someone know if it is some feature of javascript?
If the plugin is to be executed on MacOs, do I have to change this piece of code?
Yaroslav.

