The code Below is part of a LIB to act as interfaz betwen a DLL ( similar to
DLL.LIB )
But in actual version of Harbour compile ok but create an error when use it
:
____________________________________________
Error: Error BASE/1068 Argument error: array access
Called from CALLDLL32(64)
Called from ABRIRPUERTO(71)
____________________________________________
May be a change in Harbour produce this error
Any Help with this ?
Thanks in advance
Bruno
////////////HDLL.prg
////////////////////////////////////////////////////////////////////////////////////////////
#define MAX_PARAMS 8
function CALLDLL32(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10)
local aPass := array(11)
local aParms := HB_aParams()
local nParmCnt := LEN(aParms)
local i
IF nParmCnt > MAX_PARAMS + 2
return 0
ENDIF
aPass[1] := aParms[1]
aPass[2] := aParms[2]
aPass[3] := nParmCnt-2
FOR i := 3 TO nParmCnt
aPass[i+1] := IIF(valtype(aParms[i]) == "C", STRPTR(aParms[i]),
aParms[i])
NEXT
return HB_DynaCall1(
aPass[1],aPass[2],aPass[3],aPass[4],aPass[5],aPass[6],aPass[7],aPass[8],aPass[9],aPass[10],aPass[11])
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
and the C part of the LIB
///////////////////////////////// CDLL.C
////////////////////////////////////////////////////////////////////
#include "windows.h"
#include "hbapi.h"
#define MAX_PARAMS 8
HINSTANCE HB_DllStore[256];
HINSTANCE HB_LoadDll(char *);
void HB_UnloadDll(void);
typedef int (CALLBACK *DYNACALL1)(void);
int HB_DynaCall(char *, char *, int, ...);
HINSTANCE HB_LoadDll (char *DllName)
{
static int DllCnt;
static int RegUnload;
if (!RegUnload) RegUnload=!atexit(HB_UnloadDll);
DllCnt=(DllCnt+1) & 255;
FreeLibrary(HB_DllStore[DllCnt]);
return HB_DllStore[DllCnt]=LoadLibrary(DllName);
}
HB_FUNC( UNLOADALLDLL )
{
HB_UnloadDll();
}
void HB_UnloadDll (void)
{
register int i;
for(i=255;i>=0;i--)
{
FreeLibrary(HB_DllStore[i]);
}
}
HB_FUNC( HB_DYNACALL1 )
{
hb_retnl(
HB_DynaCall(
hb_parc(1),
hb_parc(2),
hb_parnl(3),
hb_parnl(4),
hb_parnl(5),
hb_parnl(6),
hb_parnl(7),
hb_parnl(8),
hb_parnl(9),
hb_parnl(10),
hb_parnl(11)
)
);
}
int HB_DynaCall (char *FuncName, char *DllName, int nArgs, ...)
{
register int i;
HINSTANCE hInst;
DYNACALL1 lpAddr;
int arg;
int result = -2000;
//int *argtable = (int*)malloc(nArgs * sizeof *argtable);
int argtable[MAX_PARAMS];
char buff[256];
va_list ap;
hInst=GetModuleHandle(DllName);
if(hInst==NULL)
{
hInst=HB_LoadDll(DllName);
}
lpAddr=(DYNACALL1)GetProcAddress(hInst,FuncName);
if(lpAddr==NULL)
{
sprintf(buff,"%s%s",FuncName,"A");
lpAddr=(DYNACALL1)GetProcAddress(hInst,buff);
}
if(lpAddr==NULL)
{
sprintf(buff,"%s%s","_",FuncName);
lpAddr=(DYNACALL1)GetProcAddress(hInst,buff);
}
if (lpAddr)
{
va_start(ap,nArgs);
for (i=0; i<nArgs;i++)
{
arg = va_arg(ap,int);
argtable[i] = arg;
}
for (i=nArgs-1;i >=0; i--)
{
arg = argtable[i];
#if defined( __LCC__ )
_asm("pushl %arg")
#elif defined( __MINGW32__ )
__asm__("pushl %0" : : "r" (arg));
#elif defined( __BCPLUSPLUS__ )
asm push arg
#else
__asm{push arg}
#endif
}
result = (int)(lpAddr)();
va_end(ap);
}
return result;
}
HB_FUNC( STRPTR )
{
char *cString = hb_parc( 1 );
hb_retnl( ( LONG_PTR) cString );
}
HB_FUNC( PTRSTR )
{
hb_retc( (LPSTR) hb_parnl(1) );
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_______________________________________________
Harbour-users mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour-users