Page 1 of 1

export function from the executable

Posted: Thu Jul 22, 2010 3:49 pm
by hallodri
hi,

I use the GtkBuilder with Glade, where you can specify an event function and it will later call it.

Example in C:

Code: Select all

#include <gtk\gtk.h>

extern "C" __declspec( dllexport ) void on_window1_destroy()
{
	gtk_main_quit();
}

int main(int argc, char** argv)
{

	GtkWidget	*Window = 0;
	GtkBuilder	*GBuild;

	gtk_init(&argc, &argv);

	
	GBuild = gtk_builder_new();
	
	gtk_builder_add_from_file(GBuild, "test2.glade", NULL);
	
	Window = GTK_WIDGET(gtk_builder_get_object (GBuild, "window1"));

	gtk_builder_connect_signals(GBuild, 0);

	gtk_widget_show_all(Window);

	g_object_unref (GBuild);

	gtk_main();

	return 0;
}
test2.glade

Code: Select all

<?xml version="1.0"?>
<interface>
  <requires lib="gtk+" version="2.16"/>
  <!-- interface-naming-policy project-wide -->
  <object class="GtkWindow" id="window1">
    <signal name="destroy" handler="on_window1_destroy"/>
  </object>
</interface>
When I close the window is automatically invoked on_window1_destroy.

Example PB:

Code: Select all

XIncludeFile "..\include\gtk2.pbi"

ProcedureCDLL on_window1_destroy()
  gtk_main_quit()
EndProcedure

ProcedureC main()  
  Protected window.i
  Protected gBuilder.i
  
  
  If gtk_init(0, 0)
    
    gBuilder = gtk_builder_new ()        
    
    gtk_builder_add_from_file(gBuilder, @"test2.glade", #Null)            
    gtk_builder_connect_signals(gBuilder, 0)
    
  	Window = gtk_builder_get_object (gBuilder, @"window1")
  	gtk_widget_show_all(Window)   
    
    g_object_unref (gBuilder)
    
    gtk_main ()
                   
  EndIf

EndProcedure

main() 

With Purebasic the whole does not work, because PB is not the function exported.
Therefore, my wish that Purebasic functions declared with ProcedureCDLL / ProcedureDLL
be exported from executable.

Re: export function from the executable

Posted: Sun Jan 06, 2013 12:40 pm
by uwekel
Hi!

I am stuck on the same problem right now. Is it already possible with PureBasic?

As a work around, you can use

Code: Select all

g_signal_connect_(*myobject, "signal-name", @my_handler(), user_data)
but it's a line for any single event you want to track.

Best regards
Uwe.

Re: export function from the executable

Posted: Thu Jan 10, 2013 5:38 am
by idle
Uwe

As it happens you can export a function reasonably easily if you view the commented ASM to find the label of the function
in your finished code.

http://www.purebasic.fr/english/viewtop ... 12&t=52807

Re: export function from the executable

Posted: Fri Jan 11, 2013 8:46 am
by User_Russian
idle, does not work exported function.

Code: Select all

Import "/EXPORT:Message" : EndImport 
;...
!public _Procedure0 As 'Message'
ProcedureDLL Message(Title.s, Message.s)
  MessageRequester(Title, Message)
EndProcedure

Code: Select all

Prototype Funct(Title.s, Message.s)

If OpenLibrary(0,"exe.exe")
  Funct.Funct=GetFunction(0, "Message")
  If Funct
    Funct("Message", "Test")
  EndIf
EndIf

Re: export function from the executable

Posted: Fri Jan 11, 2013 3:31 pm
by hallodri
try this

Code: Select all

ProcedureDLL Message(Title.s, Message.s)
	MessageRequester(Title, Message)
	ProcedureReturn 
	Message("", "") ; <--- important
EndProcedure
PB puts the function in a macro. If the macro is never called, the code will not compile.

Re: export function from the executable

Posted: Sat Jan 12, 2013 1:14 am
by idle
@User_Russian

I think you need to own the processes to call an exported function from it.

The trick works for gtk_builder_connect_signals(GBuild, 0);
because gtk is loaded into your process and it can then use library functions
to find and set the callbacks.