I have a small C++ library and want to use swig to create a Java wrapper.
I need to extend one of the C++ clases in java so I’ve tried to use the ‘director’ feature. I also want to send binary data (which in my C++ is represented as unsigned char*) so I’ve used the char* to byte[] typemap found in various.i.
I’ve created a small example illustrating the problem.
My C++ source file (MyFile.h):
class MyCppSocketBase
    MyCppSocketBase() {}
    virtual ~MyCppSocketBase() {}
    virtual void SendPacket(char* BYTE, int LENGTH) = 0;
class MyCppClass
    MyCppSocketBase* mySocket;
    MyCppClass(MyCppSocketBase* base) {
        mySocket = base;
    void SetData(char* BYTE, int LENGTH) {
        mySocket->SendPacket(BYTE, LENGTH);
My interface file:
%module(directors="1") MyFile
#include "MyFile.h"
%include "various.i"
%feature("director") MyCppSocketBase; 
%include "MyFile.h"
When I swig and compile this, I get the following error:
1>------ Rebuild All started: Project: SwigTest, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'SwigTest', configuration 'Debug|Win32'
1>Performing Custom Build Step
1>c:\Users\Silje\Documents\Visual Studio 2005\Projects\SwigTest\SwigTest>swig.exe -c++ -java -package my.app MyFile.i
1>c:\users\silje\documents\visual studio 2005\projects\swigtest\swigtest\myfile_wrap.cxx(442) : error C2440: '=' : cannot convert from 'jstring' to 'jbyteArray'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://c:\Users\Silje\Documents\Visual Studio 2005\Projects\SwigTest\SwigTest\Debug\BuildLog.htm"
1>SwigTest - 1 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Here’s the generated function in MyFile_wrap.cxx  that has the warning:
void SwigDirector_MyCppSocketBase::SendPacket(char *BYTE, int LENGTH) {
  JNIEnvWrapper swigjnienv(this) ;
  JNIEnv * jenv = swigjnienv.getJNIEnv() ;
  jobject swigjobj = (jobject) NULL ;
  jbyteArray jBYTE = 0 ;
  jint jLENGTH  ;
  if (!swig_override[0]) {
    SWIG_JavaThrowException(JNIEnvWrapper(this).getJNIEnv(), SWIG_JavaDirectorPureVirtual, "Attempted to invoke pure virtual method MyCppSocketBase::SendPacket.");
  swigjobj = swig_get_self(jenv);
  if (swigjobj && jenv->IsSameObject(swigjobj, NULL) == JNI_FALSE) {
    jBYTE = 0;
    if (BYTE) {
      jBYTE = jenv->NewStringUTF((const char *)BYTE);                       /* - ERROR LINE - */
      if (!jBYTE) return ;
    jLENGTH = (jint) LENGTH;
    jenv->CallStaticVoidMethod(Swig::jclass_MyFileJNI, Swig::director_methids[0], swigjobj, jBYTE, jLENGTH);
    if (jenv->ExceptionOccurred()) return ;
  } else {
    SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null upcall object");
  if (swigjobj) jenv->DeleteLocalRef(swigjobj);

Any help is appreciated. Thank you.
Silje Helfjord