From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3d1c21a87689d7bd X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-03-16 05:54:18 PST Path: archiver1.google.com!postnews2.google.com!not-for-mail From: happysegfault@yahoo.com (Happy Segfault) Newsgroups: comp.lang.ada Subject: Re: Minimal pragma Export (StdCall... example? Date: 16 Mar 2004 05:54:17 -0800 Organization: http://groups.google.com Message-ID: References: <2de350pqsadlrvvgkrpc7261k31l5ejuap@4ax.com> NNTP-Posting-Host: 68.184.214.99 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1079445258 16692 127.0.0.1 (16 Mar 2004 13:54:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 16 Mar 2004 13:54:18 +0000 (UTC) Xref: archiver1.google.com comp.lang.ada:6342 Date: 2004-03-16T05:54:17-08:00 List-Id: I've got a minimal almost-working example now. In case someone else goes looking for one later, I'll paste it in here. Of course, if I'm doing something wrong, I'd appreciate someone pointing it out. There is some weirdness, however. There is a seemingly GWindows-related access violation exception being thrown for some variations of this code. I cannot figure it out! -- gw_in_a_dll.def LIBRARY gw_in_a_dll EXPORTS pop_a_window=pop_a_window@0 pop_a_window@0 pop_a_window_int=pop_a_window_int@4 pop_a_window_int@4 -- makefile PACKAGES = gw_in_a_dll call_gw_dll ADAOPTS = -I../../bindings/ all: gw_in_a_dll call_gw_dll gw_in_a_dll: gnatmake ${ADAOPTS} gw_in_a_dll ${POSTOPTS} gnatdll -egw_in_a_dll.def -dgw_in_a_dll.dll gw_in_a_dll.ali call_gw_dll: gnatmake ${ADAOPTS} call_gw_dll ${POSTOPTS} -- gw_in_a_dll.ads -- Demonstrates using GWindows in a DLL -- -- Modified from original GWindows version to use Stdcall calling -- convention and to test parameter passing -- -- This version does not work... with Interfaces.C; package GW_In_A_DLL is procedure Pop_A_Window; pragma Export (Stdcall, Pop_A_Window); procedure Pop_A_Window_Int(I : Interfaces.C.Int); pragma Export (Stdcall, Pop_A_Window_Int); end GW_In_A_DLL; -- gw_in_a_dll.adb -- Demonstrates using GWindows in a DLL -- -- Modified from original GWindows version to use Stdcall calling -- convention and to test parameter passing -- -- This version does not work... with Interfaces.C; with GWindows.Application; with GWindows.Windows; with GWindows.GStrings; package body GW_In_A_DLL is DLL_PROCESS_DETACH : constant := 0; DLL_PROCESS_ATTACH : constant := 1; procedure Adainit; pragma Import (C, Adainit); procedure Adafinal; pragma Import (C, Adafinal); function DllMain (hinstDLL : Interfaces.C.long; fdwReason : Interfaces.C.unsigned_short; lpvReserved : Integer) return Interfaces.C.int; pragma Export (StdCall, DllMain, "DllMain"); ------------- -- DllMain -- ------------- function DllMain (hinstDLL : Interfaces.C.long; fdwReason : Interfaces.C.unsigned_short; lpvReserved : Integer) return Interfaces.C.int is pragma Warnings (Off, lpvReserved); begin case fdwReason is when DLL_PROCESS_ATTACH => GWindows.Application.Set_hInstance (HinstDLL); return 1; when DLL_PROCESS_DETACH => Adafinal; return 1; when others => return 1; end case; end DllMain; ------------------ -- Pop_A_Window -- ------------------ procedure Pop_A_Window is use GWindows.Windows; use GWindows.GStrings; Window : Window_Type; J : constant Interfaces.C.Int := 2; begin Adainit; Create (Window, -- To_GString_From_String("Your number is " & "not here"), -- To_GString_From_String("Your number is not here"), -- To_GString_From_String("Your number defaults to " & J'Img), -- Any of the above will crash with an access violation "Your number is " & "not here", -- This line works fine! Width => 300, Height => 100); Visible (Window); GWindows.Application.Show_Modal (Window); end Pop_A_Window; ---------------------- -- Pop_A_Window_Int -- ---------------------- procedure Pop_A_Window_Int(I : Interfaces.C.Int) is use GWindows.Windows; use GWindows.GStrings; Window : Window_Type; J : constant Interfaces.C.Int := 222; begin Adainit; Create (Window, -- To_GString_From_String("Your number is " & J'Img), To_GString_From_String("Your number is " & I'Img), -- To_GString_From_String("Your number is not here either"), -- All of the above work from call_gw_dll.exe, but this -- procedure crashes Excel if I call it from Visual Basic. Width => 300, Height => 100); Visible (Window); GWindows.Application.Show_Modal (Window); end Pop_A_Window_Int; end GW_In_A_DLL; -- call_gw_dll.adb with Ada.Text_IO; with Interfaces.C; procedure Call_GW_DLL is pragma Linker_Options ("-lgw_in_a_dll"); procedure Pop_A_Window; pragma Import (Stdcall, Pop_A_Window); procedure Pop_A_Window_Int(I : Interfaces.C.Int); pragma Import (Stdcall, Pop_A_Window_Int); I : constant Interfaces.C.Int := 3; begin Ada.Text_IO.Put_Line("Doing Pop_A_Window"); Pop_A_Window; Ada.Text_IO.Put_Line("Doing Pop_A_Window_Int(I)"); Pop_A_Window_Int(3); Ada.Text_IO.Put_Line("Done!"); end Call_GW_DLL;