Jna

3 respostas
S

e ai pessoal,

eu estou tentando usar o tal do jna… mas não to conseguindo… peguei um exemplo da internet e já setei o classpath, e talz…mas ele nao encontra a dll… o que sera q ta acontecendo?

la vai o codigo:

esse é o testejna.cpp:

#include <stdio.h>
#include <windows.h>
#include "testejna.h"

void librarymethod(char* whatToSay)
{
   printf("Java Rocks, I’m Calling this without JNI and telling the C code to Say: %s !\n",whatToSay);
}

testejna.h:

#ifndef testejna_H
#define testejna_H
void librarymethod(char* whatToSay);
#endif

MySharedLibrary.java:

package testejna;

import com.sun.jna.Library;


public interface MySharedLibrary extends Library{
        public void librarymethod(String whatToSay);
}

e TesteJNA.java:

package testejna;

import com.sun.jna.Native;

public class TesteJNA {
    public static void main(String args[]){
                
        MySharedLibrary lib = (MySharedLibrary) Native.loadLibrary("testejna", MySharedLibrary.class);
        lib.librarymethod("Java Rocks");
        
    }
}

tem gente que ja conseguiu usar isso e diz q eh simples… mas tem algo obscuro ai… hehe

3 Respostas

S

já consegui carregar a dll… agora só não consigo usar os métodos dela…

obs. nao to mais usando esse exemplo… ja to fazendo do meu projeto… existe algum programa que descompila dlls?

S

hehe ja consegui …
mas apareceu um trem esquisito… alguem sabe explicar que tipos sao esses? e como eu devo colocar a assinatura JAVA desses métodos?

function DefHost(IPaddr: BSTR; ServPort: I4): I4; stdcall;
  //method DefLink
  function DefLink(pgmid: BSTR; commlen: I4): I4; stdcall;
  //method Link
  function Link: I4; stdcall;
  //method Release
  function Release: I4; stdcall;
  //method PutF
  function PutF(infield: BSTR; disp: I4; length: I4): I4; stdcall;
  //method GetF
  function GetF(disp: I4; length: I4): BSTR; stdcall;
  //method GetSpl
  function GetSpl(disp: I4; occurs: I4): BSTR; stdcall;
  //method GetCcw
  function GetCcw(disp: I4; occurs: I4): BSTR; stdcall;
  //method GetRLen
  function GetRLen(disp: I4; occurs: I4): I4; stdcall;
V

onde você esta dando loadLibrary da tua Dll que tu deseja invocar:?

Criado 18 de dezembro de 2007
Ultima resposta 19 de dez. de 2007
Respostas 3
Participantes 2