From: Gerd on
Hi all,

I tried to create my own Ada bindings for a dll, but I didn't succeed.


The C-header contains:

DWORD __stdcall CAN_GetHwParam(
HCANHW hHw,
WORD wParam,
void* pBuff,
WORD wBuffLen);


My Ada-spec look like this:

with System;

package CanApi2 is

pragma Linker_Options ("-lCanApi2");

subtype
HCANHW is Integer;

subtype
Word is Integer;

function CAN_GetHwParam (hHw : HCANHW; wParam : Word; pBuff :
System.Address; wBuffLen : Word) return Integer;

private
pragma Import (Stdcall, CAN_GetHwParam, External_Name =>
"CAN_GetHwParam");
end CanApi2;

The lib-file (CanApi2.lib) contains this names:

_CAN_GetHwParam(a)16 __imp__CAN_GetHwParam(a)16 _CAN_SetHwParam(a)12
__imp__CAN_SetHwParam(a)12


And that's what I get when build my test-program:

C:\Work\CAN>gnatmake cantest
gcc -c cantest.adb
gcc -c canapi2.ads
gnatbind -x cantest.ali
gnatlink cantest.ali
../cantest.o(.text+0x264):cantest.adb: undefined reference to
`CAN_GetHwParam(a)16'

gnatlink: cannot call C:\GNAT\bin\gcc.exe
gnatmake: *** link failed.

DLL2DEF shows this:

EXPORTS
CAN_GetHwParam


So what's wrong with my code? Please help, thanks.

Gerd

From: Dmitry A. Kazakov on
On 17 May 2006 23:46:23 -0700, Gerd wrote:

> The C-header contains:
>
> DWORD __stdcall CAN_GetHwParam(
> HCANHW hHw,
> WORD wParam,
> void* pBuff,
> WORD wBuffLen);

[...]
> function CAN_GetHwParam (hHw : HCANHW; wParam : Word; pBuff :
> System.Address; wBuffLen : Word) return Integer;
>
> private
> pragma Import (Stdcall, CAN_GetHwParam, External_Name =>
> "CAN_GetHwParam");

What about "_CAN_GetHwParam"? It looks like 'extern "C"' stuff.

Or maybe, pragma Import (C, CAN_GetHwParam, "CAN_GetHwParam");

BTW, is it a CAN-bus adapter APIs? Which vendor?

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: Gerd on
> What about "_CAN_GetHwParam"? It looks like 'extern "C"' stuff.

The GNAT Users Guide say that the "_" and the "@16" is appended
automatically for "__stdcall" (as far as I understood). And the
function is declared as "__stdcall" in the header-file.


> BTW, is it a CAN-bus adapter APIs? Which vendor?

Yes, it is. It's a "PEAK-Service GmbH, Darmstadt" device.

Are there any CAN-bus bindings for Ada available on the net (for any
vendor)?


> What about "_CAN_GetHwParam"? It looks like 'extern "C"' stuff.
> Or maybe, pragma Import (C, CAN_GetHwParam, "CAN_GetHwParam");

Thanks, I will try it.

Gerd

From: christoph.grein on
Gerd wrote:
>
> The GNAT Users Guide say that the "_" and the "@16" is appended
> automatically for "__stdcall" (as far as I understood). And the
> function is declared as "__stdcall" in the header-file.

External_Name and Link_Name in pragma Import are optional. But if you
provide them, they must be exact (AFAICS).

From: Gerd on

christoph.grein(a)eurocopter.com schrieb:

> Gerd wrote:
> >
> > The GNAT Users Guide say that the "_" and the "@16" is appended
> > automatically for "__stdcall" (as far as I understood). And the
> > function is declared as "__stdcall" in the header-file.
>
> External_Name and Link_Name in pragma Import are optional. But if you
> provide them, they must be exact (AFAICS).

No. The Users guide say the "@nn" is always added, the "_" can be
dropped by specifying a link name, but is added if not specified in
external name.

 |  Next  |  Last
Pages: 1 2
Prev: tasksing and TCP sockets
Next: GWindows