Get your CodeRanch badge!*
The moose likes Other JSE/JEE APIs and the fly likes Problem in using JNA to call win32 api Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Problem in using JNA to call win32 api "AddFontMemResourceEx"" Watch "Problem in using JNA to call win32 api "AddFontMemResourceEx"" New topic
Author

Problem in using JNA to call win32 api "AddFontMemResourceEx"

Abhi Ahuja
Greenhorn

Joined: Oct 11, 2010
Posts: 7
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

Joined: Oct 27, 2005
Posts: 19541
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Abhi Ahuja
Greenhorn

Joined: Oct 11, 2010
Posts: 7
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

Joined: Oct 27, 2005
Posts: 19541
    
  16

I haven't used JNA before so this is where my help ends. I always preferred JNI.
Abhi Ahuja
Greenhorn

Joined: Oct 11, 2010
Posts: 7
No Problem Rob, Thanks anyways.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in using JNA to call win32 api "AddFontMemResourceEx"
 
Similar Threads
Get File Version
no tabbin for text box
Problem while installing activeX- Application is reloaded.
IE 8 compatibility Issue
CGI:Win32 Error Codes