Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Ok - Not DarkGDK - But yes but no - Loading a DLL issues. (Maybe a TempIceP ?)

Author
Message
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 16th Jan 2008 05:50
Hi,

I know I shouldn't be having issues here but I am. The help for LoadLibrary, extern cdecl and all that jazz doesn't add up for me.

I have a DLL with one function. Its just a plain "C" style DLL.

How wouls I load and call the function in it? I know the name.

thanx in advance

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 16th Jan 2008 06:17
This code chokes (From MSDN Manual but retro fitted for darkGDK)


Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 16th Jan 2008 07:43 Edited at: 16th Jan 2008 08:08
You have to specify the decorated function name in GetProcAddress unless it's exported undecorated.

You're doing it pretty much right, but here is how I would do it:



jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 16th Jan 2008 14:00
This is the equiv to a hello world dll...for a calculator


I like the look of your code versus the MSDN one.

Note the TEXT() function was in the MSDN docs for LoadLibrary, my guess is it handles UniCode/Single Byte Ascii strings for your or something - just a guess...I JUST woke up because my cat decided to start yelping for no reason but to be pet... I love cats but not this moment.....grumbling

tempicek
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: Prague
Posted: 16th Jan 2008 14:58
Jason, did you get it work? You should be able to generate the export file (.def) with the library in your IDE I hope (FreePascal?), where you can find the export name of the function you want to load. If not, you can even open the library in Visual Studio.

And yes, TEXT() is a macro which makes string constants UNICODE if your project is compiled so, or does nothing if you don't use UNICODE. Once it used to be a good habit to use TEXT and T macros everywhere, so it is easy to port/build the application for UNICODE platform/target. Then it became an outdated bad habit since it's necessity to build UNICODE application these days, really. Unfortunately, this amazing GDK library faild again not providing UNICODE text functions. Nice! So I guess it's good idea again to use these macros to be prepared to the D day when GDK comes as UNICODE library.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 16th Jan 2008 15:38
Not yet. FreePascal has a ALIAS and cdecl feature to make sure stack handled right and namemangling off. No I didn't get it to work... I THINK it may be a FPC v2 thing - according to LONG research online

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 16th Jan 2008 16:25
GOT IT!

FreePascal Sample DLL



C++ code to run it



YEAH!!!!! The Crowd Goes Wild..... Thanx you Guys

tempicek
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: Prague
Posted: 16th Jan 2008 22:56
You would save yourself a lot of time if you would check the DLL content in first place (if you don't have any viewer, I'm pretty sure MSVS can show it)
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 16th Jan 2008 23:48
I did... the name was visible in the obj dump - but not the dll viewer - so I kept looking online for samples of freepascal dll's (never did one) then I saw one that actually have full code - and near the bottom - the exports keyword

tempicek
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: Prague
Posted: 17th Jan 2008 00:05
Oh, I see. I wouldn't know that either, I haven't been coding in pascal for ages.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 17th Jan 2008 00:55
Quote: "Oh, I see. I wouldn't know that either, I haven't been coding in pascal for ages. "


Well, I'm a fan - you should give it a try! Its come a LONG way! Platform independant, fast, better suited for parallel processing because of how its structured under the hood.... and with it I wrote the fastest webserver I've seen to date!

tempicek
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: Prague
Posted: 17th Jan 2008 10:24
No, thank you I found the syntax too talkative and less flexible. C++ always suits me and when not, C# is my way. Also, as far as I know, there's no IDE for Pascal or Delphi on windows platform that could stand against VS, am I wrong?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 17th Jan 2008 13:16
Well - FreePAscal is open source - so it doenst' have the $$ behind it - but the Lazarus editor has a form of intellisense .. like vb6 has. It write a lot of code for you as well... and its platform independant... its has its pros: platofrm independance, works with multiple "gui" interface... from web pages to desktop etc... it has smartlinking... its faster than .net and microsoft c++ and gcc ... at least the core language compiles a heck of alot smaller and runs faster... Its definately made a mark.

tempicek
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: Prague
Posted: 17th Jan 2008 17:29
Quote: "FreePAscal is open source - so it doenst' have the $$ behind it"


Well, you don't have to spend a single dollar if you want to code in MSVS express version and it's still a hell good IDE for individual or small teams.

Quote: "its faster than .net and microsoft c++ and gcc ... at least the core language compiles a heck of alot smaller and runs faster... Its definately made a mark"


That sounds interesting, I would like to make some experiments regarding speed. Whould you mind to help me with that (providing some simple, but not trivial code in pascal)? Like big matrix multiplication, string handling, object/memory allocation, etc?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Jan 2008 14:21
Well... I don't mind putting my money where my mouth is but I'm on vaca and I'm running out of coding time for my project - it would be worth your while to investigate I promise. also, just download it and look at the samples. I say first FPC - the core language, it has a command line compiler you can set up with editor of choice. Then you can see some sample source too - as all source provided for those. Source for lang itself is available also.

Lazarus is the one with drag-drop IDE. It comes with its own copy of compiler as its a complete package and integrated tightly to the version that comes with it.

1: Compiler is fast

2: Generated Code speed is usually as fast or faster (not hands down everytime because C++ does somestuff like direct mem copy/cut the same way when brought to assembly level.... because memcopy/cut etc boild down to CPU instructions etc.

3: Smart Linking allows you to take a 200,000 Source file for a UNIT you might include in your program, and the compiler will only "bring over to your EXE" the stuff you actually reference directly or indirectly .... You might have a HUGE lib and use one routine like "TRIM" and the compiler will just bring in the "TRIM" code. This allows for tiny exe!

Note: Using the "CLASSES" unit which brings in the OOP base code that the "RTL" (similiar to MFC) adds a WHALLOP to EXE... like 60k I think.. but that gets reused so its a small price to pay for gaining contrstructor/destructor code.

4: Lazarus has platform independant GUI for windows, Linux, Max, and variations of these... There was dev going on for Web Widgets as well... don't know status. Lazarus site was down last I checked. I think they moved it to a Wiki Page or something.

Start here:http://www.freepascal.org/advantage.var

tempicek
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: Prague
Posted: 18th Jan 2008 15:42
Quote: "3: Smart Linking allows you to take a 200,000 Source file for a UNIT you might include in your program, and the compiler will only "bring over to your EXE" the stuff you actually reference directly or indirectly .... You might have a HUGE lib and use one routine like "TRIM" and the compiler will just bring in the "TRIM" code. This allows for tiny exe!"


That goes without saying for every language and linker I know of.

And regarding the code speed, see this: http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=all
doesn't look faster to me it would be nice if they brought the same benchmark to Windows platform though, since this does not tell much for Win programs

Case closed

Login to post a reply

Server time is: 2024-09-29 09:17:09
Your offset time is: 2024-09-29 09:17:09