Reputation: 796
I'm testing JNA before wrapping big dll. Basic functions with different types args works. But when we wrap (even simple) approved code which has standard method mbstowcs_s inside, appears:
Exception in thread "main" java.lang.Error: Invalid memory access
at com.sun.jna.Native.invokePointer(Native Method)
at com.sun.jna.Function.invokePointer(Function.java:490)
at com.sun.jna.Function.invokeString(Function.java:654)
at com.sun.jna.Function.invoke(Function.java:427)
at com.sun.jna.Function.invoke(Function.java:354)
at com.sun.jna.Library$Handler.invoke(Library.java:244)
at com.sun.proxy.$Proxy0.TestWCHAR_in(Unknown Source)
at gov.nbu.App.main(App.java:85)
All versions 32bit.
Upvotes: 1
Views: 933
Reputation: 796
Problem wasn't in JNA. It appears on Cpp side on some machines (my case). Here it is:
void TestVoid(void)
{
wchar_t wcBuffer[2600] = {};
size_t szOut = 0;
std::string Path = "This message for test WCHAR.";
errno_t errCode = 0;
// Work:
errCode = mbstowcs_s(&szOut, wcBuffer, sizeof(wcBuffer), (char*)Path.c_str(), Path.size());
// Not work:
errCode = mbstowcs_s(&szOut, wcBuffer, Path.size(), (char*)Path.c_str(), Path.size());
}
Upvotes: 0