Jump to content
Excelsior Forums
Sign in to follow this  
mustang80

WinApi types and short* as an argument

Recommended Posts

Hi,

I have the function as below:

GXAPI HANDLE WINAPI GxInitReal(GX_REALINFO* pInfo);

where:

typedef struct {

? ? ?LPCTSTR ? ? ? ? ? ?filename;
? ? ?DWORD ? ? ? ? ? ?limit;
? ? ?DWORD ? ? ? ? ? ?time;
? ? ?BOOL ? ? ? ? ? ?memosave;
? ? ?LPSAVECALLBACK lpfunc;
? ? ?HWND ? ? ? ? ? ?hWnd;
? ? ?
} GX_REALINFO;

where:

#define ? ? ?DWORD ? ? ? ? ? ?unsigned long
#define ? ? ?BOOL ? ? ? ? ? ?bool

I declared it as following:

xFunction GxInitReal = new xFunction("Gx02", "int GxInitReal(GX_REALINFO*)");

and I invoked it as below:

Gx_RealInfo.filename = "D:\\dirjava\\GX-1Data\\pomiar_1";
Gx_RealInfo.limit = 0;
Gx_RealInfo.time = 1000;
Gx_RealInfo.memosave = 0;
Gx_RealInfo.lpFunction = null;
Gx_RealInfo.hWnd = 0;

int InitReal_result = ((Integer)GxInitReal.invoke(Pointer.createPointerTo(Gx_RealInfo))).intValue();

class GX_REALINFO extends Structure
{
? ? ?String filename; ? ? ?// Full path file name
? ? ?int limit; ? ? ? ? ? ? ? ? ? ? ? ? ? // Limitation value for the remaining HD space.
? ? ?int time; ? ? ? ? ? ? ? ? ? ? ? ? ? ?// Acquisition interval
? ? ?int memosave; ? ? ? ? ? ? ? ? ? // Whether to save voice memo 
? ? ?String lpFunction; // Call back function
? ? ?int hWnd; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// Window HANDLE

? ? ?public String defineLayout()
? ? ?{
? ? ? ? ? ?return "CSTRING filename, int limit, int time, int memosave, CSTRING lpFunction, int hWnd";
? ? ?}
? ? ?public GX_REALINFO() {}
}

My question is: ? Is it correct???

I am afraid this part:

Gx_RealInfo.filename = "D:\\dirjava\\GX-1Data\\pomiar_1";
Gx_RealInfo.lpFunction = null;

because last time I had this function:

GXAPI BOOL WINAPI GxSaveData(HANDLE hStandby, LPCTSTR filename, LPSAVECALLBACK pFunc, HWND hWnd);

and I built it as following:

xFunction GxSaveData = new xFunction("Gx02", "int GxSaveData(int,CSTRING,int*,int)");

Argument arg1_save = new Argument(GetStandby_result);
Argument arg2_save = new Argument("D:\\dirjava\\GX-1Data\\pomiar_1", Argument.CSTRING);
Argument arg3_save = new Argument("", Argument.CSTRING);
arg3_save = Pointer.NULL;
Argument arg4_save = new Argument(0);

int GxSaveData_result = ((Integer)GxSaveData.invoke(arg1_save, arg2_save, arg3_save, arg4_save)).intValue();

just like You advised me and it works for my.

But this time ?I have to declare it like:

Gx_RealInfo.filename = "D:\\dirjava\\GX-1Data\\pomiar_1"; 
Gx_RealInfo.lpFunction = null;

so is it correct?:huh:

I have one more question:

I have following function:

GXAPI BOOL WINAPI GxGetViewData(short* pData); 

where:

(1) Feature

Acquires view data at the current settings.

(2) Arguments

pData ?...... ?Pointer for storing acquired data. ?Sizes to be secured in advance are as follows:

? ? ? ? ? ?------------------------------------------------------------------------------------

(Waveform) Number of channels * 1000 + 16 bytes

? ? ? ? ? ?(FFT) Number of channels * 512 + 16 bytes

? ? ? ? ? ?(BAR) Number of channels * 4 + 16 bytes

? ? ? ? ? ?------------------------------------------------------------------------------------

so in Java I declared this function like below:

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

and I invoked it:

Pointer arg_view = Pointer.create("short* ?");
int GetViewData_result = ((Integer)GxGetViewData.invoke(arg_view)).intValue();
Short result = ((Short)arg_view.deref()).shortValue();

It is correct?

Share this post


Link to post
Share on other sites

1) In you case, i'd try to use 'int* lpFunction' and 'Pointer Gx_RealInfo.lpFunction = Pointer.NULL;' code. 'Gx_RealInfo.filename' part is correct.

2) Type of 'result' variable - is shall be 'short', not 'Short'.  Other code seems to be correct. Have you tried it yourself? Any problems in compile/run?

Share this post


Link to post
Share on other sites

Hi,

Yes I tried myself and I got error, because I didn't know that my function returns an array of short.

I changed my code, because now I know that my array should be: short[508].

so, my code looks like bellow:

Pointer arg_view = (Pointer)Argument.create("short*", new short[508]);
int GetViewData_result = ((Integer)GxGetViewData.invoke(arg_view)).intValue();
short[] result = (short[])arg_view.createArray(508);
for(int a=1; a<508; a++)
{
System.out.println("Result["+a+"]= " + result[a]);
}

It is corect???

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  

×