I have written a JNI code which calls a c native Dll. In my dll- functionX I have a messsagebox with utf8 characters shown below:
string aboutStr = " به این برنامه خوش آمدید";
string aboutCaption = "درباره";
MessageBox(NULL, (LPCTSTR)(aboutStr.c_str()), (LPCTSTR)(aboutCaption.c_str()), MB_OK | MB_ICONEXCLAMATION);
When in a java tester, via JNI I call functionX, the messagebox shows question mark instead of persian characters.
How can I solve this problem?
Related
I'm trying to install a kernel driver from an MFC application using CreateService function and I'm not sure that I fully understand how lpBinaryPathName parameter is supposed to be set up.
Quoting MSDN:
The fully qualified path to the service binary file. If the path
contains a space, it must be quoted so that it is correctly
interpreted. For example, "d:\my share\myservice.exe" should be
specified as "\"d:\my share\myservice.exe\"".
The path can also include arguments for an auto-start service. For
example, "d:\myshare\myservice.exe arg1 arg2". These arguments are
passed to the service entry point (typically the main function).
So I do this:
LPCTSTR pStrDriverFilePath; //Driver full path
LPCTSTR pStrDriverFileParams; //Parameters
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
CString strDrvPath;
strDrvPath.Format(L"\"%s\"", pStrDriverFilePath);
if(pStrDriverFileParams &&
pStrDriverFileParams[0])
{
strDrvPath.AppendFormat(L" %s", pStrDriverFileParams);
}
CreateService(hSCManager, pStrDriverName, pStrDriverDispName,
SERVICE_START | DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS,
dwDriverType, dwStartType, dwErrorCtrl,
strDrvPath,
NULL, NULL, NULL,
NULL, NULL);
But then when I try to start it:
StartService(hScDrvHandle, 0, NULL);
it fails with the error code 123, or ERROR_INVALID_NAME:
The filename, directory name, or volume label syntax is incorrect.
Edit: This is how it ends up looking in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\ key:
It only works if I remove double quotes (but only w/o a parameter.)
I've tried to develop an NSIS Plugin in C++.
Here is my method to set informations from NSIS:
void __declspec(dllexport) SetCredentials(HWND hWndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) {
EXDLL_INIT();
server = getuservariable(INST_0);
port = myatou(getuservariable(INST_1));
database = getuservariable(INST_2);
username = getuservariable(INST_3);
password = getuservariable(INST_4);
MessageBox(hWndParent, server, L"Info", MB_OK); // Here is the problem
setuservariable(INST_0, server);
}
Sample:
OutFile "Example.exe"
BrandingText " "
Section
MySQL::SetCredentials "localhost" 3306 "banananode" "root" ""
Pop $0
MessageBox MB_OK "Server: $0" ; Returns the server value...
SectionEnd
The Problem is, when i try to print out the server variable, chinese characters will be shown, not the correct text:
When i return the value with setuservariable(INST_0, server);, NSIS will be display it correctly:
Can you tell me, whats wrong?
I've tried to build the resulted .dll with pluginapi-x86-ansi.lib and pluginapi-x86-unicode.lib but the result is the same...
ANSI characters interpreted as Unicode (UTF-16LE) tends to look Chinese.
When you create a Unicode plug-in you need to:
Make sure UNICODE and _UNICODE is defined in your project/.C files.
Link with pluginapi-x86-unicode.lib
Add Unicode True to your .NSI
Place the plug-in in \NSIS\x86-unicode
In your case you most likely forgot about Unicode True. Returning the value works because you never actually changed the memory of server, it is still the same input string.
I'm using windows OS and trying to write ACE_Tstring that contains multiple languages sentence(by Unicode) to a file using ACE_OS::write().
But the result I'm getting in the file is unpredictable characters(gibberish text).
This is my code implemented :
ACE_Tstring *str = new ACE_Tstring(L"مرحبا привет świecie Hello")
ACE_HANDL hFile = ACE_OS::open(L"myfile", _O_WRONLY);
ACE_OS::write(hFile, str, 1048);
wprintf(L"%ls",str->c_str());
As you can see I also print the string to the screen, and on screen I get the characters "????" where any character accept for English characters appear.
Written Text
مرحبا привет świecie Hello
Result on Screen :
?????? ????? ??????? Hello
What am I missing and what is wrong with my code?
ACE_TString is a typedef for ACE_CString when ACE_USES_WCHAR is not set. Try using ACE_WString if you need to force it to wide-chars.
I want to submit a form using the CHttpFile::SendRequest and save those data to a mysql database. The field inside the DB table collation is also set to utf8mb4_unicode_ci.
It works fine except the character encoding for the non-english chars. My app is under MFC and "character set" is no set which means ASCII. I tried to convert the chars to unicode without success.
CString strFormData;
strFormData = _T(SUBMIT_FORM) + _T(strSubmitValue) + _T(USERNAME_FIELD) + _T(m_strUsername) + _T(RESTORE_EMAIL_FIELD) + _T(m_strRestoreEmail) + _T(CAPTCHA_FIELD);
LPWSTR lpUnicodeFormData = A2W( strFormData );
strHeaders = _T("Content-Type: application/x-www-form-urlencoded;charset=UTF-8\r\n");
result = pFile->SendRequest(strHeaders, (LPVOID) (LPCTSTR) lpUnicodeFormData, wcslen(lpUnicodeFormData));
What am i doing wrong here ?
Inside PHP file where the html form exists, I added the code
mysqli_set_charset($con, "utf8");
This solved the problem.
thank you to all.
I'm trying to control Word through a c++ builder 5 application. I would like to
open a ".dot" model file created with Word and modify it. In the ".dot" model file
there are some fields. For example, Title, LastName, FirstName, Address
and so on, and I would like to modify these fields putting text into them and then
saving file with a new name, for example "Warning.doc" leaving the ".dot" file
unaltered.
I can open the file, count the number of fields it contains, but then
when it comes to replacing each field with a string I don't know how to do because
I don't have a complete documentation on OleFunction and OlePropertyGet methods. I attach my source code to this message, can anybody help me to solve this problem please?
try
{
my_word = Variant::CreateObject("word.application");
}
catch (...)
{
Application->MessageBox("Unable to obtain Word automation object",
"Error:",MB_OK | MB_ICONERROR);
}
my_word.OlePropertySet("Visible", (Variant)true);
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Variant this_doc;
Variant my_fields;
Variant test;
int k,field_count;
AnsiString test1;
AnsiString filename = "d:\\ProgrammaWord\\1-Avviso.dot";
my_docs = my_word.OlePropertyGet("Documents");
this_doc = my_docs.OleFunction("Open", filename);
my_fields = this_doc.OlePropertyGet("Fields");
field_count = my_fields.OlePropertyGet("Count");
for(k = 1; k <= field_count; k++)
{
test = my_fields.OleFunction("Item",(Variant)k);
test1 = test.OleFunction("Value"); //This instruction throws an exception
// "Value" is not a recognized parameter
// in this case
Memo1->Lines->Add(test1);
}
}
I never used word Ole but I used it for Outlook and Excel, I can't try it with word since I'm currently on OSX but you should try something similar as what I did.
The generic way of using Ole was to OleGetproperty() while you get the targeted field then OleSetProperty("action", ...).
for example when I wanted to change the color of the text in a particular cell of my excel document I used:
Variant _excel = Variant::CreateObject("Excel.Application");
Variant _workbook = _excel.OlePropertyGet("WorkBooks").OleFunction("Open", filename);
Variant _worksheet = _workbook.OlePropertyGet("WorkSheets", sheet);
_worksheet.OlePropertyGet("Cells", row, col).OlePropertyGet("Font").OlePropertySet("Color", color);
Here I instanciate an excel object, then I load a file into it (_workbook), then I select the _worksheet from the _workbook and I start my business.
Here comes the interesting part:
It concist of getting to a particular cell, getting the font object from it, and then setting the color of this font object.
Disclaimer: This is an example from my sources for excel, it's not directly related to your example, but maybe you can understand the principe with it. I can't try to figure out what you need because I have no windows right now.
Hope this can help you. Finding ressources for OLE can be fierce if you don't have the good patterns to look for.