Para o pessoal que solicitou o codigo exemplo, ai vai.

Criar um projeto no Visual C++ com os arquivos :
      IntAcesso.c
      IntAcesso.h

Compile gerando uma DLL.


A classe IntAcesso.java contém um método nativo para chamada da DLL


Para executar a DLL é só utilizar este codigo em qualquer aplicação Java

    IntAcesso acesso = new IntAcesso();
    String user =  acesso.getUser();




(See attached file: IntAcesso.java)(See attached file: IntAcesso.h)(See
attached file: IntAcesso.c)

Attachment: =?iso-8859-1?Q?IntAcesso.java?=
Description: Binary data

#include <jni.h>

#ifndef _Included_IntAcesso
#define _Included_IntAcesso
#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT jstring JNICALL Java_IntAcesso_getUser
  (JNIEnv *, jclass);

#ifdef __cplusplus
}
#endif
#endif
#include "IntAcesso.h"
#include <string.h>
#include <stdlib.h>


#include <windows.h>


#include <malloc.h>
#include <memory.h>
#include <tchar.h>


JNIEXPORT jstring JNICALL Java_IntAcesso_getUser
  (JNIEnv* env, jclass cl)
{

   char * cret;
   jstring ret;

   BOOL bOk = TRUE;
   TCHAR szUserName[80];
   DWORD dwSize = 80;

   cret = (char*)malloc(80);

   if (GetUserName(szUserName, &dwSize))
     strcpy(cret,(char *)szUserName);
   else
     strcpy(cret,"");

   ret = (*env)->NewStringUTF(env, cret);
   free(cret);

   return ret;
}

------------------------------ LISTA SOUJAVA ----------------------------
http://www.soujava.org.br  -  Sociedade de Usuários Java da Sucesu-SP
dúvidas mais comuns: http://www.soujava.org.br/faq.htm
regras da lista: http://www.soujava.org.br/regras.htm
historico: http://www.mail-archive.com/java-list%40soujava.org.br
para sair da lista: envie email para [EMAIL PROTECTED]
-------------------------------------------------------------------------

Responder a