1. Sequence-Atom-DLL
- Posted by president at insight-concepts.com Jun 02, 2003
- 409 views
Hi, I have been practicing creating and using .DLLs with Euphoria and the C Translator. I created a small .dll with a procedure File_Compress(sequence infile, sequence outfile, sequence setting) When trying to call the procedure from a test application, I get an error "Fatal run-time error: device or file name must be a sequence" I tried changing the data to a sequence and then I received and error that arguments to C routines must be atoms. My question is how do I pass the sequence to the dll if arguments to C routines must be atoms ? Best regards, Chris
2. Re: Sequence-Atom-DLL
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 02, 2003
- 393 views
----- Original Message ----- From: <president at insight-concepts.com> To: "EUforum" <EUforum at topica.com> Subject: Sequence-Atom-DLL > > > Hi, > > I have been practicing creating and using .DLLs with Euphoria and the C > Translator. > > I created a small .dll with a procedure File_Compress(sequence infile, > sequence outfile, > sequence setting) > > When trying to call the procedure from a test application, I get an > error "Fatal run-time error: device or file name must be a sequence" > > I tried changing the data to a sequence and then I received and error > that arguments to C routines must be atoms. > > My question is how do I pass the sequence to the dll if arguments to C > routines must be atoms ? > You might have to pass the 'string' as an address. So in the calling program you do this... atom infileA, outfileA, settingA infileA = allocate(length(InFileName) + 1) poke(infileA, length(InFileName)) poke(infileA+1, InFileName) outfileA = allocate(length(OutFileName) + 1) poke(outfileA, length(OutFileName)) poke(outfileA+1, OutFileName) settingA = allocate(length(Setting) + 1) poke(settingA, length(Setting)) poke(settingA+1, Setting) c_proc(comp, {infileA, outfileA, settingA} ) free(infileA) free(outfileA) free(settingA) And in the 'dll' code ... procedure File_Compress(atom InFile, atom OutFile, atom Setting) sequence infilename, outfilename, setttings atom len len = peek(InFile) infilename = peek({InFile+1, len}) len = peek(OutFile) outfilename = peek({OutFile+1, len}) len = peek(Setting) settings = peek({Setting+1, len}) . . . end procedure This what you would have to do with a C written DLL. And BTW, this method assumes strings are less than 256 bytes. -- Derek
3. Re: Sequence-Atom-DLL
- Posted by Robert Craig <rds at RapidEuphoria.com> Jun 02, 2003
- 392 views
president at insight-concepts.com wrote: > I have been practicing creating and using .DLLs with Euphoria and the C > Translator. > > I created a small .dll with a procedure File_Compress(sequence infile, > sequence outfile, > sequence setting) > > When trying to call the procedure from a test application, I get an > error "Fatal run-time error: device or file name must be a sequence" > > I tried changing the data to a sequence and then I received and error > that arguments to C routines must be atoms. When calling a .dll routine that's written in Euphoria, you can pass any kind of Euphoria data as arguments to the routine, but you must declare the routine using define_c_proc/func and the E_ types (E_INTEGER, E_ATOM, ...), not the C_ types (C_INT, ...). e.g. fc = define_c_proc(lib, "File_Compress", {E_SEQUENCE, E_SEQUENCE, E_SEQUENCE}) c_proc(fc, {"infile.dat", "outfile.dat", {1,2,3}}) Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
4. Re: Sequence-Atom-DLL
- Posted by jbrown105 at speedymail.org Jun 02, 2003
- 380 views
On Mon, Jun 02, 2003 at 05:34:53PM -0400, Robert Craig wrote: <snip> > > When calling a .dll routine that's written in Euphoria, > you can pass any kind of Euphoria data as arguments to > the routine, but you must declare the routine using > define_c_proc/func and the E_ types (E_INTEGER, E_ATOM, ...), > not the C_ types (C_INT, ...). > e.g. > fc = define_c_proc(lib, "File_Compress", > {E_SEQUENCE, E_SEQUENCE, E_SEQUENCE}) > > c_proc(fc, {"infile.dat", "outfile.dat", {1,2,3}}) > > > Regards, > Rob Craig > Rapid Deployment Software > http://www.RapidEuphoria.com > Just wondering ... if i wrote a C program, and wanted to use an Eu .dll in it ... how would I call the Eu routine in the translated .dll, and how would I pass it the parameters? jbrown -- /"\ ASCII ribbon | http://www.geocities.com/jbrown1050/ \ / campain against | Linux User:190064 X HTML in e-mail and | Linux Machine:84163 /*\ news, and unneeded MIME |
5. Re: Sequence-Atom-DLL
- Posted by Robert Craig <rds at RapidEuphoria.com> Jun 02, 2003
- 407 views
jbrown105 at speedymail.org wrote: > On Mon, Jun 02, 2003 at 05:34:53PM -0400, Robert Craig wrote: >>When calling a .dll routine that's written in Euphoria, >>you can pass any kind of Euphoria data as arguments to >>the routine, but you must declare the routine using >>define_c_proc/func and the E_ types (E_INTEGER, E_ATOM, ...), >>not the C_ types (C_INT, ...). >>e.g. >> fc = define_c_proc(lib, "File_Compress", >> {E_SEQUENCE, E_SEQUENCE, E_SEQUENCE}) >> >> c_proc(fc, {"infile.dat", "outfile.dat", {1,2,3}}) > > Just wondering ... if i wrote a C program, and wanted to use an Eu .dll > in it ... how would I call the Eu routine in the translated .dll, and how > would I pass it the parameters? It's pretty easy as long as the Euphoria routine is declared with integer parameters (only), and it returns an integer as a result (if anything). It will look just like a C routine that takes int's and returns an int. A C program (after dynamically linking with the Euphoria .dll) could pass int's, up to 31-bits in size and get back a 31-bit int as a result. C and Euphoria agree on the meaning of integers up to 31-bits. Anything else is incompatible. Someone who studied the internal representation of sequences, might be able to allocate and construct a sequence in C, and pass it in, but that's definitely not for the faint of heart. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
6. Re: Sequence-Atom-DLL
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 02, 2003
- 394 views
On Mon, 02 Jun 2003 19:31:53 -0400, Robert Craig <rds at RapidEuphoria.com> wrote: > > > jbrown105 at speedymail.org wrote: >> On Mon, Jun 02, 2003 at 05:34:53PM -0400, Robert Craig wrote: >>> When calling a .dll routine that's written in Euphoria, >>> you can pass any kind of Euphoria data as arguments to >>> the routine, but you must declare the routine using >>> define_c_proc/func and the E_ types (E_INTEGER, E_ATOM, ...), >>> not the C_ types (C_INT, ...). >>> e.g. >>> fc = define_c_proc(lib, "File_Compress", >>> {E_SEQUENCE, E_SEQUENCE, E_SEQUENCE}) >>> >>> c_proc(fc, {"infile.dat", "outfile.dat", {1,2,3}}) >> >> Just wondering ... if i wrote a C program, and wanted to use an Eu .dll >> in it ... how would I call the Eu routine in the translated .dll, and >> how >> would I pass it the parameters? > > It's pretty easy as long as the Euphoria routine is > declared with integer parameters (only), and it returns > an integer as a result (if anything). It will look just like a > C routine that takes int's and returns an int. > A C program (after dynamically linking with the Euphoria .dll) > could pass int's, up to 31-bits in size and get back > a 31-bit int as a result. C and Euphoria agree on the meaning > of integers up to 31-bits. Anything else is incompatible. Just to clarify, does this also mean that 32-bit addresses might pose a problem? And what about flags bits such as #8F12817F ? > Someone who studied the internal representation of sequences, > might be able to allocate and construct a sequence in C, > and pass it in, but that's definitely not for the > faint of heart. > So normally we need to convert a sequence to some form of RAM structure and pass an address instead? -- Derek -- cheers, Derek Parnell
7. Re: Sequence-Atom-DLL
- Posted by Elliott Sales de Andrade <quantum_analyst at hotmail.com> Jun 03, 2003
- 400 views
>From: Derek Parnell <ddparnell at bigpond.com> >Subject: Re: Sequence-Atom-DLL > > >On Mon, 02 Jun 2003 19:31:53 -0400, Robert Craig <rds at RapidEuphoria.com> >wrote: > >> >>jbrown105 at speedymail.org wrote: >>>On Mon, Jun 02, 2003 at 05:34:53PM -0400, Robert Craig wrote: >>>>When calling a .dll routine that's written in Euphoria, >>>>you can pass any kind of Euphoria data as arguments to >>>>the routine, but you must declare the routine using >>>>define_c_proc/func and the E_ types (E_INTEGER, E_ATOM, ...), >>>>not the C_ types (C_INT, ...). >>>>e.g. >>>>fc = define_c_proc(lib, "File_Compress", >>>>{E_SEQUENCE, E_SEQUENCE, E_SEQUENCE}) >>>> >>>>c_proc(fc, {"infile.dat", "outfile.dat", {1,2,3}}) >>> >>>Just wondering ... if i wrote a C program, and wanted to use an Eu .dll >>>in it ... how would I call the Eu routine in the translated .dll, and how >>>would I pass it the parameters? >> >>It's pretty easy as long as the Euphoria routine is >>declared with integer parameters (only), and it returns >>an integer as a result (if anything). It will look just like a >>C routine that takes int's and returns an int. >>A C program (after dynamically linking with the Euphoria .dll) >>could pass int's, up to 31-bits in size and get back >>a 31-bit int as a result. C and Euphoria agree on the meaning >>of integers up to 31-bits. Anything else is incompatible. > >Just to clarify, does this also mean that 32-bit addresses might pose a >problem? And what about flags bits such as #8F12817F ? If you want it to receive possible 32-bit values, try reading this: http://logicsoft.pcplayground.com/modules.php?name=FAQ&myfaq=yes&id_cat=3&categories=Euphoria+and+Other+Programming+Languages >>Someone who studied the internal representation of sequences, >>might be able to allocate and construct a sequence in C, >>and pass it in, but that's definitely not for the >>faint of heart. >> > >So normally we need to convert a sequence to some form of RAM structure and >pass an address instead? -- Derek > Can't help you there.
8. Re: Sequence-Atom-DLL
- Posted by Robert Craig <rds at RapidEuphoria.com> Jun 03, 2003
- 408 views
Derek Parnell wrote: > Just to clarify, does this also mean that 32-bit addresses might pose a > problem? And what about flags bits such as #8F12817F ? With 32 bits you can represent signed integers from -2 billion to +2 billion roughly. Euphoria (currently) treats only -1 billion to + 1 billion as integers, and anything outside that range is considered a handle of a floating-point number or sequence. So yes, you'd have to be careful with 32-bit addresses and high-magnitude integers when passing them *from a C program to a Euphoria .dll*. >> Someone who studied the internal representation of sequences, >> might be able to allocate and construct a sequence in C, >> and pass it in, but that's definitely not for the >> faint of heart. > > So normally we need to convert a sequence to some form of RAM structure > and pass an address instead? -- Derek Normally you would *not* be calling a Euphoria .dll routine from a C program. You'd be calling it from a Euphoria program (either interpreted or translated/compiled), in which case everything is simple and seamless - you just declare the parameters of the routine using E_INTEGER, E_ATOM, E_SEQUENCE or E_OBJECT and you can then pass whatever Euphoria data you like without worrying about addresses, 31 vs. 32 bits or any of that stuff. However, if you want to call a Euphoria .dll routine *from a C program*, you can pass 31-bit integers easily, but to pass a sequence, you would have to first construct it in memory, then pass its address. To be safe you'd have to pass the address as two 16-bit arguments to avoid the "31-bit" problem. I expect that the vast majority of people will want to call Euphoria .dll's from Euphoria programs. Those people need not be concerned about 31 vs 32 bits etc. They can pass and receive back atoms and complex sequences of any size or shape, without worrying about how things are implemented at the bit-level. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
9. Re: Sequence-Atom-DLL
- Posted by Robert Craig <rds at RapidEuphoria.com> Jun 03, 2003
- 406 views
C. K. Lester wrote: > Why make anything a .DLL? I'm guessing there's a speed-up in execution of > the code? Is that the only benefit... speed? You have to compare it with simply making your library source available as an include file. In .dll form ... Your library will execute faster, even for people who don't use the Translator. Your source code will be well hidden. It will actually be better hidden than if you wrote the library in C and compiled to machine code, since the Euphoria to C translation makes the mapping from source to machine code even more obscure. (you could also use the shrouder to hide your code). Your code will be immune to changes in other include files. Your library might be usable by a program written in another language. Although as we've seen, there are some issues there. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
10. Re: Sequence-Atom-DLL
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 03, 2003
- 411 views
On Mon, 2 Jun 2003 23:11:12 -0500, C. K. Lester <cklester at yahoo.com> wrote: > > >> I expect that the vast majority of people will >> want to call Euphoria .dll's from Euphoria programs. > > Why make anything a .DLL? I'm guessing there's a speed-up in execution of > the code? Is that the only benefit... speed? > I believe that Windows only loads one copy of the DLL into RAM, regardless of how many processes are using it. It removes it from RAM when the last process that opened it has ended. This is why DLL is very suitable for routines that are likely to be shared by many applications. -- cheers, Derek Parnell
11. Re: Sequence-Atom-DLL
- Posted by Robert Craig <rds at RapidEuphoria.com> Jun 03, 2003
- 409 views
aku saya wrote: > A suggestion for ec*.exe > > if -dll parameter is passed, the ec*.exe should make a wrapper file > automatically (suggested name: filename.ed) > > it contains something like: Thanks, I'll consider that. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com