Bonjour à tous,

Dans le cadre de mon stage je dois faire communiquer SAP et Acrobat en vue d'un échnge de données. Je suis parti sur une solution me faisant interfacer Java (pour le JCO), et C++ via JNI (c++ étant le langage dans lequel les plugins sont codés avec Acrobat SDK).

Mon souci est que, bien que j'arrive parfaitement à appeler des fonctions Java depuis mon code C++, je n'arrive pas à avoir l'affichage du résultat de ma fonction de connexion à SAP depuis c++.

(je précise que celle-ci marche très bien depuis Java).

Quelqu'un aurait une idée s'il vous plait?

Le code source est le suivant:


Code Java:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

import com.sap.mw.jco.*;

class connectSAP {

	public static void Affiche ()
	{
		System.out.println("Test d'affichage de la methode ecrite en java mouhahahahaha");
	}
	
	public static int intMethod(int n)
	{
		return n*n;
	}
	
	public static void connect()
	   {
		   JCO.Client mConnection;
			
		    System.out.println("\nJe suis avant le try");
		   try {

			System.out.println("\nJe suis dans le try \n");
		       // Change the logon information to your own system/user

		       mConnection =

		          JCO.createClient("001", // SAP client

		            "usrid", // userid

		            "****", // password

		            "EN", // language

		            "hostname", // application server host name

		            "04"); // system number

			  				
		       System.out.println("test1");
		       
		       mConnection.connect();

		       System.out.println("test2");
		       
		       System.out.println("Attributs de connexion: \n"+mConnection.getAttributes()+"\n------------------------");
		       
		       System.out.println("hote: "+mConnection.getASHost()+"\n");
		       
		       System.out.println("test3");

		       mConnection.disconnect();

		    }

		    catch (Exception ex) {

		      ex.printStackTrace();

		      System.exit(1);

		    }
 
	   }

}

Code C++
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165

#ifdef __BORLANDC__
  #pragma argsused
#endif
 
#ifdef _WIN32
#define PATH_SEPARATOR ';'
#else
#define PATH_SEPARATOR ':'
#endif
 
#include <jni.h>
#include <windows.h>
#include <iostream>

using namespace std;
 
 
/**
*  You can find all installed JVMs' information in the Registry:
*  HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
*/
 
 
// typedef of functions needed to create the JVM dynamically
typedef jint (JNICALL GetCreatedJavaVMs_t)( JavaVM**, jsize, jsize* );
typedef jint (JNICALL CreateJavaVM_t)( JavaVM**, void **, void* );
 
// pointer declaration of those functions
GetCreatedJavaVMs_t *GetCreatedJavaVMs;
CreateJavaVM_t *CreateJavaVM;
 
// handling reference to jvm.dll
HINSTANCE hJvmDll;
 
 
int main( int argc, char * argv[] )
{
  jsize  nVMs;
  // pointer to the Virtual Machine instance interface
  JavaVM *jvm = (JavaVM *)0;
  // pointer to the thread instances interface which invokes Native APIs
  JNIEnv *env = (JNIEnv *)0;
 
  JavaVMInitArgs vm_args;
 
  jint status = -1;
  jclass cls;
  jmethodID mid;
  
 
  JavaVMOption options[1];
  options[0].optionString = "-Djava.class.path=H:\\";
 
 
  size_t bufLen = 1;
  jvm = (JavaVM *) malloc( sizeof(JavaVM) * bufLen );
 
  char debugStr[256];
 
  hJvmDll =
   LoadLibrary( "C:\\Program Files\\Java\\jre1.6.0\\bin\\client\\jvm.dll" );
 
  if ( hJvmDll != NULL )
  {
     GetCreatedJavaVMs =
       (GetCreatedJavaVMs_t*)GetProcAddress( hJvmDll, "JNI_GetCreatedJavaVMs" );
 
     CreateJavaVM =
       (CreateJavaVM_t*)GetProcAddress( hJvmDll, "JNI_CreateJavaVM" );
 
     if ( GetCreatedJavaVMs != NULL && CreateJavaVM != NULL)
        {
			sprintf( debugStr, "TOTO \n\n" );
			printf(debugStr);

          status = GetCreatedJavaVMs( &jvm, bufLen, &nVMs);
 
          if ( status != -1)
          {
              sprintf( debugStr, "There are %d VM(s) running\r\n", nVMs );
              printf(debugStr);
          }
 
          if (nVMs == 0)
          {
             vm_args.version = JNI_VERSION_1_6;
             vm_args.options = options;
             vm_args.nOptions = 1;
             vm_args.ignoreUnrecognized = JNI_TRUE;
 
             status = CreateJavaVM( &jvm, (void**) &env, &vm_args );
             if ( status == JNI_OK )
             {
                sprintf( debugStr, "VM lancee -- Launching VM okay.\r\n" );
                printf(debugStr);
             }
          }
        }
  }
 
 
  if (status == JNI_OK)
  {

	  sprintf( debugStr, "JNI_OK\n\n" );
	  printf(debugStr);


      cls = (env)->FindClass("connectSAP");

      if(cls !=0)
      {  
		sprintf( debugStr, "cls_OK\n\n" );
	  printf(debugStr);
		
		 mid = (env)->GetStaticMethodID( cls, "intMethod", "(I)I");
	        if(mid !=0)
	        {  
				sprintf( debugStr, "getMethod_int_OK\n\n" );
				printf(debugStr);

				jint square = (env)->CallStaticIntMethod(cls, mid, 5);
		       printf("Result of intMethod: %d\n", square);
	        }


			
		  mid = (env)->GetStaticMethodID( cls, "Affiche", "()V");
			if(mid !=0)
	        {  
				sprintf( debugStr, "getMethod_aff_OK\n\n" );
				printf(debugStr);

				sprintf( debugStr, "Affichage de la methode Affiche\n\n" );
				printf(debugStr);

				(env)->CallStaticVoidMethod(cls, mid);

		     }
			
			
			mid = (env)->GetStaticMethodID( cls, "connect", "()V");
			if(mid !=0)
	        {  
				sprintf( debugStr, "\n\n\n\ngetMethod_connect_OK\n\n" );
				printf(debugStr);

				sprintf( debugStr, "Affichage de la methode Connection\n\n" );
				printf(debugStr);

				(env)->CallStaticVoidMethod(cls, mid);
			}
			
    }
      (jvm)->DestroyJavaVM();
	  system("pause");
      return 0;
  }
  else
     return status;

  system("pause");
}

D'avance merci.