Hi all,
I am newbie in unity and java. I have a project to modify an unity game application which this game is using java script. I want to add the haptic feedback for this application using my device.
I have dll library of my device which generate from .c and .h with visual studio 10 name tensLib.dll.
I have try like this:
#pragma strict
#pragma implicit
#pragma downcast
import System;
import System.Runtime.InteropServices;
class SController extends MonoBehaviour
{
// Public variables shown in inspector
@DllImport("tensLibs.dll")
//etc
}
but there is error occur :
BCE0153: ‘System.Runtime.InteropServices.DllImportAttribute’ can be applied on one of these targets only : Method.
my question is how to add and access .dll to java in unity?
Plugin support is documented here:
Note that plugins require Pro support.
Hi Graham,
Thank you for the answer, I have try this code using javascript:
@DllImport("tensLibs.dll")
public static function tens_init (string):int {};
but the error is like this
MarshalDirectiveException: Marshalling of type object is not implemented
I have tried to read this function using the c# and working, I am using this code:
[DllImport("tensLibs.dll", EntryPoint="tens_init")]
public static extern int tens_init ([MarshalAsAttribute(UnmanagedType.LPStr)]string port);
the function in c is like this:
static int tens_write( unsigned char* buf, int count )
{
unsigned char chksum = 0;
int i;
DWORD nbytes;
/* Are we connected? */
if ( hnd_serial == INVALID_HANDLE_VALUE ) {
PRINTF( "No serial connection.\n" );
return FALSE;
}
/* Generate checksum. */
for ( i = 0; i < count; i++ )
chksum ^= buf[i];
/* Attempt to transmit packet followed by checksum. */
if ( !WriteFile( hnd_serial, buf, count, &nbytes, NULL ) ||
!WriteFile( hnd_serial, &chksum, 1, &nbytes, NULL ) )
{
PRINTF( "Serial write error.\n"
"Connection closed.\n" );
CloseHandle( hnd_serial );
hnd_serial = INVALID_HANDLE_VALUE;
return FALSE;
}
return TRUE;
}
I have try to change the data type in javascript but still can not help. the error still appear.
I need to use this dll to be used in javascript.