FB dll for PowerBASIC
-
- Posts: 4292
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
FB dll for PowerBASIC
I created a FB dll for PowerBASIC; it is for a friend who is not a member of this forum.
Windows issued a message box entitled 'Entry Point Not Found' with contents of "The procedure entry point WHATEVER could not be located in the dynamic link library blahblah.exe"
Dependency Walker told me the entry points were of the form WHATEVER@0 for all procedures except one which was of the form WHATEVER@8. That last one has two LONG parameters equalling 8 bytes and the @0 procedures have no parameters. So, that aspect is reasonable but why were the @n appended in the first place - no wonder the entry point was not found because I am using, obviously, WHATEVER.
I tried to use WHATEVER@0 but that was treated with extreme prejudice.<smile>
I also added an Alias but that did not help either.
You may need more details to help me out here but the above may be enough for someone to recognise the symptoms and have a cure.<smile.
Windows issued a message box entitled 'Entry Point Not Found' with contents of "The procedure entry point WHATEVER could not be located in the dynamic link library blahblah.exe"
Dependency Walker told me the entry points were of the form WHATEVER@0 for all procedures except one which was of the form WHATEVER@8. That last one has two LONG parameters equalling 8 bytes and the @0 procedures have no parameters. So, that aspect is reasonable but why were the @n appended in the first place - no wonder the entry point was not found because I am using, obviously, WHATEVER.
I tried to use WHATEVER@0 but that was treated with extreme prejudice.<smile>
I also added an Alias but that did not help either.
You may need more details to help me out here but the above may be enough for someone to recognise the symptoms and have a cure.<smile.
Re: FB dll for PowerBASIC
That is the default behaviour on Windows (with StdCall being the default calling convention).
see http://freebasic.net/wiki/wikka.php?wak ... xternBlock
and http://freebasic.net/wiki/wikka.php?wak ... onventions
example for StdCall exported as "test":
If you want to learn more about name mangling in general see https://en.wikipedia.org/wiki/Name_mangling
And some further reference :-)
https://docs.microsoft.com/en-us/cpp/cp ... onventions
https://docs.microsoft.com/en-us/cpp/cpp/stdcall
see http://freebasic.net/wiki/wikka.php?wak ... xternBlock
and http://freebasic.net/wiki/wikka.php?wak ... onventions
example for StdCall exported as "test":
Code: Select all
extern "Windows-MS"
function test( a as long) as long export
return 1
End Function
end extern
And some further reference :-)
https://docs.microsoft.com/en-us/cpp/cp ... onventions
https://docs.microsoft.com/en-us/cpp/cpp/stdcall
-
- Posts: 4292
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: FB dll for PowerBASIC
Thanks St_W. Dependency Walker is now showing the correct entry points.
If compiled as a GUI the calling app has to be ended via the Task Manager. If compiled as Console the console opens and sits there with a flashing cursor and is comatose otherwise.
I then put two statements in the calling console app ' Print "FB" ' and 'Print WHATEVER'. If 'Print WHATEVER' is commented then I get "FB". If not commented I get nothing so we are 'crashing' before ' Print "FB" '.
I have all of PowerBASIC's debug options loaded but nothing is being trapped.
I shall go over everything with a fine tooth comb.
I have seen this before. If it was a long time ago then I would remember the solution in great detail. If it was a recent history event then I will have to wait for it to be put into long term memory. As Bernard Shaw wrote: "If I lived long enough I knew something like this would happen." He was talking about dying - I am talking about ageing.<laugh>
If compiled as a GUI the calling app has to be ended via the Task Manager. If compiled as Console the console opens and sits there with a flashing cursor and is comatose otherwise.
I then put two statements in the calling console app ' Print "FB" ' and 'Print WHATEVER'. If 'Print WHATEVER' is commented then I get "FB". If not commented I get nothing so we are 'crashing' before ' Print "FB" '.
I have all of PowerBASIC's debug options loaded but nothing is being trapped.
I shall go over everything with a fine tooth comb.
I have seen this before. If it was a long time ago then I would remember the solution in great detail. If it was a recent history event then I will have to wait for it to be put into long term memory. As Bernard Shaw wrote: "If I lived long enough I knew something like this would happen." He was talking about dying - I am talking about ageing.<laugh>
Re: FB dll for PowerBASIC
So, just to ensure that I understand you correctly, you're trying to build a DLL with FreeBasic (-dll or -dylib) and an application using that DLL in PowerBasic, right?
Are you sure that the calling conventions do match? (does PB use stdcall by default or rather something like cdecl?)
And also that the size of the parameters + return value do match?
I can't think of any other common faults currently. Maybe try simple functions first (e.g. only returning a number, without any I/O).
Is it a 32-bit or 64-bit DLL? Note that you can't mix 32/64-bit applications, but you probably know that anyway.
Unfortunately I don't have PB and know nearly nothing about it, so I can't try it.
Are you sure that the calling conventions do match? (does PB use stdcall by default or rather something like cdecl?)
And also that the size of the parameters + return value do match?
I can't think of any other common faults currently. Maybe try simple functions first (e.g. only returning a number, without any I/O).
Is it a 32-bit or 64-bit DLL? Note that you can't mix 32/64-bit applications, but you probably know that anyway.
Unfortunately I don't have PB and know nearly nothing about it, so I can't try it.
-
- Posts: 4292
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: FB dll for PowerBASIC
Added: You came in, St_W, at the same time I was posting. I don't need to edit as all your questions are answered.
I created a dll with your code, St_W, with nothing added, and that worked in PowerBASIC. So, at least I have a proof of concept. Adding your code to my FreeBASIC code and it doesn't work so something else is putting a 'spanner in the works'. The only thing which is telling me something is wrong is the console taking about five seconds to close after I hit the close button. Windows then has got it's knickers in a right twist but, as is often the case, it has absolutely no idea why so keeps it's mouth shut.
Added: Having got a proof of concept then I will find the problem and will report back on my sagacity; a highly unlikely event but one which must be taken into consideration.<Ha, ha>
I created a dll with your code, St_W, with nothing added, and that worked in PowerBASIC. So, at least I have a proof of concept. Adding your code to my FreeBASIC code and it doesn't work so something else is putting a 'spanner in the works'. The only thing which is telling me something is wrong is the console taking about five seconds to close after I hit the close button. Windows then has got it's knickers in a right twist but, as is often the case, it has absolutely no idea why so keeps it's mouth shut.
Added: Having got a proof of concept then I will find the problem and will report back on my sagacity; a highly unlikely event but one which must be taken into consideration.<Ha, ha>
Last edited by deltarho[1859] on Jul 30, 2017 17:07, edited 1 time in total.
Re: FB dll for PowerBASIC
hm, are you using anything from the gfxlib (even if its only "screen 0") ?
Or are FreeBasic Strings involved in the call (as parameter or return value) ?
//edit:
Or are you using module con-/destructors in you dll?
... I'm running out of ideas, but an issue with some FB-internal thing is equally likely as some fault on your side.
Or are FreeBasic Strings involved in the call (as parameter or return value) ?
//edit:
Or are you using module con-/destructors in you dll?
... I'm running out of ideas, but an issue with some FB-internal thing is equally likely as some fault on your side.
Last edited by St_W on Jul 30, 2017 17:13, edited 2 times in total.
-
- Posts: 4292
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: FB dll for PowerBASIC
Nope.hm, are you using anything from the gfxlib (even if its only "screen 0") ?
Nope. No parameters and a Double Export. That last one sounds like a strong beer - this must be driving me to drink and I wasn't aware of it. Oh dear, I must put the kettle on.Or are FreeBasic Strings involved in the call (as parameter or return value) ?
Re: FB dll for PowerBASIC
Hi deltarho[]
I tried out powerbasic here on Win10.(64 bit)
Nothing works.
pbwin.exe seems to be 16 bits.
I can get an ide up
PBedit.exe
but I get an error message for a hello world in pbmain
Same as:
( Unsupported 16 bit application -- Doesn't work on 64 bit system)
(Just as well I didn't pay for anything)
I tried out powerbasic here on Win10.(64 bit)
Nothing works.
pbwin.exe seems to be 16 bits.
I can get an ide up
PBedit.exe
but I get an error message for a hello world in pbmain
Same as:
( Unsupported 16 bit application -- Doesn't work on 64 bit system)
(Just as well I didn't pay for anything)
-
- Posts: 4292
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: FB dll for PowerBASIC
Hi dodicat
Many moons ago both compilers, written in assembler, GUI and Console, were 16 bit but they compiled source code to 32 bit. At some point, I cannot remember when, both compilers became 32 bit and they were given to existing customers for free. For quite a while the 'flagship' compilers were for 'hard earned' but the previous versions were free. The latest versions are V10 for the GUI and V6 for the Console so the versions 9 and 6 respectively were free.
PowerBASIC changed hands in January. I have just visited the website and it appears that the free versions are no longer available. I have the previous versions, paid for when they were 'flagship' themselves but, I am sure you will appreciate, I cannot hand them out on a platter because the free versions came with a licence just as the paid for versions. The paid for versions cost less today but they have not been updated for over six years. If I was coming into the market now I would not be parting with any brass. The new owner's intention is to develop new versions and introduce a 64 bit compiler but I, for one, will not be holding my breath. I believe them - they are a US tax software developer and their flagship product is written in PowerBASIC. It is in their interest to develop PB and if they can make money on PB sales as well ... then why not.
Many moons ago both compilers, written in assembler, GUI and Console, were 16 bit but they compiled source code to 32 bit. At some point, I cannot remember when, both compilers became 32 bit and they were given to existing customers for free. For quite a while the 'flagship' compilers were for 'hard earned' but the previous versions were free. The latest versions are V10 for the GUI and V6 for the Console so the versions 9 and 6 respectively were free.
PowerBASIC changed hands in January. I have just visited the website and it appears that the free versions are no longer available. I have the previous versions, paid for when they were 'flagship' themselves but, I am sure you will appreciate, I cannot hand them out on a platter because the free versions came with a licence just as the paid for versions. The paid for versions cost less today but they have not been updated for over six years. If I was coming into the market now I would not be parting with any brass. The new owner's intention is to develop new versions and introduce a 64 bit compiler but I, for one, will not be holding my breath. I believe them - they are a US tax software developer and their flagship product is written in PowerBASIC. It is in their interest to develop PB and if they can make money on PB sales as well ... then why not.
Re: FB dll for PowerBASIC
I was only wanting to experiment with a freebasic dll.
My powerbasic works fine on WinXP, so I might try it on my other machine.
Perhaps wrap it in extern "c"
end extern.
Or make your declarations cdecl, If that can be done with Power basic.
My powerbasic works fine on WinXP, so I might try it on my other machine.
Perhaps wrap it in extern "c"
end extern.
Or make your declarations cdecl, If that can be done with Power basic.
Re: FB dll for PowerBASIC
this works here
FB code
mydll.bas
PowerBasic code
I think there's a compiler option so that it will export the functions without the @16 but can't remember what it is.
FB code
mydll.bas
Code: Select all
'' All FB functions are by default STDCALL on Windows (CDECL on Linux/DOS)
function AddNumbers alias "AddNumbers"( byval a as double, byval b as double) as double export
function = a + b
end function
Code: Select all
#COMPILE EXE
#DIM ALL
DECLARE FUNCTION AddNumbers STDCALL LIB "mydll.dll" ALIAS "AddNumbers@16" (BYVAL a AS DOUBLE, BYVAL b AS DOUBLE) AS DOUBLE
FUNCTION PBMAIN () AS LONG
PRINT AddNumbers(3,4)
PRINT "----------------------------------------"
PRINT "All done. Press any key to finish"
WAITKEY$
END FUNCTION
-
- Posts: 4292
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: FB dll for PowerBASIC
Thanks srvaldez.
I tried your method but no no avail, unfortunately.
Your method saw the @ in Dependency Walker.
I got St_W's little snippet to work using Extern and Dependency Walker showed the correct entry points.
I am getting the correct entry points with my larger code following a successful dll creation and PowerBASIC is compiling OK but on trying to get PowerBASIC to execute 'MsgBox Str$(Dummy)', where Dummy is a long, the app hangs and I have to end it in Task Manager.
The bas that the dll is based upon works OK.
Nothing is telling me that anything is untoward and if anything is slightly out of the ordinary Windows just heads for the hills - it always has done. I haven't had an automatic Windows 10 update since April - I go to MS once a week and manually update if anything is available. They keep coming out with an updated Update Diagnostic every five minutes but they couldn't catch a cold.
I tried your method but no no avail, unfortunately.
Your method saw the @ in Dependency Walker.
I got St_W's little snippet to work using Extern and Dependency Walker showed the correct entry points.
I am getting the correct entry points with my larger code following a successful dll creation and PowerBASIC is compiling OK but on trying to get PowerBASIC to execute 'MsgBox Str$(Dummy)', where Dummy is a long, the app hangs and I have to end it in Task Manager.
The bas that the dll is based upon works OK.
Nothing is telling me that anything is untoward and if anything is slightly out of the ordinary Windows just heads for the hills - it always has done. I haven't had an automatic Windows 10 update since April - I go to MS once a week and manually update if anything is available. They keep coming out with an updated Update Diagnostic every five minutes but they couldn't catch a cold.
Re: FB dll for PowerBASIC
hello deltarho[1859]
do you by any chance have the dll open in dependency walker while you are trying to run the PowerBasic code?
if so, try closing dependency walker and then run the PB program again.
do you by any chance have the dll open in dependency walker while you are trying to run the PowerBasic code?
if so, try closing dependency walker and then run the PB program again.
-
- Posts: 4292
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: FB dll for PowerBASIC
No, I closed Dependency Walker down straight away.
Actually, I dropped a clanger with your method - I had 'Alias "Dummy" () As Long' instead of 'Alias "Dummy@4" () As Long'.
However, when I do Windows tells me "The procedure entry point Dummy@4 could not be located in the dynamic link library ...".
I have PowerBASIC dlls working in FreeBASIC.
I am going to leave this alone for a few days - somebody is waving a flag at me with "FreeBASIC is making you jump through hoops again!" written on it. I didn't need to see the flag - I sensed it coming over the horizon.<groan>
I see poor old Dinosaur is having a nightmare with Linux Mint and poseidonFB. A few years ago I had a Windows box and a Ubuntu box sharing my internet connection. I persevered with Ubuntu for 12 months and one night there was a loud crack in my Ubuntu box and it 'keeled over'. I looked at it and thought "Thank Christ for that." I looked at my Windows box and said "You can have the full bandwidth back now.". Well, not really. I bought a poetic licence some time ago and I try to get my money's worth.<smile>
Actually, I dropped a clanger with your method - I had 'Alias "Dummy" () As Long' instead of 'Alias "Dummy@4" () As Long'.
However, when I do Windows tells me "The procedure entry point Dummy@4 could not be located in the dynamic link library ...".
I have PowerBASIC dlls working in FreeBASIC.
I am going to leave this alone for a few days - somebody is waving a flag at me with "FreeBASIC is making you jump through hoops again!" written on it. I didn't need to see the flag - I sensed it coming over the horizon.<groan>
I see poor old Dinosaur is having a nightmare with Linux Mint and poseidonFB. A few years ago I had a Windows box and a Ubuntu box sharing my internet connection. I persevered with Ubuntu for 12 months and one night there was a loud crack in my Ubuntu box and it 'keeled over'. I looked at it and thought "Thank Christ for that." I looked at my Windows box and said "You can have the full bandwidth back now.". Well, not really. I bought a poetic licence some time ago and I try to get my money's worth.<smile>
Last edited by deltarho[1859] on Jul 30, 2017 22:19, edited 1 time in total.
Re: FB dll for PowerBASIC
that means your PB function declaration is wrong, it must match the exported name, use the alias so it will match the case.
also, if your function takes no parameters, then @4 is wrong, perhaps it's @0
btw, did you bother to try my example?
also, if your function takes no parameters, then @4 is wrong, perhaps it's @0
btw, did you bother to try my example?