Lib2PBImport Version 1.2

Developed or developing a new product in PureBasic? Tell the world about it.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Lib2PBImport Version 1.2

Post by srod »

Dll :

Code: Select all

#ExampleStringToReturn$ = "Kwai you idiot!"

ProcedureDLL.i GetString(*buffer)
  If *buffer
    PokeS(*buffer, #ExampleStringToReturn$)
  EndIf
  ProcedureReturn Len(#ExampleStringToReturn$)
EndProcedure
Client :

Code: Select all

Import "GetString.lib"
  GetString(a.i=0) As "_GetString@4"
EndImport

;Get the required buffers size.
  numCharacters = GetString()

;Retrieve the string.
  a$ = Space(numCharacters)
  GetString(@a$)
  Debug a$
I may look like a mule, but I'm not a complete ass.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Lib2PBImport Version 1.2

Post by Kwai chang caine »

Yeeeaahhhh !!!!
I'm nearly also good that you, because i have immediately understand the first instruction :mrgreen:

Code: Select all

#ExampleStringToReturn$ = "Kwai you idiot!"
Thanks SROD for your great explanations and precious example 8)

I want to know again something about Import/EndImport.
At your advice, when i declare several functions into Import/EndImport like this

Code: Select all

Import
 FunctionA(x.s) As "_FunctionA@X"
 FunctionB(a) As "_FunctionB@X"
 FunctionC(a) As "_FunctionC@X"
EndImport
This three functions are all loaded at this instant, or she is loaded only if i call her ???? :roll:
ImageThe happiness is a road...
Not a destination
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Lib2PBImport Version 1.2

Post by srod »

Only if the PB compiler thinks you might call the function!

E.g. in the following, even though the test() procedure is never called, PB will still import the GetString() function becuase it appears within the test() procedure :

Code: Select all

Import "GetString.lib"
  GetString(a.i=0) As "_GetString@4"
EndImport

Procedure test()
  GetString()
EndProcedure
**EDIT : but even in cases when the GetString() stub is not loaded from the import library, the dll will nevertheless still be mapped into the processes virtual memory anyhow.
I may look like a mule, but I'm not a complete ass.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Lib2PBImport Version 1.2

Post by Kwai chang caine »

Very very thank you MASTER
Like usually, you have save your servant 8)

You are a real SRODO for the poor KCC :D

Image

A last question i think for today :oops:
Have you see a code, who scan a PB source file for create the import/endimport
Because, i have just find code for create import/endimport from LIB, or the freak code for create Userlib, but not a "simple" code for create the import/endimport from the PB source :(

The advantage, it's that in the source file, i know also the format of the parameter (String, integer) :wink:

I try to create this, but i have a problem with the includefile :?
Because sometime, i have write the path of the include with Constant like this :

Code: Select all

InludeFile #KCCPath + "KCC.pbi"
And only the compiler know the value of constant #KCCPath

Or perhaps have you a solution for ask to the compiler, all the line of the source code, includefile include ??? :D
I go to put this question in an other thread...perhaps somebody know a tips :roll:

Again thanks, i wish you a very good day 8)
ImageThe happiness is a road...
Not a destination
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Lib2PBImport Version 1.2

Post by srod »

Only you can know what .libs you wish to import! No amount of scanning through a PB source file will reveal which functions are supposed to exist in a given .lib/dll etc. If you are looking for a tool to adjust the funtion protoptypes as listed in the Import/EndImport section then, well, this is a little backward. The compiler takes the prototype from this section and not from function calls! Take my advice and don't bother chasing such a tool. Use ts-soft's tool instead, it is very simple and very useful. You're not going to do any better than using this tool.
I may look like a mule, but I'm not a complete ass.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Lib2PBImport Version 1.2

Post by Kwai chang caine »

Oh i don't want make better that the tools of TS-Soft :oops:

But i have thinking, just find the word "ProcedureDLL" in the sentence ProcedureDLL KccFunction(a.s), and write simply the text:

Code: Select all

Import
 KccFunction(a.s) As "_KccFunctioni@4"
