logo       

Help - Calling a DLL Entry Point - Help with instructions string for serial: msg#00000

windows.devel.jawin

Subject: Help - Calling a DLL Entry Point - Help with instructions string for serializing

Hi all:

I need to invoke a function inside a third-party legacy DLL. I know the name
of the function and I also have the ``.h" file of the DLL. The problem is
that I'm not familiar with the C/C++ world and I'm not able to pass the
parameters to the DLL function properly.

I have seen and executed the examples and all work fine. Now I'm trying to
modify the ``HelloDllGeneric.java" example to adapt it to my needs, but I'm
not having success at all.

This is the content of the header file:
---------------------------------- HEADER FILE
----------------------------------
///////////////////////////////////////////////////////////////////////////////
// <COMPANY INFORMATION DELETED>
// Version 1.0
///////////////////////////////////////////////////////////////////////////////
#ifndef __IMPORTP12__
#define __IMPORTP12__


//######################################
//Datatype definition
//#######################################
typedef long (WINAPI *PFUNCSETPARAM)(int, void *);
typedef long (WINAPI *PFUNCIMPORTCERTIFICATE)(char *,char *);

///////////////////////////////////////////////////////////////////////////////
//Prototypes of the exported functions by the DLL
///////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////
// Name: setParam
// Description: Sets generic DLL params
// Params: [in] nTypeParam Parameter type to be set
// [in] pvParam Pointer to void with the value of to parameter to
be set
// Return: ERROR_SUCCESS if all works correctly
// WIN32 error code if something wrong happens
/////////////////////////////////////////////////////////////////////////////////////////
long __stdcall setParam(int nTypeParam,
void *pvParam);


/////////////////////////////////////////////////////////////////////////////////////////
// Nombre: importCertificate
// Description: Inject a P12 cert in the smartcard
// Params: [in] pcPath String with the fullpath of the P12 cert to be
loaded in the smartcard
// [in] pcPassword String with the password of the P12
// Return: ERROR_SUCCESS if all works correctly
// WIN32 error code if something wrong happens
/////////////////////////////////////////////////////////////////////////////////////////
long __stdcall importCertificate(char *pcPath,
char *pcPassword);

#endif
---------------------------------- /HEADER FILE
----------------------------------

The DLL provider remarks in a doc that pcPath and pcPassword are strings of
ASCII chars.

The only function I need is ``importCertificate". The ``setParam" function
is reserved for future uses, says the DLL provider company.

My java code is the next:

