Calling dlls from EPrime
 
PST User Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



Calling dlls from EPrime Expand / Collapse
Author
Message
Posted 3/16/2008 5:02:54 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 3/16/2008 4:58:44 AM
Posts: 1, Visits: 1
To control a USB interface I am calling subroutines from a dll. This works just fine for most calls but the one thing I cant get E-Prime (Version 1) to do is to fill an array from the dll.
So, in standard Visual Basic, you pass a pointer to the array and fill it by doing this –
Private Declare Sub ReadAll Lib "k8055d.dll" (ByRef Data As Long)
then
Dim data(0 To 7) As Long
ReadAll(data(0))

But it doesn’t work in e-basic, and I tried all the variations I can think of!
Pointers anyone??

Post #1345
Posted 4/28/2010 8:06:42 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 4/2/2012 5:45:28 AM
Posts: 5, Visits: 66
Hi Alan,

You might try this :

This works fine in a DLL I made to use direct-input.
I am developing an alternative SR-box via the USB-port (the prototype works fine) and programmed a PIC, using a HID-USB interface and acting as a joystick.
In the DLL the button-presses an releases are events to direct-input and transferred to E-Prime ..
They may be directly used in an E-Prime response, or input by a function.


This is the E-Prime declaration :


dim Buttons(6) as long
dim retval as long


declare function PollJoyStickButtons Lib "ID_EPrime_lib" Alias "PollJoyStickButtons"
buttons() as long) as long


This is the E-Prime call :


RetVal = PollJoyStickButtons(buttons())


This is the DLL-definition :


extern "C" // Definitions of exported functions to E-Prime application ... -
{
//---------------------------------------------------------------------------
__declspec (dllexport) int CALLBACK PollJoyStickButtons(int* Buttons)
//---------------------------------------------------------------------------
{
int retval;

if(JoystickInputStarted)
{
retval = LibraryForm->PollJoyStickButtons(Buttons);
}
else
{
retval = -1;
}

return retval;
}
} // end of extern "C"


This is the method that polls the button-states ...


//---------------------------------------------------------------------------
int __fastcall TLibraryForm:ollJoyStickButtons(int* Buttons)
//---------------------------------------------------------------------------
{
int retval;

#define PRESSED(A) ((A) & 0x80)

if (Dx_JoyStickDevice->GetDeviceState(DIJoyState))
{
if (PRESSED(DIJoyState->Buttons[0])) Buttons[0] = 1; else Buttons[0] = 0;
if (PRESSED(DIJoyState->Buttons[1])) Buttons[1] = 1; else Buttons[1] = 0;
if (PRESSED(DIJoyState->Buttons[2])) Buttons[2] = 1; else Buttons[2] = 0;
if (PRESSED(DIJoyState->Buttons[3])) Buttons[3] = 1; else Buttons[3] = 0;
if (PRESSED(DIJoyState->Buttons[4])) Buttons[4] = 1; else Buttons[4] = 0;
if (PRESSED(DIJoyState->Buttons[5])) Buttons[5] = 1; else Buttons[5] = 0;
retval = 1;
}
else
{
retval = -1;
}

return retval;
}



As you can see, I am using Buttons() as parameter, giving the pointer to the start of the array.


I hope it will work for you ...

Good luck,

Eise.










Post #4297
« Prev Topic | Next Topic »


Permissions Expand / Collapse

All times are GMT -5:00, Time now is 4:10am

Powered By InstantForum.NET v4.1.4 © 2012
Execution: 0.156. 10 queries. Compression Disabled.
 
Privacy | Terms of Use | Terms and Conditions | Legal Trademarks | Authorized Use | Quality Policy
Copyright 2012 Psychology Software Tools, Inc. All Rights Reserved
Email: Info@pstnet.com | Telephone: 412.449.0078 | Fax: 412.449.0079