passing a string from a java program to a C++ dll to a VC++ dll
843829Aug 14 2006 — edited Aug 15 2006Hi,
I am terribly stuck up at a point in my code where I need to do some passing around of strings.
I have a java program which passes a string to my C++ dll (through JNI).
In the C++ dll i convert thi string i.e. the jstring to a char* as follows:
char* cText = (char *)(*jenv)->GetStringUTFChars(jenv, jtext, NULL);
Here jtext is a jstring that comes from my java program.
Now, within my C++ dll I call my VC++ dll and pass cText to it where it expects an argument of the type char*.
But each time I make a call to the function in the VC++ dll, which looks something like this:
int intMyReturnVal2 = MyFunction2(0, cText, "D:\\audioJNI.wav",5,5,5,5,1);
THe program crashes. I get this error:
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x05713d65, pid=2564, tid=3484
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode, sharing)
# Problematic frame:
# C [SakhrMultiChannelTtsSdk.dll+0x13d65]
#
# An error report file with more information is saved as hs_err_pid2564.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
[error occurred during error reporting, step 270, id 0xc0000005]
***************************************************************
When I check the error log, it looks like this:
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x05753d65, pid=2316, tid=2988
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode, sharing)
# Problematic frame:
# C [SakhrMultiChannelTtsSdk.dll+0x13d65]
#
--------------- T H R E A D ---------------
Current thread (0x00ab2ab0): JavaThread "RMI TCP Connection(2)-10.16.184.123" daemon [_thread_in_native, id=2988]
siginfo: ExceptionCode=0xc0000005, reading address 0xffffffff
Registers:
EAX=0x00000000, EBX=0x00000001, ECX=0xffffffff, EDX=0x00000000
ESP=0x0573f020, EBP=0x00000372, ESI=0x0573f094, EDI=0x066d2258
EIP=0x05753d65, EFLAGS=0x00010206
Top of Stack: (sp=0x0573f020)
0x0573f020: 0573f094 00005622 19e10020 00000372
0x0573f030: 00000800 05753f99 ffffffff 00005622
0x0573f040: 1a1d0020 00000000 19e10020 0573f094
0x0573f050: 05758b60 1a1d0020 000de7f0 1a1d0020
0x0573f060: 00005622 ffffffff 19cae6b0 19caeef4
0x0573f070: 0573f210 19cae410 001bcfe0 066d54f0
0x0573f080: 066d2608 05b79f50 19e10020 066d54f0
0x0573f090: 00000000 00000001 00005622 00000006
Instructions: (pc=0x05753d65)
0x05753d55: 4e 08 33 c0 84 c9 57 7e 16 8b 4c 24 18 8b 7e 0c
0x05753d65: 8a 14 08 88 14 07 40 0f be 56 08 3b c2 7c ee 8b
Stack: [0x05700000,0x05740000), sp=0x0573f020, free space=252k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [SakhrMultiChannelTtsSdk.dll+0x13d65]
[error occurred during error reporting, step 120, id 0xc0000005]
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j com.colornotes.TTS.TTSServer.executeTTSdll(IILjava/lang/String;)I+0
j com.colornotes.TTS.TTSServer.executeTTS(IILjava/lang/String;)Ljava/lang/Object;+190
v ~StubRoutines::call_stub
j sun.reflect.NativeMethodAccessorImpl.invoke0(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+0
j sun.reflect.NativeMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+87
j sun.reflect.DelegatingMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+6
j java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+111
j sun.rmi.server.UnicastServerRef.dispatch(Ljava/rmi/Remote;Ljava/rmi/server/RemoteCall;)V+246
j sun.rmi.transport.Transport$1.run()Ljava/lang/Object;+23
v ~StubRoutines::call_stub
j java.security.AccessController.doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;+0
j sun.rmi.transport.Transport.serviceCall(Ljava/rmi/server/RemoteCall;)Z+163
j sun.rmi.transport.tcp.TCPTransport.handleMessages(Lsun/rmi/transport/Connection;Z)V+185
j sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run()V+685
j java.lang.Thread.run()V+11
v ~StubRoutines::call_stub
--------------- P R O C E S S ---------------
Java Threads: ( => current thread )
=>0x00ab2ab0 JavaThread "RMI TCP Connection(2)-10.16.184.123" daemon [_thread_in_native, id=2988]
0x00036190 JavaThread "DestroyJavaVM" [_thread_blocked, id=2864]
0x050bf8a0 JavaThread "RMI LeaseChecker" daemon [_thread_blocked, id=3484]
0x0510b328 JavaThread "GC Daemon" daemon [_thread_blocked, id=4044]
0x051207f8 JavaThread "RMI Reaper" [_thread_blocked, id=3516]
0x05120b48 JavaThread "Timer-0" daemon [_thread_blocked, id=3916]
0x00acaab0 JavaThread "RMI TCP Accept-0" daemon [_thread_in_native, id=2732]
0x00a68e38 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=880]
0x00a67a20 JavaThread "CompilerThread0" daemon [_thread_blocked, id=2412]
0x00a66ac0 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=2264]
0x0003fc88 JavaThread "Finalizer" daemon [_thread_blocked, id=2228]
0x00a61aa0 JavaThread "Reference Handler" daemon [_thread_blocked, id=2032]
Other Threads:
0x00a5fe18 VMThread [id=1936]
0x00a6a058 WatcherThread [id=3840]
VM state:not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None
Heap
def new generation total 576K, used 5K [0x22a70000, 0x22b10000, 0x22f50000)
eden space 512K, 1% used [0x22a70000, 0x22a71758, 0x22af0000)
from space 64K, 0% used [0x22b00000, 0x22b00000, 0x22b10000)
to space 64K, 0% used [0x22af0000, 0x22af0000, 0x22b00000)
tenured generation total 1408K, used 207K [0x22f50000, 0x230b0000, 0x26a70000)
the space 1408K, 14% used [0x22f50000, 0x22f83d50, 0x22f83e00, 0x230b0000)
compacting perm gen total 8192K, used 430K [0x26a70000, 0x27270000, 0x2aa70000)
the space 8192K, 5% used [0x26a70000, 0x26adb8c8, 0x26adba00, 0x27270000)
ro space 8192K, 63% used [0x2aa70000, 0x2af7b178, 0x2af7b200, 0x2b270000)
rw space 12288K, 46% used [0x2b270000, 0x2b809fa8, 0x2b80a000, 0x2be70000)
Dynamic libraries:
0x00400000 - 0x0040c000 C:\WINDOWS\system32\java.exe
0x77f50000 - 0x77ff7000 C:\WINDOWS\System32\ntdll.dll
0x77e60000 - 0x77f46000 C:\WINDOWS\system32\kernel32.dll
0x77dd0000 - 0x77e5d000 C:\WINDOWS\system32\ADVAPI32.dll
0x78000000 - 0x78087000 C:\WINDOWS\system32\RPCRT4.dll
0x77c10000 - 0x77c63000 C:\WINDOWS\system32\MSVCRT.dll
0x6d670000 - 0x6d804000 C:\Program Files\Java\jre1.5.0_06\bin\client\jvm.dll
0x77d40000 - 0x77dcd000 C:\WINDOWS\system32\USER32.dll
0x7f000000 - 0x7f042000 C:\WINDOWS\system32\GDI32.dll
0x76b40000 - 0x76b6c000 C:\WINDOWS\system32\WINMM.dll
0x629c0000 - 0x629c8000 C:\WINDOWS\system32\LPK.DLL
0x72fa0000 - 0x72ffa000 C:\WINDOWS\system32\USP10.dll
0x5dac0000 - 0x5dac7000 C:\WINDOWS\system32\rdpsnd.dll
0x6d280000 - 0x6d288000 C:\Program Files\Java\jre1.5.0_06\bin\hpi.dll
0x76bf0000 - 0x76bfb000 C:\WINDOWS\system32\PSAPI.DLL
0x6d640000 - 0x6d64c000 C:\Program Files\Java\jre1.5.0_06\bin\verify.dll
0x6d300000 - 0x6d31d000 C:\Program Files\Java\jre1.5.0_06\bin\java.dll
0x6d660000 - 0x6d66f000 C:\Program Files\Java\jre1.5.0_06\bin\zip.dll
0x10000000 - 0x10036000 D:\Profiles\e50435\My Documents\tts\Copy_of_Mr[1]._Pengfai\Copy of Mr. Pengfai\sun\HelloTTS.dll
0x79170000 - 0x79196000 C:\WINDOWS\system32\mscoree.dll
0x70a70000 - 0x70ad6000 C:\WINDOWS\system32\SHLWAPI.dll
0x791b0000 - 0x79416000 C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorwks.dll
0x7c340000 - 0x7c396000 C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\MSVCR71.dll
0x79040000 - 0x79085000 C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\fusion.dll
0x4fec0000 - 0x4ffe6000 C:\WINDOWS\system32\ole32.dll
0x7cd00000 - 0x7d4fb000 C:\WINDOWS\system32\SHELL32.dll
0x71950000 - 0x71a35000 C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.1816_x-ww_7d33ba0e\comctl32.dll
0x77340000 - 0x773cb000 C:\WINDOWS\system32\comctl32.dll
0x79780000 - 0x7998c000 c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll
0x79990000 - 0x79ccc000 c:\windows\assembly\nativeimages1_v1.1.4322\mscorlib\1.0.5000.0__b77a5c561934e089_6bce435b\mscorlib.dll
0x79430000 - 0x7947d000 C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\MSCORJIT.DLL
0x51a70000 - 0x51af0000 C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\diasymreader.dll
0x0ffd0000 - 0x0fff3000 C:\WINDOWS\System32\rsaenh.dll
0x75a70000 - 0x75b15000 C:\WINDOWS\system32\USERENV.dll
0x71c20000 - 0x71c6e000 C:\WINDOWS\system32\netapi32.dll
0x6d4c0000 - 0x6d4d3000 C:\Program Files\Java\jre1.5.0_06\bin\net.dll
0x71ab0000 - 0x71ac4000 C:\WINDOWS\system32\WS2_32.dll
0x71aa0000 - 0x71aa8000 C:\WINDOWS\system32\WS2HELP.dll
0x71a50000 - 0x71a8b000 C:\WINDOWS\System32\mswsock.dll
0x76f20000 - 0x76f45000 C:\WINDOWS\system32\DNSAPI.dll
0x76fb0000 - 0x76fb7000 C:\WINDOWS\System32\winrnr.dll
0x76f60000 - 0x76f8c000 C:\WINDOWS\system32\WLDAP32.dll
0x76fc0000 - 0x76fc5000 C:\WINDOWS\system32\rasadhlp.dll
0x71a90000 - 0x71a98000 C:\WINDOWS\System32\wshtcpip.dll
0x6d5f0000 - 0x6d5f6000 C:\Program Files\Java\jre1.5.0_06\bin\rmi.dll
0x05740000 - 0x06350000 C:\Program Files\Sakhr\Sakhr Arabic TTS SDK\bin\SakhrMultiChannelTtsSdk.dll
0x77be0000 - 0x77bf4000 C:\WINDOWS\system32\MSACM32.dll
0x20000000 - 0x20023000 C:\WINDOWS\system32\WKWIN32.dll
0x71ad0000 - 0x71ad8000 C:\WINDOWS\system32\WSOCK32.dll
0x77c00000 - 0x77c07000 C:\WINDOWS\system32\VERSION.dll
0x06350000 - 0x06369000 C:\WINDOWS\system32\IPPSigDLL.dll
0x06370000 - 0x0638e000 C:\WINDOWS\system32\LangDetect.dll
0x73000000 - 0x73023000 C:\WINDOWS\system32\WINSPOOL.DRV
0x763b0000 - 0x763f5000 C:\WINDOWS\system32\comdlg32.dll
0x77120000 - 0x771ab000 C:\WINDOWS\system32\OLEAUT32.dll
0x1f7a0000 - 0x1f7d6000 C:\WINDOWS\system32\ODBC32.dll
0x1f840000 - 0x1f857000 C:\WINDOWS\system32\odbcint.dll
0x74720000 - 0x74764000 C:\WINDOWS\System32\MSCTF.dll
0x06770000 - 0x06799000 C:\Program Files\Common Files\Sakhr\Diac\dlls\diac.dll
0x067b0000 - 0x0688a000 C:\Program Files\Common Files\Sakhr\Diac\dlls\sat.dll
0x05620000 - 0x0565c000 C:\Program Files\Common Files\Sakhr\Diac\dlls\arabic\cnvrtr.dll
0x07440000 - 0x0752c000 C:\Program Files\Common Files\Sakhr\ADS\5.2\ADSDLL52.dll
0x07570000 - 0x075d2000 C:\Program Files\Common Files\Sakhr\MMMP\5.1\Mex3251.dll
0x08840000 - 0x08878000 C:\Program Files\Common Files\Sakhr\ADS\5.2\Lex32.dll
0x09ec0000 - 0x09ed5000 C:\Program Files\Common Files\Sakhr\ADS\5.2\Tagger.dll
0x73dd0000 - 0x73ec2000 C:\WINDOWS\system32\MFC42.DLL
0x5fd00000 - 0x5fd0d000 C:\WINDOWS\System32\MFC42LOC.DLL
0x09ee0000 - 0x09f08000 C:\Program Files\Common Files\Sakhr\ADS\5.2\pnsrch.dll
0x0c440000 - 0x0c47c000 C:\Program Files\Common Files\Sakhr\ADS\5.2\ExpDetector.dll
0x0fce0000 - 0x0fd00000 C:\Program Files\Common Files\Sakhr\ADS\5.2\ArabicCollocation.dll
0x0ff00000 - 0x0ff1f000 C:\Program Files\Common Files\Sakhr\ADS\5.2\idmprs32.dll
0x0ff20000 - 0x0ff35000 C:\Program Files\Common Files\Sakhr\Diac\dlls\arabic\prsrdiag.dll
0x0ff40000 - 0x0ff69000 C:\Program Files\Common Files\Sakhr\Diac\dlls\diacph2.dll
0x0ff80000 - 0x0ffb1000 C:\Program Files\Common Files\Sakhr\Diac\tools\Sgmntr\sntSeg.dll
0x15f80000 - 0x15fa9000 C:\Program Files\Common Files\Sakhr\Diac\dlls\pnsrch.dll
0x160c0000 - 0x160c7000 C:\Program Files\Common Files\Sakhr\Diac\dlls\arbtkn.dll
0x160d0000 - 0x160f6000 C:\Program Files\Sakhr\Sakhr Arabic TTS SDK\G2P\WAV2WMA.dll
0x16100000 - 0x162fd000 C:\WINDOWS\system32\WMVCore.DLL
0x16300000 - 0x16339000 C:\WINDOWS\system32\WMASF.DLL
0x16350000 - 0x163a6000 C:\Program Files\Sakhr\Sakhr Arabic TTS SDK\G2P\G2PLib.dll
0x164c0000 - 0x164f6000 C:\Program Files\Sakhr\Sakhr Arabic TTS SDK\G2P\NCDiac.dll
VM Arguments:
jvm_args: -Djava.security.policy=policy.all
java_command: com.colornotes.TTS.TTSServer baa
Launcher Type: SUN_STANDARD
Environment Variables:
JAVA_HOME=C:\Program Files\Java\jre1.5.0_06\bin;D:\Sun\AppServer\jdk\bin
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Adaptec Shared\System;C:\Program Files\Hummingbird\Connectivity\8.00\Accessories\;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;D:\Programs\Informix\bin;C:\Program Files\atria\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\ntutils;C:\Scripts;C:\Program Files\Java\jre1.5.0_06\bin;D:\Sun\AppServer\jdk\bin
USERNAME=e50435
LD_LIBRARY_PATH=D:\Profiles\e50435\My Documents\Visual Studio Projects\HelloTTS\debug\HelloTTS.dll
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 15 Model 2 Stepping 7, GenuineIntel
--------------- S Y S T E M ---------------
OS: Windows XP Build 2600 Service Pack 1
CPU:total 1 family 15, cmov, cx8, fxsr, mmx, sse, sse2, ht
Memory: 4k page, physical 522228k(14604k free), swap 1278668k(437616k free)
vm_info: Java HotSpot(TM) Client VM (1.5.0_06-b05) for windows-x86, built on Nov 10 2005 11:12:14 by "java_re" with MS VC++ 6.0
**************************************************************
could someone please help me with this? I have tried a lot of things to make it work, but in vain. I know that the problem is with passing the char* from my C++ dll to my VC++ dll, and that the JVM seems to be complaining about it, but dont knw how to fix it.
Instead of passing the string from java to C++ to VC++, I even tried to hardcode a char* during my call from C++ to VC++, but i get the same error.
Any help will be really appreciated.
Thanks