---------------------------------- JAVA CODE
----------------------------------
[...]
public static void z() throws Exception{
FuncPtr msgBox = null;
String ruta = "c:\\Temp\\uactivo951v_firma.p12";
String clave = "1234";
System.out.println("ruta: " + ruta);
try {
msgBox = new FuncPtr("ImportP12.DLL", "importCertificate");

// create a NakedByteStream for the serialization of Java
variables
NakedByteStream nbs = new NakedByteStream();

// wrap it in a LittleEndianOutputStream
LittleEndianOutputStream leos = new
LittleEndianOutputStream(nbs);

// and then write the Java arguments
leos.writeStringUnicode(ruta);
leos.writeStringUnicode(clave);

// (1) leos.writeChars(ruta);
// (1) leos.writeChars(clave);
// (2) leos.writeStringANSI(ruta);
// (2) leos.writeStringANSI(clave);

// call the generic invoke, with the NakedByteStream
// and parameters describing how to deserialize the
// NakedByteStream byte-array on the native side
byte[] resultado = msgBox.invoke("GG:I:", 12, nbs, null,
ReturnFlags.CHECK_W32);
System.out.println("--- END ---");
} catch (COMException e) {
// handle exception
e.printStackTrace();
throw new RuntimeException(e);
} finally {
if (msgBox != null) {
try {
msgBox.close();
} catch (COMException e) {
// handle fatal exception
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
}
[...]
---------------------------------- /JAVA CODE
----------------------------------

Remarks:
All imports are made properly.
Jawin.dll and ImportP12.dll are in a directory reachable (I mean that
all ``loadLibrary" executions are working fine).
I have tried to make it in serveral different ways as you can see below:



A) With:

leos.writeStringUnicode(ruta);
leos.writeStringUnicode(clave);
[...]
byte[] resultado = msgBox.invoke("GG:I:", 12, nbs, null,
ReturnFlags.CHECK_W32);

The output I get is the next:

---------------------------------- OUTPUT ----------------------------------
ruta: c:\Temp\uactivo951v_firma.p12
Loading jawin from hardcoded path C:\Documents and Settings\juser\Mis
documentos\downloads\Java\Jawin\jawin-2.0-alpha1\bin\debug\jawind.dll
org.jawin.COMException: 2: El sistema no puede hallar el archivo
especificado.*

at org.jawin.marshal.GenericStub.win32Invoke0(Native Method)
at org.jawin.marshal.GenericStub.win32Invoke(GenericStub.java:152)
at org.jawin.FuncPtr.invoke(FuncPtr.java:186)
at org.jawin.FuncPtr.invoke(FuncPtr.java:205)
at CertificateImporter.z(CertificateImporter.java:83)
at CertificateImporter.main(CertificateImporter.java:13)
java.lang.RuntimeException: org.jawin.COMException: 2: El sistema no puede
hallar el archivo especificado.*

at CertificateImporter.z(CertificateImporter.java:88)
at CertificateImporter.main(CertificateImporter.java:13)
Caused by: org.jawin.COMException: 2: El sistema no puede hallar el archivo
especificado.*

at org.jawin.marshal.GenericStub.win32Invoke0(Native Method)
at org.jawin.marshal.GenericStub.win32Invoke(GenericStub.java:152)
at org.jawin.FuncPtr.invoke(FuncPtr.java:186)
at org.jawin.FuncPtr.invoke(FuncPtr.java:205)
at CertificateImporter.z(CertificateImporter.java:83)
... 1 more
Exception in thread "main"
---------------------------------- /OUTPUT
----------------------------------

*: This message is in Spanish. A translation wold be: The system can't find
the indicated file

I think that the string contained in the var ``ruta" (= path in english),
when arrieves into the C/C++ side hasn't the same content than in the Java
side, and thus the DLL function isn't able to find the file and fails when
try to access it.



B) Uncommenting the lines marked with (1), and commenting the two previous:

// leos.writeStringUnicode(ruta);
// leos.writeStringUnicode(clave);
leos.writeChars(ruta);
leos.writeChars(clave);

[...]

The output is the next:

---------------------------------- OUTPUT ----------------------------------
ruta: c:\Temp\uactivo951v_firma.p12
Loading jawin from hardcoded path C:\Documents and Settings\juser\Mis
documentos\downloads\Java\Jawin\jawin-2.0-alpha1\bin\debug\jawind.dll
org.jawin.COMException: 8000ffff: Invalid ptr null flag
at org.jawin.marshal.GenericStub.win32Invoke0(Native Method)
at org.jawin.marshal.GenericStub.win32Invoke(GenericStub.java:152)
at org.jawin.FuncPtr.invoke(FuncPtr.java:186)
at org.jawin.FuncPtr.invoke(FuncPtr.java:205)
at CertificateImporter.z(CertificateImporter.java:83)
at CertificateImporter.main(CertificateImporter.java:13)
java.lang.RuntimeException: org.jawin.COMException: 8000ffff: Invalid ptr
null flag
at CertificateImporter.z(CertificateImporter.java:88)
at CertificateImporter.main(CertificateImporter.java:13)
Caused by: org.jawin.COMException: 8000ffff: Invalid ptr null flag
at org.jawin.marshal.GenericStub.win32Invoke0(Native Method)
at org.jawin.marshal.GenericStub.win32Invoke(GenericStub.java:152)
at org.jawin.FuncPtr.invoke(FuncPtr.java:186)
at org.jawin.FuncPtr.invoke(FuncPtr.java:205)
at CertificateImporter.z(CertificateImporter.java:83)
... 1 more
Exception in thread "main"
---------------------------------- /OUTPUT
----------------------------------



C) Uncommenting the lines marked with (2), and commenting the four previous:

// leos.writeStringUnicode(ruta);
// leos.writeStringUnicode(clave);
// leos.writeChars(ruta);
// leos.writeChars(clave);
leos.writeStringANSI(ruta);
leos.writeStringANSI(clave);
[...]

The output is the next:
---------------------------------- OUTPUT ----------------------------------
ruta: c:\Temp\uactivo951v_firma.p12
Loading jawin from hardcoded path C:\Documents and Settings\acardenas\Mis
documentos\downloads\Java\Jawin\jawin-2.0-alpha1\bin\debug\jawind.dll
org.jawin.COMException: 8000ffff: passed end of stream in the marshalling
layer
at org.jawin.marshal.GenericStub.win32Invoke0(Native Method)
at org.jawin.marshal.GenericStub.win32Invoke(GenericStub.java:152)
at org.jawin.FuncPtr.invoke(FuncPtr.java:186)
at org.jawin.FuncPtr.invoke(FuncPtr.java:205)
at CertificateImporter.z(CertificateImporter.java:83)
at CertificateImporter.main(CertificateImporter.java:13)
java.lang.RuntimeException: org.jawin.COMException: 8000ffff: passed end of
stream in the marshalling layer
at CertificateImporter.z(CertificateImporter.java:88)
at CertificateImporter.main(CertificateImporter.java:13)
Caused by: org.jawin.COMException: 8000ffff: passed end of stream in the
marshalling layer
at org.jawin.marshal.GenericStub.win32Invoke0(Native Method)
at org.jawin.marshal.GenericStub.win32Invoke(GenericStub.java:152)
at org.jawin.FuncPtr.invoke(FuncPtr.java:186)
at org.jawin.FuncPtr.invoke(FuncPtr.java:205)
at CertificateImporter.z(CertificateImporter.java:83)
... 1 more
Exception in thread "main"
---------------------------------- /OUTPUT
----------------------------------



I've tried the B) and C) in order to test another ways to pass the content
of the strings to the C/C++ side, but it hasn't been succesful.

Could anybody help me? Is my ``invoke("GG:I:", 12, nbs, null,
ReturnFlags.CHECK_W32);" coherent with the interface of the function? If
not, how should I pass the content of strings in ``ruta" y ``clave" to the
C/C++ side?

Thank you in advance,

Alberto



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise