开发者

Windows Mobile Native Code - jstring to LPCTSTR

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:

co开发者_C百科nst 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