Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. extern "C"
  2. JNIEXPORT void JNICALL
  3. Java_com_ihorkucherenko_storage_Store_setString(
  4. JNIEnv* pEnv,
  5. jobject pThis,
  6. jstring pKey,
  7. jstring pString) {
  8. // Turns the Java string into a temporary C string.
  9. StoreEntry* entry = allocateEntry(pEnv, &gStore, pKey);
  10. if (entry != NULL) {
  11. entry->mType = StoreType_String;
  12. // Copy the temporary C string into its dynamically allocated
  13. // final location. Then releases the temporary string.
  14. jsize stringLength = pEnv->GetStringUTFLength(pString);
  15. entry->mValue.mString = new char[stringLength + 1];
  16. // Directly copies the Java String into our new C buffer.
  17. pEnv->GetStringUTFRegion(pString, 0, stringLength, entry->mValue.mString);
  18. // Append the null character for string termination.
  19. entry->mValue.mString[stringLength] = '\0';
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement