comp.lang.ada
 help / color / mirror / Atom feed
* function from dll
@ 2004-01-22 20:36 Szymon Guz
  2004-01-22 23:43 ` Stephen Leake
  2004-01-23  6:05 ` Per Sandberg
  0 siblings, 2 replies; 4+ messages in thread
From: Szymon Guz @ 2004-01-22 20:36 UTC (permalink / raw)


Hi,
I've got maybe a trivial question but I still can't solve the problem:

I've a dll written in C under Windows and I want to use specific 
function from that in my Ada program. For loading the library I use the 
WinApi function LoadLibrary and then I use the function GetProcAddress 
to get the Win32.Windef.FARPROC handle to the function that I need. I 
need to map the function from the dll in Ada to have sth like that:

<C++ CODE>
void sth(){}
</C++ CODE>

<ADA CODE>
function sth() return Integer;
</ADA CODE>

now I want to run in the ada function body the function from dll... well 
how to use the Win32.Windef.FARPROC handle ?

Szymon Guz





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: function from dll
  2004-01-22 20:36 function from dll Szymon Guz
@ 2004-01-22 23:43 ` Stephen Leake
  2004-01-23  1:59   ` tmoran
  2004-01-23  6:05 ` Per Sandberg
  1 sibling, 1 reply; 4+ messages in thread
From: Stephen Leake @ 2004-01-22 23:43 UTC (permalink / raw)
  To: comp.lang.ada

Szymon Guz <alpha@skynetSMIECI.VONorg.NOJUSZpl> writes:

> Hi,
> I've got maybe a trivial question but I still can't solve the problem:
> 
> I've a dll written in C under Windows and I want to use specific
> function from that in my Ada program. For loading the library I use
> the WinApi function LoadLibrary and then I use the function
> GetProcAddress to get the Win32.Windef.FARPROC handle to the function
> that I need. I need to map the function from the dll in Ada to have
> sth like that:
> 
> <C++ CODE>
> void sth(){}
> </C++ CODE>
> 
> <ADA CODE>
> function sth() return Integer;
> </ADA CODE>

The Ada spec doesn't match the C spec; the C code does not return an
int.

> now I want to run in the ada function body the function from dll...
> well how to use the Win32.Windef.FARPROC handle ?

I've never actually done this, but you can probably define an access
to procedure type, and do an unchecked conversion from System.Address
to it.

-- 
-- Stephe




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: function from dll
  2004-01-22 23:43 ` Stephen Leake
@ 2004-01-23  1:59   ` tmoran
  0 siblings, 0 replies; 4+ messages in thread
From: tmoran @ 2004-01-23  1:59 UTC (permalink / raw)


> well how to use the Win32.Windef.FARPROC handle ?
  The relevant Claw routine has the spec and comments:

    function Get_Proc_Address (DLL_Object: in DLL_Type;
                               Sub_Name:  in String)
                return Claw.Any_Subprogram_Access_Type;
        --
        -- Get the address of the subprogram named Sub_Name in the
        -- already-loaded DLL, indicated by the DLL_Object.  Sub_Name
        -- is the full subprogram name as exported from the DLL, with
        -- exactly the same case and spelling.
        --
        -- Raises:
        --      Not_Valid_Error if DLL_Object was not previously initialized
        --              using Load.
        --      Windows_Error if Windows returns an error.
        --
        -- Note: The user will need to do an Unchecked_Conversion of the
        --       returned value into an access-to-subprogram variable with
        --       the appropriate convention, parameters, and result in order
        --       to actually call the DLL function from Ada.  The returned
        --       value is useful only for a parameterless procedure.
        --



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: function from dll
  2004-01-22 20:36 function from dll Szymon Guz
  2004-01-22 23:43 ` Stephen Leake
@ 2004-01-23  6:05 ` Per Sandberg
  1 sibling, 0 replies; 4+ messages in thread
From: Per Sandberg @ 2004-01-23  6:05 UTC (permalink / raw)
  To: comp.lang.ada

Why don do an lib file that contains all symbols in the dll
and then link the library and avoid messing around with liad libraray 
and such.
Unless you requere dynamic loading ofd the dll in runtime.

sample code

<C-code>
external C{  // to avoid C++ name mangling.
void sth(){};
}
</C-code>

<Ada-code
procedure sth;
pragma import (<C or Stdcal>,sth,"sth");
pragma Linker_Options("-llibname"); -- GNAT specific.
<How-to>
#if GNAT then

How to create a lib-file
copy the libname.lib to liblibname.a
then gnatmake -L<the directory where liblibname.a is> <other params>
#elseif ObjectAda then
In project properties
add libname.lib to linker arguments
Add the directory wher libname.lib resides in
the "Linker only" search list.
#end if;
</How-to>
<Ada-code>
/Per Sandberg


Szymon Guz wrote:

> Hi,
> I've got maybe a trivial question but I still can't solve the problem:
> 
> I've a dll written in C under Windows and I want to use specific 
> function from that in my Ada program. For loading the library I use the 
> WinApi function LoadLibrary and then I use the function GetProcAddress 
> to get the Win32.Windef.FARPROC handle to the function that I need. I 
> need to map the function from the dll in Ada to have sth like that:
> 
> <C++ CODE>
> void sth(){}
> </C++ CODE>
> 
> <ADA CODE>
> function sth() return Integer;
> </ADA CODE>
> 
> now I want to run in the ada function body the function from dll... well 
> how to use the Win32.Windef.FARPROC handle ?
> 
> Szymon Guz
> 
> 
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
> 




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-01-23  6:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-22 20:36 function from dll Szymon Guz
2004-01-22 23:43 ` Stephen Leake
2004-01-23  1:59   ` tmoran
2004-01-23  6:05 ` Per Sandberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox