Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in using JNA to call win32 api "AddFontMemResourceEx"

 
Abhi Ahuja
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to use the win32 API AddFontMemResourceEx (http://msdn.microsoft.com/en-us/library/dd183325%28v=vs.85%29.aspx) using JNA.

My interface declaration:

public interface GDILib extends Library
{
int AddFontMemResourceEx(/*byte[]*/ Memory font, int noOfBytes, int pdv, IntByReference NoOfFonts);
}

Usage in main:

public static void main(String[] args)
{
GDILib lib = (GDILib) Native.loadLibrary("gdi32", GDILib.class);
lib.AddFontMemResourceEx(m, b.length, 0, noOfFonts1);

}

I am guessing the first parameter of the AddFontMemResourceEx() has some issue. I have tried to pass ByteArrayInputStream, FileInputStream, byte[] and memory. None of them seem to work. I am not getting any exception but it just doesnot set the fourth parameter, it always zero.

Also, I am able to achieve the same using the method "AddFontResourceEx" (http://msdn.microsoft.com/en-us/library/dd183327%28v=vs.85%29.aspx), but I owuld like to achieve using Stream

Thanks, please help.


 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I recall correctly, PVOID is little more than void *, in other words any generic pointer. That would mean you should use Pointer as the parameter type. You can still use Memory as the argument since Memory extends Pointer. The signature would then become this:
Instead of 0 for the third argument you would use Pointer.NULL.
 
Abhi Ahuja
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob, Thanks a lot for the reply.

I still could not make it work, Please take a look at the code I used, please suggest if I am wrong somewhere.

Interface:
interface GDILib extends Library
{
int AddFontMemResourceEx(Pointer font, int noOfBytes, Pointer pdv, IntByReference NoOfFonts);
}

Main:

public static void main(String[] args)
{
GDILib lib = (GDILib) Native.loadLibrary("gdi32", GDILib.class);

Memory m = new Memory(b.length);
FileInputStream fileInputStream = new FileInputStream(file);
fileInputStream.read(b);
m.read(0, b, 0, b.length);
lib.AddFontMemResourceEx(m.getPointer(1L), b.length, Pointer.NULL, noOfFonts1);
lib.AddFontMemResourceEx(m, b.length, 0, noOfFonts1);

}

Please suggest.
Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't used JNA before so this is where my help ends. I always preferred JNI.
 
Abhi Ahuja
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Problem Rob, Thanks anyways.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic