For debugging reasons, I am writing a jna wrapper for the C ++ DLL (compiled with gcc and mingw32)
write16Byte.dll
void write16Byte(const BYTE* mem) {
FILE* out = fopen("BSTRvalues.txt", "a+");
if (out == NULL) {
printf("Error opening file!\n");
return;
}
for (int i=0; i<16; i++) fprintf(out, "0x%x ", mem[i]);
fwprintf(out, L"\n");
fclose(out);
}
jna wrapper
public interface W16BDll extends com.sun.jna.Library {
W16BDll INSTANCE = (W16BDll)com.sun.jna.Native.loadLibrary("write16Byte.dll", W16BDll.class);
void write16Byte(com.sun.jna.Memory version);
}
Calling fprintf leads to "java.lang.Error: Invalid memory access" because when I delete fprintf everything works fine (I already read the thread in JNA Invalid memory access when writing to stdout )
source
share