Page 2 of 2
Re: Export functions in an EXE (just like a dll) - uses coffIT
Posted: Thu Feb 04, 2010 2:41 pm
by ts-soft
Make a doubleclick on "PB\v4.41\PureBasic.exe", close it and use coffit!
Greetings
Thomas
Re: Export functions in an EXE (just like a dll) - uses coffIT
Posted: Thu Feb 04, 2010 2:42 pm
by srod
Then coffIT is probably locating the 4.2 or 4.3 version of PB (the registry entries changed somewhere along the line - version 4 I think?)
Run the following program Kwai, it will tell you which version of PB coffIT is using.
Code: Select all
Procedure.s GetPBFolder(index=0)
Protected hKey1.l, Type.l, Res.l, Folder$, lpbData.l, cbData.l, PBRegKey.s
cbData = 1024 ;The PB entry is really quite long!
lpbData = AllocateMemory(cbData)
Folder$=""
hKey1=0
Type=0
Res=-1
If lpbData
Select OSVersion()
Case #PB_OS_Windows_95,#PB_OS_Windows_98,#PB_OS_Windows_ME
PBRegKey="Software\Classes\PureBasic.exe\shell\open\command"
Res=RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, PBRegKey, 0, #KEY_ALL_ACCESS, @hKey1)
Case #PB_OS_Windows_NT3_51,#PB_OS_Windows_NT_4,#PB_OS_Windows_2000,#PB_OS_Windows_Server_2003
PBRegKey="Applications\PureBasic.exe\shell\open\command"
Res=RegOpenKeyEx_(#HKEY_CLASSES_ROOT, PBRegKey, 0, #KEY_ALL_ACCESS, @hKey1)
Case #PB_OS_Windows_XP, #PB_OS_Windows_Vista,#PB_OS_Windows_Server_2008,#PB_OS_Windows_Future
PBRegKey="Software\Classes\PureBasic.exe\shell\open\command"
Res=RegOpenKeyEx_(#HKEY_CURRENT_USER, PBRegKey, 0, #KEY_ALL_ACCESS , @hKey1)
EndSelect
If Res = #ERROR_SUCCESS And hKey1
If RegQueryValueEx_(hKey1, "", 0, @Type, lpbData, @cbData)=#ERROR_SUCCESS
Folder$ = PeekS(lpbData)
Select index
Case 0
Folder$ = GetPathPart(StringField(Folder$,2,Chr(34)))
Case 1
Folder$ = StringField(Folder$,6,Chr(34))
Case 2
Folder$ = StringField(Folder$,8,Chr(34))
Case 3
Folder$ = StringField(Folder$,10,Chr(34))
EndSelect
EndIf
RegCloseKey_(hKey1)
EndIf
FreeMemory(lpbData)
EndIf
ProcedureReturn Folder$
EndProcedure
Debug GetPBFolder()
Re: Export functions in an EXE (just like a dll) - uses coffIT
Posted: Thu Feb 04, 2010 2:48 pm
by Kwai chang caine
Hello MASTER TsSoFT
The PB 4.41 run in the same time, and it's the one i use now
Thanks SROD...your IDIOT is always IDIOT
He push the F5 key of his keyboard to have your answer...and he don't see you have already answered but in the second page

And he wait ...wait...and cry alone in his desktop
And another little light in his brain...i see the litle "2" ..and i'm here with you two...on the second page
So i have tried the code
You have again right
Code: Select all
E:\Donnees\User\MES DOCUMENTS\Travail\[[PureBasic]]\v3.94\
Re: Export functions in an EXE (just like a dll) - uses coffIT
Posted: Thu Feb 04, 2010 2:56 pm
by srod
Okay Kwai, I will add a facility for manually setting the PB installation folder to over-ride that located by coffIT itself.
Re: Export functions in an EXE (just like a dll) - uses coffIT
Posted: Thu Feb 04, 2010 2:59 pm
by Kwai chang caine
So your servant again surprising you...
He read with his eyes the bad REG KEY and found it
I have modify it, with big kick ass....
And you don't believe me ....that's works now...no error
I continue to try your tips

Re: Export functions in an EXE (just like a dll) - uses coffIT
Posted: Thu Feb 04, 2010 3:00 pm
by srod
Kwaï chang caïne wrote:So your servant again surprising you...
He read with his eyes the bad REG KEY and found it
I have modify it, with big kick ass....
And you don't believe me ....that's works now...no error
I continue to try your tips

That's one way around the problem for sure.

Re: Export functions in an EXE (just like a dll) - uses coffIT
Posted: Thu Feb 04, 2010 3:14 pm
by Kwai chang caine
I have finish to try your splendid example.
That's works ..
You have take the time to good explain, slowly, and preciously...
And IDIOTMAN have not understand, why it's interesting to convert an EXE for using it like a DLL ??? :roll:
Never mind...don't try to explain to me...because it's already difficult for me to understand in french.
So in english.. it's more difficult..and furthermore it's certainly an use for the MASTER :roll:
At my advice..it's again too difficult for my level
Perhaps i understand better a day, when i'm behind a problem and you say to me : "Try my example

"
Again thanks for your kindness

Re: Export functions in an EXE (just like a dll) - uses coffIT
Posted: Thu Feb 04, 2010 3:33 pm
by srod
Well it just means that your EXE can have two uses; first as a standalone program and second as a shared library.
I admit that loading an EXE as if it were a dll is probably of little real use because ordinarily you would be better off siphoning the shared functions into a separate dll anyhow which would be more efficient.
However, that is not to say that this 'dual use' cannot have its uses. For example, you can effectively have an option for the exe to run within the same process as another by simply invoking an appropriate exported function in the exe. Makes it relatively easy to share data between the two programs that way.
I am sure there are many additional reasons for wishing to export EXE functions as well.

Re: Export functions in an EXE (just like a dll) - uses coffIT
Posted: Thu Feb 04, 2010 3:49 pm
by Kwai chang caine
Thanks for your explanation.
I'm again too small to use your tips..i have already enough difficulty to use a code when it is not compiled...
Then when it's compiled...
Before it's clear in my litle head...an EXE is alone (A little bit like me with my head)
And A dll is for an EXE...i have print this in my brain
If now you divert to convert DLL in EXE and EXE in DLL....i believe that i begin to be mad
It's a pity, you are not in the heaven...because i'm sure you can with your giant knowledge, modify man in women...
Like this ...we have numerous girls computing in this forum
Too strong my master....too strong !!!
I return to your and Netmaestro code for detecting Mouse ID...because it's already more difficult to me to modify it

Re: Export functions in an EXE (just like a dll) - uses coffIT
Posted: Fri Feb 05, 2010 8:06 am
by idle
thanks Srod, good to know that we can export functions without to much sweat.
Re: Export functions in an EXE (just like a dll) - uses coffIT
Posted: Sun Feb 14, 2010 2:25 am
by srod
14th Feb 2010.
The linker file in the relevant posting above has been adjusted to include the line :
This option forces the linker to add a relocation .reloc section to the executable. Without this, the Windows loader will not be able to relocate the exe if required.
My thanks to Mistrel for the heads up here.
Re: Export functions in an EXE (just like a dll) - uses coff
Posted: Tue Dec 07, 2010 10:19 am
by dige
fix for win7:
Code: Select all
; Line 17
Case #PB_OS_Windows_XP To #PB_OS_Windows_Future
Re: Export functions in an EXE (just like a dll) - uses coff
Posted: Sun Dec 26, 2010 1:05 pm
by Seldon
Thank you for this trick ! It does work here ! Though I've found a problem I don't know if it can be solved. My exported EXE function is like this:
Code: Select all
Structure mystruct
a.s
b.s
EndStructure
ProcedureDLL ModifyList(*element.mystruct)
*element\a="xxx"
*element\b="yyy"
EndProcedure
I make all the procedure with coffIT and I have a file called 'prova2.exe' .
And this is the caller program:
Code: Select all
Structure mystruct
a.s
b.s
EndStructure
Prototype ProtoModifyList(*element.mystruct)
Define *p
Define i
Define ModifyList
NewList mylist.mystruct()
If OpenLibrary(0,"prova2.exe")
ModifyList.ProtoModifyList=GetFunction(0,"ModifyList")
EndIf
AddElement(mylist())
mylist()\a="ciao"
mylist()\b="mondo"
AddElement(mylist())
mylist()\a="ciao1"
mylist()\b="mondo1"
AddElement(mylist())
mylist()\a="ciao2"
mylist()\b="mondo2"
ForEach mylist()
*p=mylist()
If i=1
ModifyList(*p)
EndIf
Debug mylist()\a
Debug mylist()\b
Debug ""
i+1
Next
I get a 'memory write error' when calling the function. That doesn't happen if I use a normal DLL. I've also tried to include the complete PB wrapper, not only the exported object file.
Thanks in advance for any hints.
Re: Export functions in an EXE (just like a dll) - uses coff
Posted: Sun Dec 26, 2010 1:31 pm
by Seldon
OK, I made further tests and I've found that if I don't use strings, it works :
Code: Select all
Structure mystruct
a.i
b.i
EndStructure
ProcedureDLL ModifyList(*element.mystruct)
*element\a=30
*element\b=90
EndProcedure
But what if I need strings ? I'll make other tests.
Re: Export functions in an EXE (just like a dll) - uses coff
Posted: Mon Jan 24, 2011 12:23 pm
by mback2k
Would it be possible to use coffIT to automatically create debug symbols for all procedures in an executable?
That would be really great to debug Windows services and programs using generic debugging tools.
Corresponding feature request:
http://forum.purebasic.com/english/view ... 91&start=0