DLL Wrapping

Previous topic - Next topic

Gary

I have followed Kittys tutorial on this but when I try to use a different DLL file I am having problems.

I have a DLL to control an external USB device and am starting off by trying to send a simple wake up call to the device

The C prototype for the function is as follows

Code (glbasic) Select

10.3 OpenMHE
10.31,1 Synopsis
This call is made by the PC application software to open the "Money Handling Equipment" Interface.

long OpenMHE (void);

10.31,2 Parameters
None

10.31,3 Return Value
If the Open call succeeds then the value zero is returned.
In the event of a failure one of the following standard windows error codes will be returned, either as a direct echo of a Windows API call failure, or to indicate internally detected failures that closelycorrespond to the quoted meanings.
Error Number  Suggested string for English decoding        Microsoft Mnemonic    Retry
13            The DLL, application or device are at
              incompatible revision levels.
                                                           ERROR_INVALID_DATA    No
20            The system cannot find the device
              specified.
                                                           ERROR_BAD_UNIT        No
21            The device is not ready.                     ERROR_NOT_READY Yes
1167          The device is not connected.             ERROR_DEVICE_NOT_CONNECTED Yes


the code I am using in GLBasic to try to set up this function is as follows

Code (glbasic) Select
WHILE KEY(28)=0 // wait for return to exit
DEBUG OpenMHE()
WEND


INLINE
extern "C" {
DECLARE_ALIAS(exportOpenMHE, "aesimhei.dll", "OpenMHE", (void), long);}
ENDINLINE

FUNCTION OpenMHE:

INLINE
IF(exportOpenMHE)     
RETURN exportOpenMHE();
ENDINLINE

ENDFUNCTION


when I try to compile this I get the error

Code (glbasic) Select
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:79: error: expected unqualified-id before string constant
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::OpenMHE()':
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:114: error: `exportOpenMHE' was not declared in this scope
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:114: error: `IF' was not declared in this scope
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:116: error: expected `;' before "RETURN"


I have about 20 commands I need to wrap but if I cant get this one running there is no point in carrying on lol

I can provide the DLL file if anyone requires it to be able to help

Thanks in advance
Gary

Kitty Hello

remove the extern "C" { } and make that DECLARE_C_ALIAS?

Gary

Hi Kitty

I changed it to

Code (glbasic) Select
INLINE
DECLARE_C_ALIAS(exportOpenMHE, "aesimhei.dll", "OpenMHE", (void), long);
ENDINLINE


And get the error

Code (glbasic) Select
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::OpenMHE()':
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:112: error: `exportOpenMHE' was not declared in this scope
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:112: error: `IF' was not declared in this scope
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:114: error: expected `;' before "RETURN"


I have attached the project and the DLL if that helps

Regards
Gary

[attachment deleted by admin]

Kitty Hello

Code (glbasic) Select

WHILE KEY(28)=0 // wait for return to exit
DEBUG OpenMHE()
WEND

FUNCTION must_end_main_or_start_new_file:
ENDFUNCTION



INLINE
DECLARE_ALIAS(exportOpenMHE, "aesimhei.dll", "OpenMHE", (void), long);
ENDINLINE

FUNCTION OpenMHE:

INLINE
if(exportOpenMHE)     
return exportOpenMHE();
ENDINLINE

ENDFUNCTION



compiles for me.

Gary

Ahh thanks Kitty

It was when the IF and RETURN were in capitals it broke the compilier

Just need to work out now why I am not getting the response I expected from the board :(
Thanks again for your help

Gary

Kitty Hello

try either:
DECLARE_C_ALIAS instead of DELCARE_ALIAS


Gary

Was simpler as that, when I checked other threads I made the same mistake as others did and didnt copy the actual call name from Dependancy Walker, I needed to have _OpenMHE@0 as the routine name and not OpenMHE

Cheers
Gary

Gary

Apologies for asking another couple of questions but I have 2 commands I cant import and wondered if anyone could point me in the right direction

First one is this header

Code (glbasic) Select
14.4 ReadCounterCaption

14.41,1 Synopsis
The ReadCounterCaption call is used to determine the caption for the specified counter

char* ReadCounterCaption(long CounterNo);

14.41,2 Parameters
1. CounterNo
This is the number of the counter to be incremented.

14.41,3 Return Value
None

14.41,4 Remarks
1. If the counter specified is higher than the highest supported, then the call returns an empty string ("").
2. All captions stored in the meter are read out at system start-up and used to initialise the captions used by the interface.


I thought the correct GLBasic code would be

Code (glbasic) Select
DECLARE_C_ALIAS(exportReadCounterCaption, "aesimhei.dll", "_ReadCounterCaption@4", (long), char*);

with this to read it

Code (glbasic) Select
FUNCTION ReadCounterCaption: meternum
INLINE
if(exportReadCounterCaption)
return exportReadCounterCaption(meternum);
ENDINLINE
ENDFUNCTION


but when I compile it I get the following error

Code (glbasic) Select
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::ReadCounterCaption(DGInt)':
C:\DOCUME~1\Owner\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:218: error: cannot convert `char*' to `DGInt' in return


The second one is I have a function with the following header

Code (glbasic) Select
11.6 ReadDispenserDetails

11.61,1 Synopsis

The ReadDispenserDetails call provides a snapshot of all the information possessed by the interface
on a single unit of money dispensing equipment.
bool ReadDispenserDetails( long Number,DispenserBlock* Snapshot) ;

11.61,2 Parameters

1. Number
The serial number of the coin or note dispenser about which information is required.

2. Snapshot
A pointer to a program buffer, into which all the information about the specified dispenser will be copied.

11.61,3 Return Value
True if the specified input device exists, False if the end of the list is reached.

11.61,4 Remarks
The serial numbers of the dispensers are contiguous and run from zero upwards.


What would be the GLBasic code to import that function?

Many thanks again
Gary

Kitty Hello

The function returns a char* - that is a C string (a pointer to the first character of the string characters buffer.)
Code (glbasic) Select

function foo$: in% // output is a string
inline
DGStr retv = (const char*)c_function(in);
return retv;
endinline
endunfunction


Try that.