Jump to content
Excelsior Forums
Sign in to follow this  
mustang80

WINAPI types and xFunction ???

Recommended Posts

Hi,

I am wondering if is possible to use WINAPI types with xFunction???

I have following functions which I have to call form Gx02.dll in Java in following sequence:

GXAPI HANDLE WINAPI GxOpenData(GX_DATAINFO* pInfo);
GXAPI HANDLE WINAPI GxGetStandby(HANDLE hFile);
GXAPI BOOL WINAPI GxGetData(HANDLE hStandby, UINT nCh, short* pData, long nSize);
GXAPI BOOL WINAPI GxSaveData(HANDLE hStandby, LPCTSTR filename, LPSAVECALLBACK pFunc, HWND hWnd);

where:

first function (GxOpenData) returnes:

0   if there is an error

1  if everything is right

and GX_DATAINFO is declared:

typedef struct {

     WORD            device;
     WORD            id;
     DWORD            startsample;
     DWORD            endsample;
     BYTE            rsv[4];
     char            name[8];
     char            dir[8];
     
} [b]GX_DATAINFO[/b];

second  function (GxGetStandby) returnes:

handle for standby for downloading

and:

hFile - handle returned with GxOpenData

third function: GxGetData has argument:

hStandby- handle returned with GxGetStandby

and last function has arguments as below:

hStandby- handle returned with GxGetStandby

filename- name of a file to be save

pFunc- call back function

hWnd- window HANDLE passed with GxSaveData function

where:

// callback function

typedef BOOL (CALLBACK SAVECALLBACK)(UINT nSave, UINT nRate, HWND hWnd);
typedef SAVECALLBACK FAR* LPSAVECALLBACK;

I know how I should declare:

- GX_DATAINFO struct in Java

- UINT nCh, short* pData, long nSize

because it is in examples, but I have not idea how I should declare:

1. returned value, I mean HANDLE in first function:

   

xFunction GxOpenData = new xFunction("Gx02", " GxOpenData(GX_DATAINFO*)");

2. LPCTSTR filename, LPSAVECALLBACK pFunc, HWND hWnd and:

typedef BOOL (CALLBACK SAVECALLBACK)(UINT nSave, UINT nRate, HWND hWnd);

typedef SAVECALLBACK FAR* LPSAVECALLBACK;

in the last function???

Any help will be appreciate.

Share this post


Link to post
Share on other sites

The general rule is to find out which C type represents given WINAPI type. It can be found either in MSDN or in standard headers (windef.h etc.). In particular, BOOL and all handles (HANDLE, HWND etc.) may be though of as usual 'int', so it is mapped to Java int.

LPCTSTR is either CSTRING or UNICODESTRING, depending of whether 'UNICODE' symbol was defined when your module have been compiled.

Regarding LPSAVECALLBACK: if the callback is supposed to be really invoked - you have to define it in Java (i.e. derive com.excelsior.xFunction.Callback class, see samples 7,8,9). Otherwise, it is safe to declare the type as "int*" and provide Pointer.NULL as argument.

Share this post


Link to post
Share on other sites

Hi,

Thank You for quickly replay.

I managed with three of four this functions.

Unfortunatelly I couldn't manage with this one, which would seems to be easy.

So, this functions works for me:

GXAPI HANDLE WINAPI GxOpenData(GX_DATAINFO* pInfo); 
GXAPI HANDLE WINAPI GxGetStandby(HANDLE hFile); 
GXAPI BOOL WINAPI GxSaveData(HANDLE hStandby, LPCTSTR filename, LPSAVECALLBACK pFunc, HWND hWnd); 

but this one doesn't works:

GXAPI BOOL WINAPI GxGetData(HANDLE hStandby, UINT nCh, short* pData, long nSize); 

where:

hStandby- Handel returned with GxGetStandby

nch- The number of channel

pData- Pointer to the buffer to store acquired data

nSize- Size of data be acquired (by a byte)

So, I simple declared this function as follows:

xFunction GxGetData = new xFunction("Gx02", "int GxGetData(int,int,short*,long)");

Argument arg1 = new Argument(GetStandby_result);
Argument arg2 = new Argument(n_chanel);
short[] array3 = new short[512];
Pointer arg3 = (Pointer)Argument.create("short*", array3);
Argument arg4 = new Argument(10000000);

int GetData_result = ((Integer)GxGetData.invoke(arg1,arg2,arg3,arg4)).intValue();

but I got this  error:

Exception in thread "main" com.excelsior.xFunction.IncompatibleArgumentTypeException: The argument number '3' is not compatible with the one specified in signature.

What could be wrong with this code???

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×