Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 756753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:16:52+00:00 2026-05-14T15:16:52+00:00

I have been trying to call a C function that has the following signature

  • 0

I have been trying to call a C function that has the following signature

int changeFoo(L_TCHAR* pszFileSrc){....}

in my JNI call my method looks like this:

JNIEXPORT jint JNICALL Java_com_me_L_AFoo(JNIEnv * env, jclass jclass, jstring pSrc)
{
    jint retValue = -100;
    retValue = changeFoo(pSrc);
    return retValue;
}

I get the following error in visual studio.

Error 1 error C2664: ‘L_FileConvert’ : cannot convert parameter 1 from ‘jstring’ to ‘L_TCHAR *’ c:\Ayusman\Work\MyVCpp\LTExampleDll\LTExampleDll\LTExampleMain.cpp 46 LTExampleDll

When I looked at the definition of L_TCHAR *

here is what I got in the header files (in that sequence):

typedef TCHAR L_TCHAR;
typedef WCHAR TCHAR,*PTCHAR;
typedef wchar_t WCHAR; //wc, 16 bit UNICODE char

I work on java, this is a JNI application that I am trying to build.
Can any body help as to how can I convert this properly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:16:52+00:00Added an answer on May 14, 2026 at 3:16 pm

    You’ll have to manually convert the string. Here’s some (corrected) example code:

    #include <stdio.h>
    #include <wchar.h>
    #include <stdlib.h>
    #include <string.h>
    #include <assert.h>
    
    #include "Foo.h"
    #define SURROGATE_MASK 0xD800
    #define is_surrogate(c) (((c) & SURROGATE_MASK) == SURROGATE_MASK)
    
    static wchar_t calculate_code_point(wchar_t surrogate_1, wchar_t surrogate_2);
    
    JNIEXPORT void JNICALL
    Java_Foo_foo(JNIEnv *env, jobject obj, jstring bar) {
      const jchar *chars = NULL;
      wchar_t *result = NULL;
      size_t len;
      size_t source_pos, result_pos;
    
      if (bar == NULL) {
        return;
      }
    
      len = (*env)->GetStringLength(env, bar);
      chars = (*env)->GetStringChars(env, bar, NULL);
      if (chars == NULL) {
        return;
      }
    
      result = (wchar_t *) malloc(sizeof(wchar_t) * (len + 1));
      source_pos = result_pos = 0;
      while (source_pos < len) {
        wchar_t curr_char = chars[source_pos++];
        if (is_surrogate(curr_char)) {
          wchar_t surrogate_1 = curr_char;
          wchar_t surrogate_2 = chars[source_pos++];
          curr_char = calculate_code_point(surrogate_1, surrogate_2);
        }
        result[result_pos++] = curr_char;
      }
      result[result_pos] = L'\0';
    
      (*env)->ReleaseStringChars(env, bar, chars);
    
      printf("%ls\n", result);
      free(result);
    }
    
    /**
     * Based on example code from http://unicode.org/faq/utf_bom.hmtl
     */
    static wchar_t calculate_code_point(wchar_t high_surrogate, wchar_t low_surrogate) {
      wchar_t x = (high_surrogate & ((1 << 6) - 1)) <<10 | low_surrogate & ((1 << 10) - 1);
      wchar_t w = (high_surrogate >> 6) & ((1 << 5) - 1);
      wchar_t u = w + 1;
      return u << 16 | x;
    }
    

    Note that this code only applies if you’re using Java 5 or above and your wchar_t data type is four bytes long. If you’re using Java 1.4 or below or your wchar_t data type is two bytes long then you don’t have to worry about surrogates.

    This code also leaves out some basic error checking and assumes that the first surrogate in the pair is the high-order surrogate (which is the case on my machine). You can definitively tell which surrogate is the high-order surrogate and which is the low-order surrogate by their respective values. The high-order surrogate is between 0xD800 and 0xDBFF, inclusive. The low-order surrogate is between 0xDC00 and 0xDFFF, inclusive. If you find a high-order surrogate that isn’t paired with a low-order surrogate or a low-order surrogate that isn’t paired with a high-order surrogate then the string is coded incorrectly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to call the NewPixelRegionIterator function in ImageMagick's library from C#
I am trying to call a function after the page has been sent to
I have been trying to call a mapreduce job from a simple java program
I have been trying for half a day to loop this countdown function. I
I have been trying to write a style sheet for the following documents which
I have been following the post below trying to hook my SubVersion installation to
I'm trying to interop with C in Python, and I have the following function
I've been trying to call the overloaded table::scan_index(std::string, ...) member function without success. For
Have have been trying to make a validator for my xml files. I have
I have been trying to customize a navigation bar in an iPhone app. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.