It is said that, "a wise man knows his own turnips." In my case, I've run into some difficulty converting GNAT.Spitbol to UTF-32. The compiler error messages are marvellously helpful, but I'm a newbie to Ada and ... yeah, well, you get the idea.
The source code is up on Box.net, if you feel so inclined as to download it and tell me where I'm going wrong.
Past (20 years or so) and present code. A variety of languages and platforms. Some gems. More gravel. Some useful stuff and some examples of how not to do it.
Showing posts with label Ada. Show all posts
Showing posts with label Ada. Show all posts
Monday, December 10, 2007
Monday, December 03, 2007
[Ada (GNAT/GCC)] VARPTR, GNAT and data "transput"
Okay, have got it figured (soli Deo gloria!)
The following listings demonstrate the passing of a two part Type containing two Singles from VB6 into a GNAT/GCC DLL. Once inside, the elements of the Type are swapped and control returns to VB6. VB6 then displays the results.
As before, the code has been worked out in the context of the afore-posted
First up, the additions to api.ads:
Next, the additions to api.adb:
API.DEF must also be modified, adding
Next, some VB code to demonstrate ...
... and part of a sample output.
The project that all this was part of was done in both GNAT/GCC and ObjectAda 7.2.2. Interestingly, ObjectAda's Float is equivalent to VB6's Double, whereas GNAT/GCC's Float is equivalent to VB6's Single. Does anyone know why?
By the way, regarding "transput", Wikipedia's article on Algol states:
© Copyright Bruce M. Axtens, 2007
The following listings demonstrate the passing of a two part Type containing two Singles from VB6 into a GNAT/GCC DLL. Once inside, the elements of the Type are swapped and control returns to VB6. VB6 then displays the results.
As before, the code has been worked out in the context of the afore-posted
api project. If you want to play with this, just take the earlier work and tweak it appropriately.First up, the additions to api.ads:
Next, the additions to api.adb:
API.DEF must also be modified, adding
swapsingles to the list of EXPORTS.Next, some VB code to demonstrate ...
... and part of a sample output.
The project that all this was part of was done in both GNAT/GCC and ObjectAda 7.2.2. Interestingly, ObjectAda's Float is equivalent to VB6's Double, whereas GNAT/GCC's Float is equivalent to VB6's Single. Does anyone know why?
By the way, regarding "transput", Wikipedia's article on Algol states:
ALGOL 60 as officially defined had no I/O facilities; implementations defined their own in ways that were rarely compatible with each other. In contrast, ALGOL 68 offered an extensive library of transput (ALGOL 68 parlance for Input/Output) facilities.A extensive library of transput facilities is something you'll find in Protium, too.
© Copyright Bruce M. Axtens, 2007
Wednesday, November 28, 2007
[Ada (GNAT/GCC)] Passing data with VB6's VARPTR to Ada
In the current project, I've been trying to figure out how to pass data to Ada. Because I'll be passing Long, Double (Float), and two Types to emulate a LongLong and a DoubleDouble, I decided I'd use VB's VarPtr and have Ada sort the mess out on its side.
After the loss of a little hair, the reading of bits of Michael B. Feldman's Software Construction and Data Structures with Ada 95, and with help from Martin Krischik and Simon Wright, I came up with the following.
The code was worked out in the context of the afore-posted
First up, the additions to api.ads:
Next, the additions to api.adb:
Next, some VB code to demonstrate ...
... and a sample output.
I'm in the process now of working out how to access the LongLong and DoubleDouble Types. Shall keep you posted.
By the way, the return value will eventually be a pointer as well. That'll keep the VB programmer on his toes.
© Copyright Bruce M. Axtens, 2007
After the loss of a little hair, the reading of bits of Michael B. Feldman's Software Construction and Data Structures with Ada 95, and with help from Martin Krischik and Simon Wright, I came up with the following.
The code was worked out in the context of the afore-posted
api project. If you want to play with this, just take the earlier work and stuff this into it.First up, the additions to api.ads:
Next, the additions to api.adb:
Next, some VB code to demonstrate ...
... and a sample output.
I'm in the process now of working out how to access the LongLong and DoubleDouble Types. Shall keep you posted.
By the way, the return value will eventually be a pointer as well. That'll keep the VB programmer on his toes.
© Copyright Bruce M. Axtens, 2007
Monday, November 26, 2007
[Ada (GNAT/GCC)] Better build automation
Just after I notified comp.lang.ada of my posting re GNAT/GPL, Martin Krischik wrote suggesting I use a .gpr file and
After reading a friendly manual, I came up with the following .grp file and a batch file to control it.
I have stayed with the batch file, simply because I can't yet see how to have a multiple-program linkage (
First,
And then,
Trust that's helpful.
© Copyright Bruce M. Axtens, 2007
gnat make rather than a direct reference to gcc. After reading a friendly manual, I came up with the following .grp file and a batch file to control it.
I have stayed with the batch file, simply because I can't yet see how to have a multiple-program linkage (
gnatlink, dlltool and gnatlink a second time).First,
build.gprAnd then,
build.bat. Note the call to UPX, which compresses the release version of the .DLL. Note also that the debug and release subdirectories must already exist (though it wouldn't have been difficult to check-for-and-create-if-missing.)Trust that's helpful.
© Copyright Bruce M. Axtens, 2007
Friday, November 23, 2007
[Ada (GNAT/GCC)] Creating DLLs for VB6
And finally, after much prayer and perspiration, the GNAT/GCC version. Again, thanks to Roger Pearse for The Noddy Guide to using ADA code with Visual Basic. I'm sure there was someone else [This space set aside for an attribution.]
First up, api.ads, which declares the functions and exports them.
Next, api.adb, where the declarations are explained.
I'm still working through the issue of what to do with Mangle. Perhaps two routines are needed. The first to ask the DLL how much space is needed, with VB the allocating it, and the second then actually poking the data into the allocated space.
Pattern returns a pointer to the string data. I rediscovered the technique for reading it out and that's in the VB code below. It also seems that, for as long as the DLL is loaded, the data stored in
api.def lists the symbols exported, and is needed by gnatdll.
Now, pulling it all together requires some handwaving on the commandline. From one of the demos I modified the make.bat to look like this:
The output from a run of these is as follows:
Now the VB code. Take note of a few things:
Finally, a sample run under VB6
Next? Well, there's the issue of how to export overloaded functions and procedures. And there's the question of how to pass in complex data types, like records and the like. I'll keep you posted.
(By the way, I'm not doing this merely for the fun of it, but also in pursuit of the fulfillment of my employer's expectations. So more will follow.)
© Copyright Bruce M. Axtens, 2007
First up, api.ads, which declares the functions and exports them.
- function Factorial, which accepts a Win32.LONG and returns a Win32.LONG (I gave up on C.int as it was too small for a Factorial of 16)
- function GetCount, which returns the value of the global
Count(another Win32.LONG) - procedure Mangle, which accepts a Win32.LPWSTR and attempts the same dangerous stuff that Bob6 does in the ObjectAda version.
- function Pattern, which returns a long pointer to some string data
- procedures Initialize_API, and Finalize_API, which I understand are mandatory. (If someone knows better, please tell me.)
Next, api.adb, where the declarations are explained.
I'm still working through the issue of what to do with Mangle. Perhaps two routines are needed. The first to ask the DLL how much space is needed, with VB the allocating it, and the second then actually poking the data into the allocated space.
Pattern returns a pointer to the string data. I rediscovered the technique for reading it out and that's in the VB code below. It also seems that, for as long as the DLL is loaded, the data stored in
foo is available for transfer.api.def lists the symbols exported, and is needed by gnatdll.
Now, pulling it all together requires some handwaving on the commandline. From one of the demos I modified the make.bat to look like this:
The output from a run of these is as follows:
Now the VB code. Take note of a few things:
- Exporting as
DLLgenerates decorated names, but dlltool was able to resolve the decorated ones with the undecorated ones specified in api.def - For reasons I remember reading somewhere, initialize_api and finalize_api are mandatory, and must be the first and last calls to the DLL
- Seeing as woof woof woof woof is longer than foo man chew,
sends up containing foo man chew f woof - As mentioned before, I rediscovered some code for getting data from a pointer and put that in. It's the
PointerToStringfunction at the bottom.
Finally, a sample run under VB6
Next? Well, there's the issue of how to export overloaded functions and procedures. And there's the question of how to pass in complex data types, like records and the like. I'll keep you posted.
(By the way, I'm not doing this merely for the fun of it, but also in pursuit of the fulfillment of my employer's expectations. So more will follow.)
© Copyright Bruce M. Axtens, 2007
Thursday, November 22, 2007
[Ada (GNAT/GPL)] Creating DLLs for VB6
As promised, the GNAT/GPL code. Based on Roger Pearse's The Noddy Guide to using ADA code with Visual Basic.
How I ended up with the names api.ads, api.adb and api.def is an artefact from something I was reading. [This space set aside for an attribution.]
First up, api.ads, which declares the functions and exports them.
Next, api.adb, where the declarations are explained.
Mangle replaces the incoming string with something of its own. If the incoming string is larger or the same size then everything's more or less okay. (Less in the latter case, but at least it doesn't crash.) However, if the incoming string is shorter, VB truncates up to the length it knows about, and who knows what damage we've done with whatever gets overwritten by the rest of
Pattern returns a pointer to the string data. Not knowing a lot about Ada, I don't know if the contents of
api.def lists the symbols exported, and is needed by gnatdll.
Now, pulling it all together requires some handwaving on the commandline.
The output from a run of these is as follows:
Now the VB code. Take note of a few things:
Next stop is to get this working with "GNAT/GCC MS-Windows MinGW 4.2.1 R0". I would prefer to be working under the GMGPL.
© Copyright Bruce M. Axtens., 2007
How I ended up with the names api.ads, api.adb and api.def is an artefact from something I was reading. [This space set aside for an attribution.]
First up, api.ads, which declares the functions and exports them.
- function Factorial, which accepts a C.int and returns a C.int
- procedure Mangle, which accepts a Win32.LPWSTR and attempts the same dangerous stuff that Bob6 does in the ObjectAda version. Still working on this one.
- function Pattern, which returns a Win32.LPWSTR
- procedures Initialize_API, and Finalize_API, which I understand are mandatory. (If someone knows better, please tell me.)
Next, api.adb, where the declarations are explained.
Mangle replaces the incoming string with something of its own. If the incoming string is larger or the same size then everything's more or less okay. (Less in the latter case, but at least it doesn't crash.) However, if the incoming string is shorter, VB truncates up to the length it knows about, and who knows what damage we've done with whatever gets overwritten by the rest of
foo.Pattern returns a pointer to the string data. Not knowing a lot about Ada, I don't know if the contents of
foo will still be there by the time VB looks it and reads out.api.def lists the symbols exported, and is needed by gnatdll.
Now, pulling it all together requires some handwaving on the commandline.
The output from a run of these is as follows:
Now the VB code. Take note of a few things:
- Exporting as
DLLgenerates decorated names, but gnatdll was able to resolve the decorated ones with the undecorated ones specified in api.def - For reasons I remember reading somewhere, initialize_api and finalize_api are mandatory, and must be the first and last calls to the DLL
- Seeing as woof woof woof woof is longer than foo man chew,
sends up containing foo man chew woof
Next stop is to get this working with "GNAT/GCC MS-Windows MinGW 4.2.1 R0". I would prefer to be working under the GMGPL.
© Copyright Bruce M. Axtens., 2007
Tuesday, November 20, 2007
[Ada (ObjectAda 7.2.2)] Creating VB6 DLLs
Creating DLLs for use by VB6 seems to be somewhat of a dark art. From what Roger Pearse, in his The Noddy Guide to using ADA code with Visual Basic says, it doesn't appear to be something easily achieved.
So far I've achieved it, to a certain extent, with ObjectAda and GNAT/GPL. The code for the ObjectAda implementation is below. I'll post the GNAT/GPL stuff in the next couple of days, God willing.
BO_DLib.adb, BO_D.adb and BO_D.ads are all based, albeit rather loosely, on sample files in winapi\samples\petzold\ch19\edrlib\
First up, BO_DLib.adb
Next, the spec file, BO_D.ads
There are six routines:
And, finally, BO_D.adb, where the definitions given in BO_D are fleshed out.
Now the VB code. Take note of a few things:
By the way, if you think my code sucks, say so. I'm a total newb when it comes to Ada. Critiques are always welcome. King Solomon said, "The wise person accepts instructions." and also "Better is open rebuke than hidden love."
© Copyright Bruce M. Axtens., 2007
So far I've achieved it, to a certain extent, with ObjectAda and GNAT/GPL. The code for the ObjectAda implementation is below. I'll post the GNAT/GPL stuff in the next couple of days, God willing.
BO_DLib.adb, BO_D.adb and BO_D.ads are all based, albeit rather loosely, on sample files in winapi\samples\petzold\ch19\edrlib\
First up, BO_DLib.adb
Next, the spec file, BO_D.ads
There are six routines:
- procedure Bob1 calls dobox to show a messagebox.
- function Bob2 returns a long value, 1.
- function Bob3 receives a long and adds 21 to it.
- procedure Bob4 receives a long pointer to a string and passes it to dobox for display.
I can pass Unicode to it and have it rendered appropriately. - function Bob5 receives a long pointer to a string and returns a long being the length of the string.
- function Bob6 receives a long pointer to a string and catenates a string to it.
"Danger, Will Robinson!" ... this is not how to do it and VB complains bitterly.
And, finally, BO_D.adb, where the definitions given in BO_D are fleshed out.
Now the VB code. Take note of a few things:
- I declared the functions and procedures as DLL_Stdcall in BO_D.ads so the routines come in decorated, thus the use of Alias in the Declare line. I used Microsoft's Dependency Walker to discover to what extent the names had been mangled.
- A reference to SCRRUN.DLL was added to the project, making possible the use of the FileSystemObject.
- Bob6 barges past the limit set for the string by VB, so things get a bit unstable. I'm still working through how to pass strings back.
By the way, if you think my code sucks, say so. I'm a total newb when it comes to Ada. Critiques are always welcome. King Solomon said, "The wise person accepts instructions." and also "Better is open rebuke than hidden love."
© Copyright Bruce M. Axtens., 2007
Subscribe to:
Posts (Atom)