Workaround Euphoria To C Translator 4.0.0
- Posted by moskito_x Mar 29, 2010
- 1338 views
PART #1 Euphoria To C Translator 4.0.0 borland is no longer supported
to test it i now must have open-watcom and so i downloaded "open-watcom-c-win32-1.9RC2.exe"
my 8th c-compiler one more .. so what
i will try Euphoria To C Translator without -bor
to try out by yourself you need to install Ming (swf output) wrapper (alpha04) http://rapideuphoria.com/euming04.zip
libpng13.dll and zlib1.dll
unzip euming04.zip, for example in "D:\euphoria-40b2\euming04\"
to keep your installation clean copy the "ming" Folder to "mingT" Folder
now it looks like
"D:\euphoria-40b2\"
"D:\euphoria-40b2\euming04\"
"D:\euphoria-40b2\euming04\ming"
"D:\euphoria-40b2\euming04\mingT"
in mingT folder put DTX_JTestC.exw and dtx-makeTDllC.bat
see below
DTX_JTestC.exw -------------------------------------- include ming.ew include get.e with trace -- with profile trace(1) global procedure main() init_ming() Ming_useSWFVersion(VERSION5) end procedure main() --------------------------------------
the drive letter D: has to be changed to your WATCOM installation
dtx-makeTDllC.bat -------------------------------------- @echo off set PATH=D:\WATCOM\BINNT;%PATH% set PATH=D:\WATCOM\BINW;%PATH% set INCLUDE=D:\WATCOM\H;%INCLUDE% set INCLUDE=D:\WATCOM\H\NT;%INCLUDE% set WATCOM=D:\WATCOM set EDPATH=D:\WATCOM\EDDAT euc -dll -keep -emake DTX_JTestC.exw --------------------------------------
open a command Shell window
click-> START - run - cmd
the drive letter D: has to be changed to your euphoria installation
type
cd \
cd D:\euphoria-40b2\euming04\mingT
to make C Code
type
dtx-makeTDllC
D:\euphoria-40b2\euming04\MingT>dtx-makeTDllC Translating code, pass: 1 2 3 4 5 generating Writing emake file emake.bat 8.c files were created. To build your project, type emake.bat Warning ( translator ): <0216>:: Watcom should have the H and the H\NT includes at the front of the INCLUDE variable. Warning : <0217>:: Statements have been inserted to trace execution of your program.
run emake.bat
type
emake
-------------------------------------- D:\euphoria-40b2\euming04\MingT>emake Compiling with Watcom Compiling 6% init-.c Compiling 22% DTX_JTestC.c Compiling 33% main-.c Compiling 44% ming.c Compiling 56% dll.c Compiling 67% misc.c Compiling 78% machine.c Compiling 89% get.c Linking 100% DTX_JTestC.dll You can now use DTX_JTestC.dll --------------------------------------
it looks well
explore just created "DTX_JTestC.dll"
-------------------------------------- File type: WINDOWS EXECUTABLE File Header: Machine: 0x014C (Intel x86) Number of Sections: 5 Time Date Stamp: 0x4BB0FDB7 (29.03.2010 20:21:27) Pointer to Symbol Table: 0x00000000 Number of Symbols: 0 Size of Optional Header: 0x00E0 (224) Characteristics: 0x2182 File is executable. Low bytes of machine word are reversed. 32 bit word machine. File is a DLL. Optional Header: Magic: 0x010B Linker Version: 2.18 Size of Code: 0x0003FC00 (261120) Size of Initialized Data: 0x00024200 (147968) Size of Uninitialized Data: 0x00000000 (0) Adress of Entry Point: 0x00032D56 Base of Code: 0x00001000 Base of Data: 0x00041000 Image Base: 0x00400000 Section Align: 0x00001000 File Align: 0x00000200 Operating System Version: 1.11 Image Version: 0.00 Subsystem Version: 4.00 ...... Number of Rva and Sizes: 16 Data Directory: Export directory: VA: 0x000C9000 Size: 0x00000094 (148) Import directory: VA: 0x00041000 Size: 0x00000D2B (3371) ...... (unknown directory entry): VA: 0 Size: 0 Export Table: Name: DTX_JTestC.dll Time Date Stamp: 0x00000000 Version: 0.00 Ordinal Base: 1 Number of Functions: 5 Number of Names: 5 Ordinal Entry Point Name 1 0x00002210 main 4 0x00019C40 regcomp_ 2 0x00019B80 regerror_ 5 0x00019CF0 regexec_ 3 0x00019C30 regfree_ Import Table: USER32.DLL Import Adress Table: 0x0004124C Import Name Table: 0x00041050 Time Date Stamp: 0x00000000 Index of first forwarder reference: 0x00000000 0x0004146C 1 CharUpperA 0x0004147A 2 MessageBoxA KERNEL32.DLL Import Adress Table: 0x00041258 Import Name Table: 0x0004105C Time Date Stamp: 0x00000000 Index of first forwarder reference: 0x00000000 0x00041488 1 AllocConsole 0x00041498 2 CloseHandle 0x000414A6 3 CreateConsoleScreenBuffer ...... 0x00041B80 92 WriteConsoleA 0x00041B90 93 WriteConsoleOutputA 0x00041BA6 94 WriteConsoleOutputAttribute 0x00041BC4 95 WriteConsoleOutputCharacterA 0x00041BE4 96 WriteFile WS2_32.DLL Import Adress Table: 0x000413DC Import Name Table: 0x000411E0 Time Date Stamp: 0x00000000 Index of first forwarder reference: 0x00000000 0x00041BF0 1 WSACleanup 0x00041BFE 2 WSAGetLastError 0x00041C10 3 WSAStartup 0x00041C1E 4 __WSAFDIsSet ..... 0x00041D16 25 shutdown 0x00041D22 26 socket Section Table: Section Header #1 Name: AUTO Virtual Size: 0x0003FB9C (261020) ..... Number of Relocations: 0 Number of Line Numbers: 0 Characteristics: 0x42000040 Section contains initialized data. Section can be discarded. Section is readable. --------------------------------------
only 5 Entry Points in our "DTX_JTestC.dll" ???
the "DTX_JTestC.dll" made with EUPHORIA 3.1.1
there are about 259 Entry Points ???
Ordinal Entry Point Name
1 0x00002210 main
4 0x00019C40 regcomp_
2 0x00019B80 regerror_
5 0x00019CF0 regexec_
3 0x00019C30 regfree_
------------------------------------
if you want to test the "DTX_JTestC.dll" with a calling program
there will be a zip file with all included
also test.wpj a project file for Watcom IDE
let me know is of interest to you.
ONLY TO EXPLAIN WHATS GOING ON A SMALL PIECE OF CODE
gen32.c --> to Test.exe -------------------------------------- #include <windows.h> #include <stdio.h> #include <malloc.h> #include "gen32.h" #include "stddef.h" /* defines offsetof macro */ HINSTANCE MyInstance; static BOOL FirstInstance( HINSTANCE ); static BOOL AnyInstance( HINSTANCE, int, LPSTR ); HWND hwndH; long _EXPORT FAR PASCAL WindowProc( HWND, unsigned, UINT, LONG ); int w4; ..... typedef void (WINAPI *PFNDLL)( VOID ); HINSTANCE dllctrl_inst; PFNDLL idll; ..... dllctrl_inst = LoadLibrary( "DTX_JTestC.dll" ); if( dllctrl_inst != NULL ) { idll = (PFNDLL)GetProcAddress( dllctrl_inst, "main" ); if( idll != NULL ) { idll(); } } ..... --------------------------------------
copy the new DTX_JTestC.dll to the Folder
inside "test.exe"
run test.exe
oh, oh, oh it crashes
------------------------------------
a look at "ctrace-d.out" to see what's happend
ctrace-d.out
-------------------------------------- DTX_JTestC.exw:14 main() DTX_JTestC.exw:10 init_ming() ming.ew:162 rc = Ming_init() ..... ming.ew:84 SWF_versionNum = get_version() ming.ew:77 xSWF_versionNum_a = define_c_var(ming_dll, "SWF_versionNum") ..... DTX_JTestC.exw:11 Ming_useSWFVersion(VERSION5) ming.ew:542 xMing_useSWFVersion = define_c_proc(ming_dll, calltype & "Min ..... DTX_JTestC.exw:12 end procedure DTX_JTestC.exw:10 init_ming() ming.ew:162 rc = Ming_init() ming.ew:147 ret = -1 ming.ew:148 xMing_init = define_c_func(ming_dll, calltype & "Ming_init", dll.e:56 return machine_func(M_DEFINE_C, {lib, routine_name, arg_types, r ming.ew:149 if xMing_init != -1 then ming.ew:152 puts(2, "Fatal: ming.ew: Ming_init error\n") ming.ew:153 abort(1) === THE END === --------------------------------------
It looks like the code will be executed 2 times
1 x seems automatic and
next time with crash at ming.ew:152
why 2 x init_ming() ?? I call main() only once ???? I dont't know but that is not would I have expected
the code runs automatic when I open the DTX_JTestC.dll
it runs again when I call "_1main()"
Let me try to change this behavior below the both .c Files
DTX_JTestC.c -------------------------------------- // Euphoria To C version 4.0.0 beta 2 (r2670) #include "include/euphoria.h" #include "main-.h" void __stdcall _1main() { int _0, _1, _2; ctrace("DTX_JTestC.exw:10 init_ming()"); _2init_ming(); ctrace("DTX_JTestC.exw:11 Ming_useSWFVersion(VERSION5)"); _2Ming_useSWFVersion(5); ctrace("DTX_JTestC.exw:12 end procedure"); return; ; } --------------------------------------
main-.c (shortened) -------------------------------------- // Euphoria To C version 4.0.0 beta 2 (r2670) #include <time.h> #include "include\euphoria.h" #include "main-.h" int Argc; char **Argv; unsigned default_heap; __declspec(dllimport) unsigned __stdcall GetProcessHeap(void); ..... char *stack_base; int total_stack_size = 262144; int __stdcall _CRT_INIT (int, int, void *); void EuInit() { ..... Argc = 0; default_heap = GetProcessHeap(); ..... init_literal(); ..... ctrace("machine.e:307 check_calls = 1"); ctrace("ming.ew:16 ming_dll = open_dll(\"libming_eu1.dll\")"); _0 = _3open_dll(_477); ..... ctrace("ming.ew:17 if ming_dll = 0 then"); if (binary_op_a(NOTEQ, _2ming_dll_1087, 0)){ goto L1; // [71] 101 } ..... ctrace("ming.ew:22 abort(1)"); UserCleanup(1); L1: ctrace("ming.ew:26 init_rtns = {} -- these must be parameterless procedures"); ..... ctrace("ming.ew:32 SWF_versionNum = -1 -- not initialised"); _2SWF_versionNum_1097 = -1; ctrace("ming.ew:88 init_rtns &= rid_get_version -- call get_version as part of init_ming()"); ..... ctrace("DTX_JTestC.exw:6 trace(1)"); TraceOn = 1; -->>>> ctrace("DTX_JTestC.exw:14 main()"); -->>>> _1main(); ..... DeRef1(_2M_PI_1147); ; } int __stdcall LibMain(int hDLL, int Reason, void *Reserved) { if (Reason == 1) EuInit(); return 1; } --------------------------------------
look at
ctrace("DTX_JTestC.exw:10 init_ming()");
_2init_ming();
ctrace("DTX_JTestC.exw:11 Ming_useSWFVersion(VERSION5)");
_2Ming_useSWFVersion(5);
ctrace("DTX_JTestC.exw:12 end procedure");
return;
>>>>
returns to main-.c ! this works because it's all done by the
initial code in main-.c before it jumps to DTX_JTestC.c _1main();
----------
for example: done in main-.c
default_heap = GetProcessHeap();
init_literal();
ming_dll = open_dll(\"libming_eu1.dll\")");
etc.
in trace mode Watcom IDE (test.exe) after
idll = (PFNDLL)GetProcAddress( dllctrl_inst, "main" );
if( idll != NULL ) {
next step key(F10)
>>>> idll();
that crashes ! thats what i expected.
Because now DTX_JTestC.c "_1main();" will called directly
without calling the inital code in main-.c
but I have no other choice the only entry point in my DLL is "main"
DTX_JTestC.c _1main();
to explain that more in detail
let's add a few code
-------------------------------------- main-.c before -------------------------------------- int __stdcall LibMain(int hDLL, int Reason, void *Reserved) { if (Reason == 1) EuInit(); return 1; } -------------------------------------- main-.c with new code -------------------------------------- int __stdcall LibMain(int hDLL, int Reason, void *Reserved) { TraceOn = 1; if (Reason > 1) { ctrace("main-.c:148 before Reason call By Me");} else { ctrace("main-.c:148 before Reason call NOT By Me");} if (Reason == 2) { ctrace("main-.c:151 before Euinit"); EuInit(); ctrace("main-.c:153 after Euinit"); } return Reason; } --------------------------------------
next Post PART#2