diff --git a/lclbindings/clazhello/Makefile.win b/lclbindings/clazhello/Makefile.win new file mode 100644 index 000000000..6a4b50151 --- /dev/null +++ b/lclbindings/clazhello/Makefile.win @@ -0,0 +1,30 @@ +# Project: clazhello +# Makefile created by Dev-C++ 4.9.9.2 + +CPP = g++.exe +CC = gcc.exe +WINDRES = windres.exe +RES = +OBJ = clazhello.o $(RES) +LINKOBJ = clazhello.o $(RES) +LIBS = -L"C:/Programas/Dev-Cpp/lib" -mwindows liblclexports.a +INCS = -I"C:/Programas/Dev-Cpp/include" -I"../lclincludes" +CXXINCS = -I"C:/Programas/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Programas/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Programas/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Programas/Dev-Cpp/include/c++/3.4.2" -I"C:/Programas/Dev-Cpp/include" -I"../lclincludes" +BIN = clazhello.exe +CXXFLAGS = $(CXXINCS) +CFLAGS = $(INCS) +RM = rm -f + +.PHONY: all all-before all-after clean clean-custom + +all: all-before clazhello.exe all-after + + +clean: clean-custom + ${RM} $(OBJ) $(BIN) + +$(BIN): $(OBJ) + $(CC) $(LINKOBJ) -o "clazhello.exe" $(LIBS) + +clazhello.o: clazhello.c + $(CC) -c clazhello.c -o clazhello.o $(CFLAGS) diff --git a/lclbindings/clazhello/clazhello.c b/lclbindings/clazhello/clazhello.c new file mode 100644 index 000000000..51cca7f84 --- /dev/null +++ b/lclbindings/clazhello/clazhello.c @@ -0,0 +1,49 @@ +/* +clazhello.c + +Simple demonstration program that uses the LCL Exports library to build a GUI + +LICENSE: Public domain + +AUTHOR: Felipe Monteiro de Carvalho +*/ + +#include "vcl.h" + +TFormH MyForm; +TButtonH MyButton; + +/* Callback for the close button */ +FASTCALL_TNOTIFYEVENT_START(MyButton_OnClick) /* void* Self, TObjectH Sender */ + + TCustomForm_Close(MyForm); +} + +/* Application entry-point */ +APPBEGIN() +{ + Application_Initialize(); + + Application_CreateForm(&MyForm); + + TControl_SetTop(MyForm, 50); + TControl_SetLeft(MyForm, 50); + TControl_SetHeight(MyForm, 200); + TControl_SetWidth(MyForm, 200); + TControl_SetCaption(MyForm, "C Lazarus app"); + + MyButton = TButton_Create(MyForm); + TWinControl_SetParent(MyButton, MyForm); + + TControl_SetTop(MyButton, 150); + TControl_SetLeft(MyButton, 50); + TControl_SetWidth(MyButton, 100); + + TControl_SetOnClick(MyButton, &MyButton_OnClick); + TControl_SetCaption(MyButton, "Close Button"); + + /* Enter main loop */ + Application_Run(); + + return 0; +} diff --git a/lclbindings/clazhello/clazhello.dev b/lclbindings/clazhello/clazhello.dev new file mode 100644 index 000000000..1723b09f9 --- /dev/null +++ b/lclbindings/clazhello/clazhello.dev @@ -0,0 +1,119 @@ +[Project] +FileName=clazhello.dev +Name=clazhello +UnitCount=7 +Type=0 +Ver=1 +ObjFiles= +Includes=..\lclincludes +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler=_@@_ +CppCompiler= +Linker=liblclexports.a_@@_ +IsCpp=0 +Icon= +ExeOutput= +ObjectOutput= +OverrideOutput=0 +OverrideOutputName=clazhello.exe +HostApplication= +Folders= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000000000000000000 + +[Unit1] +FileName=clazhello.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd=$(CC) -c clazhello.c -o clazhello.o $(CFLAGS) + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 + +[Unit2] +FileName=..\lclincludes\classes.h +CompileCpp=0 +Folder=clazhello +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit3] +FileName=..\lclincludes\controls.h +CompileCpp=0 +Folder=clazhello +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit4] +FileName=..\lclincludes\forms.h +CompileCpp=0 +Folder=clazhello +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit5] +FileName=..\lclincludes\stdctrls.h +CompileCpp=0 +Folder=clazhello +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit6] +FileName=..\lclincludes\system.h +CompileCpp=0 +Folder=clazhello +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit7] +FileName=..\lclincludes\vcl.h +CompileCpp=0 +Folder=clazhello +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/lclbindings/lclexports/builddef.bat b/lclbindings/lclexports/builddef.bat new file mode 100644 index 000000000..7615d21c4 --- /dev/null +++ b/lclbindings/lclexports/builddef.bat @@ -0,0 +1,3 @@ +PATH=c:\Programas\Dev-Cpp\bin\ +pexports.exe lclexports.dll > liblclexports.def +dlltool.exe --def liblclexports.def --dllname lclexports.dll --output-lib liblclexports.a diff --git a/lclbindings/lclexports/clean.bat b/lclbindings/lclexports/clean.bat new file mode 100644 index 000000000..3228b36a1 --- /dev/null +++ b/lclbindings/lclexports/clean.bat @@ -0,0 +1,4 @@ +del *.o +del *.ppu +del *.compiled +del *.bak \ No newline at end of file diff --git a/lclbindings/lclexports/controlsexports.pas b/lclbindings/lclexports/controlsexports.pas new file mode 100644 index 000000000..7508e7c02 --- /dev/null +++ b/lclbindings/lclexports/controlsexports.pas @@ -0,0 +1,131 @@ +{ +controlsexports.pas + +Exports the functionality from the Controls LCL unit + +This file is part of the LCL Exports library. + +LICENSE: The same modifyed LGPL as the Free Pascal Runtime Library + and the Lazarus Component Library + +Copyright (C) 2008 Felipe Monteiro de Carvalho +} +unit controlsexports; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, + Controls; + +{ TControl } + +{ Events } +function TControl_GetOnClick(Self: TControl): TNotifyEvent; cdecl; +procedure TControl_SetOnClick(Self: TControl; AValue: TNotifyEvent); cdecl; +{ Properties } +function TControl_GetCaption(Self: TControl): PChar; cdecl; +procedure TControl_SetCaption(Self: TControl; AValue: PChar); cdecl; + +function TControl_GetLeft(Self: TControl): Integer; cdecl; +procedure TControl_SetLeft(Self: TControl; AValue: Integer); cdecl; +function TControl_GetHeight(Self: TControl): Integer; cdecl; +procedure TControl_SetHeight(Self: TControl; AValue: Integer); cdecl; +function TControl_GetHint(Self: TControl): PChar; cdecl; +procedure TControl_SetHint(Self: TControl; AValue: PChar); cdecl; +function TControl_GetTop(Self: TControl): Integer; cdecl; +procedure TControl_SetTop(Self: TControl; AValue: Integer); cdecl; +function TControl_GetWidth(Self: TControl): Integer; cdecl; +procedure TControl_SetWidth(Self: TControl; AValue: Integer); cdecl; + +{ TWinControl } + +function TWinControl_GetParent(Self: TWinControl): TWinControl; cdecl; +procedure TWinControl_SetParent(Self: TWinControl; AValue: TWinControl); cdecl; + +implementation + +function TControl_GetOnClick(Self: TControl): TNotifyEvent; cdecl; +begin + Result := Self.OnClick; +end; + +procedure TControl_SetOnClick(Self: TControl; AValue: TNotifyEvent); cdecl; +begin + Self.OnClick := AValue; +end; + +function TControl_GetCaption(Self: TControl): PChar; cdecl; +begin + Result := PChar(Self.Caption); +end; + +procedure TControl_SetCaption(Self: TControl; AValue: PChar); cdecl; +begin + Self.Caption := string(AValue); +end; + +function TControl_GetLeft(Self: TControl): Integer; cdecl; +begin + Result := Self.Left; +end; + +procedure TControl_SetLeft(Self: TControl; AValue: Integer); cdecl; +begin + Self.Left := AValue; +end; + +function TControl_GetHeight(Self: TControl): Integer; cdecl; +begin + Result := Self.Height; +end; + +procedure TControl_SetHeight(Self: TControl; AValue: Integer); cdecl; +begin + Self.Height := AValue; +end; + +function TControl_GetHint(Self: TControl): PChar; cdecl; +begin + Result := PChar(Self.Hint); +end; + +procedure TControl_SetHint(Self: TControl; AValue: PChar); cdecl; +begin + Self.Hint := string(AValue); +end; + +function TControl_GetTop(Self: TControl): Integer; cdecl; +begin + Result := Self.Top; +end; + +procedure TControl_SetTop(Self: TControl; AValue: Integer); cdecl; +begin + Self.Top := AValue; +end; + +function TControl_GetWidth(Self: TControl): Integer; cdecl; +begin + Result := Self.Width; +end; + +procedure TControl_SetWidth(Self: TControl; AValue: Integer); cdecl; +begin + Self.Width := AValue; +end; + +function TWinControl_GetParent(Self: TWinControl): TWinControl; cdecl; +begin + Result := Self.Parent; +end; + +procedure TWinControl_SetParent(Self: TWinControl; AValue: TWinControl); cdecl; +begin + Self.Parent := AValue; +end; + +end. + diff --git a/lclbindings/lclexports/formsexports.pas b/lclbindings/lclexports/formsexports.pas new file mode 100644 index 000000000..55ff8053a --- /dev/null +++ b/lclbindings/lclexports/formsexports.pas @@ -0,0 +1,76 @@ +{ +formsexports.pas + +Exports the functionality from the Forms LCL unit + +This file is part of the LCL Exports library. + +LICENSE: The same modifyed LGPL as the Free Pascal Runtime Library + and the Lazarus Component Library + +Copyright (C) 2008 Felipe Monteiro de Carvalho +} +unit formsexports; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, Forms; + +{ Application } + +procedure Application_CreateForm(var Reference: Pointer); cdecl; +procedure Application_Initialize; cdecl; +procedure Application_Run; cdecl; + +{ TCustomForm } + +procedure TCustomForm_Close(Self: TCustomForm); cdecl; +procedure TCustomForm_Show(Self: TCustomForm); cdecl; + +{ TForm } + +function TForm_Create(TheOwner: TComponent): TForm; cdecl; + +implementation + +{ Application } + +procedure Application_CreateForm(var Reference: Pointer); cdecl; +begin + Application.CreateForm(TForm, Reference); +end; + +procedure Application_Initialize; cdecl; +begin + Application.Initialize; +end; + +procedure Application_Run; cdecl; +begin + Application.Run; +end; + +{ TCustomForm } + +procedure TCustomForm_Close(Self: TCustomForm); cdecl; +begin + Self.Close; +end; + +procedure TCustomForm_Show(Self: TCustomForm); cdecl; +begin + Self.Show; +end; + +{ TForm } + +function TForm_Create(TheOwner: TComponent): TForm; cdecl; +begin + Result := TForm.Create(TheOwner); +end; + +end. + diff --git a/lclbindings/lclexports/lclexports.dpr b/lclbindings/lclexports/lclexports.dpr new file mode 100644 index 000000000..88b07a476 --- /dev/null +++ b/lclbindings/lclexports/lclexports.dpr @@ -0,0 +1,56 @@ +{ +lclexports.dpr + +Export library to use LCL functions in other languages + +This file is part of the LCL Exports library. + +LICENSE: The same modifyed LGPL as the Free Pascal Runtime Library + and the Lazarus Component Library + +Copyright (C) 2008 Felipe Monteiro de Carvalho +} +library lclexports; + +{$ifndef fpc} + {$mode objfpc}{$H+} +{$endif} + +uses + Interfaces, // Necessary to create the widgetset object + Classes, + formsexports, + controlsexports, + stdctrlsexports; + +exports + { ControlsExports } + TControl_GetOnClick, + TControl_SetOnClick, + TControl_GetCaption, + TControl_SetCaption, + TControl_GetLeft, + TControl_SetLeft, + TControl_GetHeight, + TControl_SetHeight, + TControl_GetHint, + TControl_SetHint, + TControl_GetTop, + TControl_SetTop, + TControl_GetWidth, + TControl_SetWidth, + TWinControl_GetParent, + TWinControl_SetParent, + { FormsExports } + Application_CreateForm, + Application_Initialize, + Application_Run, + TCustomForm_Close, + TCustomForm_Show, + TForm_Create, + { StdCtrlsExports } + TButton_Create; + +begin +end. + diff --git a/lclbindings/lclexports/lclexports.lpi b/lclbindings/lclexports/lclexports.lpi new file mode 100644 index 000000000..a213cda6e --- /dev/null +++ b/lclbindings/lclexports/lclexports.lpi @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lclbindings/lclexports/stdctrlsexports.pas b/lclbindings/lclexports/stdctrlsexports.pas new file mode 100644 index 000000000..f0ca67124 --- /dev/null +++ b/lclbindings/lclexports/stdctrlsexports.pas @@ -0,0 +1,33 @@ +{ +stdctrlsexports.pas + +Exports the functionality from the StdCtrls LCL unit + +This file is part of the LCL Exports library. + +LICENSE: The same modifyed LGPL as the Free Pascal Runtime Library + and the Lazarus Component Library + +Copyright (C) 2008 Felipe Monteiro de Carvalho +} +unit stdctrlsexports; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, + StdCtrls; + +function TButton_Create(TheOwner: TComponent): TButton; cdecl; + +implementation + +function TButton_Create(TheOwner: TComponent): TButton; cdecl; +begin + Result := TButton.Create(TheOwner); +end; + +end. + diff --git a/lclbindings/lclincludes/classes.h b/lclbindings/lclincludes/classes.h new file mode 100644 index 000000000..e77ac2730 --- /dev/null +++ b/lclbindings/lclincludes/classes.h @@ -0,0 +1,29 @@ +/* +classes.h + +C/C++ header for the LCL Exports library + +LICENSE: The same modifyed LGPL as the Free Pascal Runtime Library + and the Lazarus Component Library + +Copyright (C) 2008 Felipe Monteiro de Carvalho +*/ + +#ifndef LAZARUS_CLASSES_H +#define LAZARUS_CLASSES_H + +#include "system.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* TComponent */ + +typedef void* TComponentH; + +#ifdef __cplusplus +} +#endif + +#endif /* !LAZARUS_CLASSES_H */ diff --git a/lclbindings/lclincludes/controls.h b/lclbindings/lclincludes/controls.h new file mode 100644 index 000000000..44eee3820 --- /dev/null +++ b/lclbindings/lclincludes/controls.h @@ -0,0 +1,88 @@ +/* +controls.h + +C/C++ header for the LCL Exports library + +LICENSE: The same modifyed LGPL as the Free Pascal Runtime Library + and the Lazarus Component Library + +Copyright (C) 2008 Felipe Monteiro de Carvalho +*/ + +#ifndef LAZARUS_CONTROLS_H +#define LAZARUS_CONTROLS_H + +#include "system.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* TControl */ + +typedef void* TControlH; + +/* Helper macros to access the parameters of an event */ +#ifdef __BORLANDC__ + +typedef __fastcall void (*TNotifyEvent) (void* Self, TObjectH Sender); + +#define FASTCALL_TNOTIFYEVENT_START(EventName) \ + __fastcall void EventName(void* Self, TObjectH Sender){ + +#elif __GNUC__ + +#ifdef __i386__ + +typedef void (*TNotifyEvent) (void); + +#define FASTCALL_TNOTIFYEVENT_START(EventName) \ + void EventName(){ \ + void* Self; \ + TObjectH Sender; \ + __asm__ __volatile__ ("nop" \ + : "=a" (Self), "=d" (Sender) \ + : "a" (Self), "d" (Sender) \ + ); + + +#else + +typedef void (*TNotifyEvent) (void* Self, TObjectH Sender); + +#define FASTCALL_TNOTIFYEVENT_START(EventName) \ + void EventName(void* Self, TObjectH Sender){ + +#endif + +#endif + +__cdecl TNotifyEvent TControl_GetOnClick(TControlH Self); +__cdecl TControl_SetOnClick(TControlH Self, TNotifyEvent AValue); + +__cdecl char* TControl_GetCaption(TControlH Self); +__cdecl TControl_SetCaption(TControlH Self, char* AValue); + +__cdecl Integer TControl_GetLeft(TControlH Self); +__cdecl TControl_SetLeft(TControlH Self, Integer AValue); +__cdecl Integer TControl_GetHeight(TControlH Self); +__cdecl TControl_SetHeight(TControlH Self, Integer AValue); +__cdecl char* TControl_GetHint(TControlH Self); +__cdecl TControl_SetHint(TControlH Self, char* AValue); +__cdecl Integer TControl_GetTop(TControlH Self); +__cdecl TControl_SetTop(TControlH Self, Integer AValue); +__cdecl Integer TControl_GetWidth(TControlH Self); +__cdecl TControl_SetWidth(TControlH Self, Integer AValue); + +/* TWinControl */ + +typedef void* TWinControlH; + +__cdecl TWinControlH TWinControl_GetParent(TWinControlH Self); +__cdecl TWinControl_SetParent(TWinControlH Self, TWinControlH AValue); + +#ifdef __cplusplus +} +#endif + +#endif /* !LAZARUS_CONTROLS_H */ diff --git a/lclbindings/lclincludes/forms.h b/lclbindings/lclincludes/forms.h new file mode 100644 index 000000000..ae72c4404 --- /dev/null +++ b/lclbindings/lclincludes/forms.h @@ -0,0 +1,46 @@ +/* +forms.h + +C/C++ header for the LCL Exports library + +LICENSE: The same modifyed LGPL as the Free Pascal Runtime Library + and the Lazarus Component Library + +Copyright (C) 2008 Felipe Monteiro de Carvalho +*/ + +#ifndef LAZARUS_FORMS_H +#define LAZARUS_FORMS_H + +#include "system.h" +#include "classes.h" +#include "controls.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Application */ + +__cdecl void Application_CreateForm(void** Reference); +__cdecl void Application_Initialize(); +__cdecl void Application_Run(); + +/* TCustomForm */ + +typedef void* TCustomFormH; + +__cdecl void TCustomForm_Close(TCustomFormH Self); +__cdecl void TCustomForm_Show(TCustomFormH Self); + +/* TForm */ + +typedef void* TFormH; + +__cdecl TFormH TForm_Create(TComponentH Owner); + +#ifdef __cplusplus +} +#endif + +#endif /* !LAZARUS_FORMS_H */ diff --git a/lclbindings/lclincludes/stdctrls.h b/lclbindings/lclincludes/stdctrls.h new file mode 100644 index 000000000..7dfd210f8 --- /dev/null +++ b/lclbindings/lclincludes/stdctrls.h @@ -0,0 +1,33 @@ +/* +stdctrls.h + +C/C++ header for the LCL Exports library + +LICENSE: The same modifyed LGPL as the Free Pascal Runtime Library + and the Lazarus Component Library + +Copyright (C) 2008 Felipe Monteiro de Carvalho +*/ + +#ifndef LAZARUS_STDCTRLS_H +#define LAZARUS_STDCTRLS_H + +#include "system.h" +#include "classes.h" +#include "controls.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* TButton */ + +typedef void* TButtonH; + +__cdecl TButtonH TButton_Create(TComponentH TheOwner); + +#ifdef __cplusplus +} +#endif + +#endif /* !LAZARUS_STDCTRLS_H */ diff --git a/lclbindings/lclincludes/system.h b/lclbindings/lclincludes/system.h new file mode 100644 index 000000000..c0a5a1681 --- /dev/null +++ b/lclbindings/lclincludes/system.h @@ -0,0 +1,54 @@ +/* +system.h + +C/C++ header for the LCL Exports library + +LICENSE: The same modifyed LGPL as the Free Pascal Runtime Library + and the Lazarus Component Library + +Copyright (C) 2008 Felipe Monteiro de Carvalho +*/ + +/* Basic Pascal declarations */ + +#ifndef LAZARUS_SYSTEM_H +#define LAZARUS_SYSTEM_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Cross-platform entry-point */ + +#ifdef __Win32__ + +#define APPBEGIN() \ + int WINAPI WinMain (HINSTANCE hThisInstance, \ + HINSTANCE hPrevInstance, \ + LPSTR lpszArgument, \ + int nFunsterStil) + +#else + +#define APPBEGIN() \ +int main(int argc, char *argv[]) + +#endif + +typedef void* TObjectH; + +/* 32-bit types */ + +typedef int Integer; +typedef unsigned int Cardinal; + +/* Variable width types */ + +typedef int PtrInt; +typedef unsigned int PtrUInt; + +#ifdef __cplusplus +} +#endif + +#endif /* !LAZARUS_SYSTEM_H */ diff --git a/lclbindings/lclincludes/vcl.h b/lclbindings/lclincludes/vcl.h new file mode 100644 index 000000000..ba5f8dbb7 --- /dev/null +++ b/lclbindings/lclincludes/vcl.h @@ -0,0 +1,21 @@ +/* +vcl.h + +C/C++ header for the LCL Exports library + +LICENSE: The same modifyed LGPL as the Free Pascal Runtime Library + and the Lazarus Component Library + +Copyright (C) 2008 Felipe Monteiro de Carvalho +*/ + +#ifndef LAZARUS_VCL_H +#define LAZARUS_VCL_H + +#include "classes.h" +#include "controls.h" +#include "forms.h" +#include "stdctrls.h" +#include "system.h" + +#endif /* !LAZARUS_VCL_H */