views:

65

answers:

1

I have a Java app which needs to interact with the camera on a Windows Mobile device. I have written the Java Code and the Native code and it all works fine. The problem I am having now is that I want to start passing variables from Java to the Native code, e.g. the directory and file name to use for the photo.

The native code uses a SHCAMERACAPTURE object to interact with the camera and it expects the directory and filename to be specified using LPCTSTRs. The string passed in is a jstring, which I can get to a const char * by calling:

const char *strDir=(jEnv)->GetStringUTFChars(dirName, 0);

But I am not sure how I can pass this to the the SHCAMERACAPTURE object because it cannot convert const char * to LPCTSTR. I tried a cast (LPCTSTR)strDir and it compiled, but I get an error when it runs (that it can't create the file).

I am a Java developer and pretty new to C++ etc. so I am really not too sure what I need to do to get my string into the native call. Any ideas?

+2  A: 

I think you should try GetStringChars() instead of GetStringUTFChars() According to this page it returns the Unicode String.

WindowsCE and Windows mobile use UNICODE exclusively so LPCTSTR is actually LPCWSTR (Long Pointer to Const WideChar String)

SHCAMERACAPTURE shcc;
ZeroMemory(&shcc, sizeof(shcc));
shcc.cbSize = sizeof(shcc);
shcc.pszInitialDir = (TCHAR*)(jEnv)->GetStringChars(dirName, 0 ); 
shcc.pszDefaultFileName = (TCHAR*)(jEnv)->GetStringChars(defFileName, 0 );

I assume you want to provide a path and a filename. This is adapted from this MS page

renick
`GetStringChars()` returns a `const jchar *`, so I still don't know how I can pass that to my native object?
DaveJohnston
see updated answer
renick
What is `shcam.szFile`? and `GetStringChars()` does not take 0 arguments? Can you explain what that line of code is trying to do? Thanks.
DaveJohnston
See updated answer. I did not remember well. Its been a few years away from WM. I am on a Mac and don't have access to VS2008 so it takes a while to find things.
renick
Thanks, that works now :D
DaveJohnston
You are welcome. I am doing JNI on the Mac so I feel your situation perfectly...
renick