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 7524425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:05:33+00:00 2026-05-30T03:05:33+00:00

I have a C function that returns an unsigned char * that can either

  • 0

I have a C function that returns an unsigned char * that can either be a pointer to a byte array (binary data representing a File..etc) or a pointer to an array of characters. I’m currently using the SWIG %array_class that wraps all C functions that return an unsigned char pointer and creates a Java array utility (SampleArrayUtil.java) to handle the population and retrieval on the Java side.

My problem is that I also use wrap the unsigned char * using: %apply char * { unsigned char * }; so that I get an array of Strings on the Java side. I don’t want to wrap the unsigned char * return value (using %apply char * { unsigned char * };) when I get binary data back, I want to just have the byte array on the Java side. I was thinking of creating another C function to handle the binary data, but I’m unsure how to wrap this new function as it will also return an unsigned char * (see getValueFromRowAsByteArray)

C Functions:

unsigned char * getValueFromRowAsStringArray(struct result_row *row, attribute_type type, int32_t *len)

unsigned char * getValueFromRowAsByteArray(struct result_row *row, attribute_type type, int32_t *len)
//*row* input param with data results, *type* input enum type for the data type being requested and *len* is an output param that contains the length of the data being returned.

SWIG Interface File for Wrapping C Function Returning unsigned char * (array of char):

%module Sample
%include "typemaps.i"
%include "stdint.i"
%include "arrays_java.i"
%include "carrays.i"
%array_class(unsigned char, SampleArrayUtil);
%{
#include "C_API.h"
%}
%apply char * { unsigned char * };
%include "C_API.h"
  • 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-30T03:05:34+00:00Added an answer on May 30, 2026 at 3:05 am

    You can apply different type maps to the same types in different places in at least two ways.

    Firstly you can change the active typemap with %apply or %clear, e.g.:

    %module test
    
    %include "stdint.i"
    
    %apply intptr_t { unsigned char * };
    unsigned char * test1();
    
    %apply char * { unsigned char * };
    unsigned char * test2();
    
    %clear unsigned char *;
    unsigned char * test3();
    

    Gives three functions in Java with different return types, according to the active typemap.

    Secondly you can also write more specific typemaps though, for example:

    %apply long long { unsigned char * test4 };
    %apply char * { unsigned char * test5 };
    unsigned char * test4();
    unsigned char * test5();
    

    Only applies to test4 and test5 respectively – it matches on the type and the function name. In Java this results in:

      public static long test4() {
        return testJNI.test4();
      }
    
      public static String test5() {
        return testJNI.test5();
      }
    

    For arguments you can match on the type and the parameter name in the function signature similarly.

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

Sidebar

Related Questions

I have byte to binary string function, std::string byte_to_binary(unsigned char byte) { int x
How can we new primitive types in JNI. I have a function that returns
I have a function that takes some bitmap data and returns a UIImage *
I have a function that returns a float from 0 to 255. I would
I have a function that returns an entry on a dictionary, based on the
I have a function that returns a date from a stored procedure, and it
I have a function that returns a table. The returned table contains (among other
If I have a function that returns an object, but this return value is
Let's say you have a function that returns a date: Date myFunc(paramA, paramB){ //conditionally
I have a simple function that returns an NSString after decoding it. I use

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.