9 messages in net.java.dev.jna.usersRe: [jna-users] Need help for beginner
FromSent OnAttachments
Hao JiangFeb 10, 2009 3:16 pm 
Daniel KaufmannFeb 10, 2009 4:58 pm 
Timothy WallFeb 10, 2009 5:00 pm 
Hao JiangFeb 11, 2009 9:08 am 
Hao JiangFeb 11, 2009 12:53 pm 
Timothy WallFeb 11, 2009 2:09 pm 
Timothy WallFeb 11, 2009 2:11 pm 
Hao JiangFeb 11, 2009 2:35 pm 
Hao JiangFeb 12, 2009 9:41 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Need help for beginnerActions...
From:Timothy Wall (twal@dev.java.net)
Date:Feb 11, 2009 2:09:55 pm
List:net.java.dev.jna.users

On Feb 11, 2009, at 12:08 PM, Hao Jiang wrote:

Thanks for help

Now I have a serious issue, the JVM crashed. I thinks it's because of the Info structure

In C it like this

typedef struct { char* a; StructA sa; StructB* sb; double c; double d; } Info;

And the things I want are c and d. I think may have to create class of StructA, but just use a Pointer for StructB, that's my code

public static class StructA extends Structure{ public int x, y}

public static class Info extends Structure{ public String a; public StructA sa; public Pointer sb; public double c; public double d; }

Is this correct?

Yes, that is correct. You can also make field "sb" implement StructureByReference, but there's no point to doing that if you don't need the structure contents.

Thanks

Hao

-----Original Message----- From: Timothy Wall [mailto:twal@dev.java.net] Sent: Tuesday, February 10, 2009 6:01 PM To: use@jna.dev.java.net Subject: Re: [jna-users] Need help for beginner

On Feb 10, 2009, at 6:16 PM, Hao Jiang wrote:

Hi,

I just found this tool and hope it can solve my problem, I'm in a rush

to finish some work so will really appreciate if someone can help me out

Basically I need to access 2 functions in a dll

int Load

( const char* aFilename,

Handle* aLayer,

int aLoadFlags);

typedef void* Handle;

here I translate it into java function

int load(String fName, PointerByReference pr, int flag);

It seems working, the return int is an error code which tells me no error.

Then I need to call this function

const Info* Info

(

Handle aLayer

);

Here Info is a structure and I've created class for it extends Structure, I translate this function in java like this

Pointer Info(Pointer p);

Call it after the first function

PointerByReference pr = new PointerByReference(); Int error = load("a.txt", pr, 0); Pointer p = Info(pr.pr.getPointer());

Use pr.getValue(), not pr.getPointer(). The former is the returned pointer value, the latter is the address where the value was stored.

No error so far, I just have no idea how to continue to get structure (Info) out of Pointer (p)

Thanks for any help

Hao

Structure.useMemory(Pointer) followed by Structure.read(). Or simply declare the return type to be your structure type.

--------------------------------------------------------------------- To unsubscribe, e-mail: user@jna.dev.java.net For additional commands, e-mail: user@jna.dev.java.net

*************************************************************************

PRIVILEGE AND CONFIDENTIALITY NOTICE:

The information in this email is intended for the named recipients only.

It may contain privileged and confidential information. If you have

received this communication in error, any use, copying or dissemination

of its contents is strictly prohibited. Please erase all copies of the

message along with any included attachments and notify Intermap

Technologies or the sender immediately by telephone at the number

indicated on this page.