EndImport
And add after the lines that you give to me above, for return the string, if obviously the return is string :mrgreen:
With the LIB you say to me it's impossible to know if the parameter is string...but with the source code..it's easy :wink:

Like this :

Code: Select all

Import
 KccFunction(a.s) As "_KccFunctioni@4"
EndImport

ProcedureDLL.s StringKcc()
 numCharacters = KccFunction()
 a$ = Space(numCharacters)
 KccFunction(@a$)
 ProcedureReturn a$
EndProcedure 

Debug StringKccFunction()
And put all of this in an Includefile "PBI" :D
ImageThe happiness is a road...
Not a destination
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Lib2PBImport Version 1.2

Post by srod »

Why???

It takes but a few minutes to create an Import/EndImport section as it is; why waste your time when you can be getting on with the main business of coding instead?
I may look like a mule, but I'm not a complete ass.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Lib2PBImport Version 1.2

Post by Kwai chang caine »

Yes, the code of TS-SOFT is top
But he don't see the type of parameter (String, Integer) like you have say to me
Furthermore, i have hundred procedure in my DLL, and create news all the day like you all.
Much of my procedures, return string, so i'm forced to create this code for each of string procedure import:

Code: Select all

ProcedureDLL.s FunctionKcc1()
numCharacters = KccFunction1()
a$ = Space(numCharacters)
KccFunction1(@a$)
ProcedureReturn a$
EndProcedure 

ProcedureDLL.s FunctionKcc2()
numCharacters = KccFunction2()
a$ = Space(numCharacters)
KccFunction2(@a$)
ProcedureReturn a$
EndProcedure 

etc ....
...
...
...

This is a long job, to modify the code of TS-SOFT and create a procedure return string for each return :(

It's a pity, that FRED can't create a function to call different procedure by name :(

Code: Select all

CallFunctionName("FunctionKcc1")
CallFunctionName("FunctionKcc2")
Because with this, only one procedure is need, to all my return procedure string :D
And in this case, you are very right to say it's not interesting to create a code for just modify TS-SOFT code return :wink:

I have just thinking that, if i have the list of all the lines of code.
I can find the word "ProcedureDLL" , find if the parameter is string, integer, etc ...
And also create the procedure return string, that you have give to me above, in one click for hundred procedure :D

But if nobody have a tips for list all the lines of a source code.....it's impossible to create what i have thinking :(
Since a long time ago FLAITH create a counter of lines "PBLC" :D
But he promise to me perhaps a day, he modify his code for include Constant, and also return full lines :D
http://www.purebasic.fr/english/viewtopic.php?p=274560

I can create all what i want, i have just the problem with the CONSTANT in a PB RES :?
How can i ask to PB the value of a CONSTANT in live mode ???
In fact it's only my problem for finish this code :(

It's the reason why, i say , that only the compiler know all the line that it compile
Because just before compiling, it read this line i suppose :roll:
And if it's possible to ask to it, to write the line in log file...it's win !!! :D
I'm sure not missing lines of code....in any file PBI
And it's easy after to create full Import/EndImport procedure and all the procedure return string :mrgreen:

But if it's impossible.....never mind...i put it back in my pants :( (French expression :wink: )
ImageThe happiness is a road...
Not a destination
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Lib2PBImport Version 1.2

Post by applePi »

this is a great utility, thank you,
i have posted before about a regular expression engine here http://www.purebasic.fr/english/viewtop ... ilit=deelx
and using this utility to do the *.PBI makes the main code shorter and more readable and makes the life easier
i have posted today the new code at the same link above with the DLL, Lib, *,pbi
the same appreciation about the PureDLLHelper.
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: Lib2PBImport Version 1.2

Post by Zebuddi123 »

@Thomas was just reading latest posts and read applePi`s post and downloaded this tool was having a quick look around and i have noticed that any .lib larger than 511kb loads but fails to display the gui. The app can been seen running in taskmanager, dont know if this is a bug or there is something that i have not understood (happens all the time :shock: )

Zebuddi. :D
malleo, caput, bang. Ego, comprehendunt in tempore
Post Reply