Dll call another DLL

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5522
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Dll call another DLL

Post by Kwai chang caine »

Hello at all

I have two question to ask :

1/ What is the best way to shared an array in a exe and two DLL call by this exe.
I want the array is GLOBAL in the three code.

2/ My first DLL call the second DLL.
The first DLL need already the procedure of the second DLL.

Then i talk to me : "Is it no more better to open the second DLL only one time, else to open and close it, in every procedures ???" :roll:
Then i think to open the second DLL in the AttachProcess procedure of the first and close it in the DetachProcess of the first DLL.
Like that, only one open, for all the First DLL :D

But, i believe that's not works :cry:
Is it normal ???

Thanks for your precious help
Good day
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5522
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

After more try, i see that open a library in AttachProcess procedure of another is works :D
But i don't know if is a good method ? :roll:
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5522
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Nobody can help me ???? :cry:

"I'm poor lonesome cowboy......."
Image
ImageThe happiness is a road...
Not a destination
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Shared memory using a file map is the easiest method. You can also try streaming your array using a pipe.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Here a code for shared memory and example:
shared_memory.pbi

Code: Select all

Define HandleMap.l

Procedure CreateSharedMemory(Name.s, Size.l)
  Shared HandleMap
  HandleMap = CreateFileMapping_(#INVALID_HANDLE_VALUE, 0, #PAGE_READWRITE|#SEC_COMMIT|#SEC_NOCACHE, 0, Size, @Name)
  If HandleMap
    ProcedureReturn MapViewOfFile_(HandleMap, #FILE_MAP_ALL_ACCESS, 0, 0, 0)
  EndIf
EndProcedure

Procedure OpenSharedMemory(Name.s)
  Shared HandleMap
  HandleMap = OpenFileMapping_(#FILE_MAP_ALL_ACCESS, 0, @Name)
  If HandleMap
    ProcedureReturn MapViewOfFile_(HandleMap, #FILE_MAP_ALL_ACCESS, 0, 0, 0)
  EndIf
EndProcedure

Procedure CloseSharedMemory(MemoryAddress.l)
  Shared HandleMap
  UnmapViewOfFile_(MemoryAddress)
  CloseHandle_(HandleMap)
EndProcedure
example client.pb

Code: Select all

EnableExplicit

XIncludeFile "shared_memory.pbi"

Structure myMem
  text.s{23}
  quit.l
EndStructure

; test
Define *mem.myMem = OpenSharedMemory("MyMemory")

If *mem
  MessageRequester("MyMemory", *mem\text)
  
  *mem\quit = #True
  CloseSharedMemory(*mem)
EndIf
example server.pb

Code: Select all

EnableExplicit

XIncludeFile "shared_memory.pbi"

Structure myMem
  text.s{23}
  quit.l
EndStructure

; test
Define *mem.myMem = CreateSharedMemory("MyMemory", SizeOf(myMem))

If *mem
  *mem\text = "Feel the ..Pure.. Power"
  
  While *mem\quit = #False
    Delay(100)
  Wend
  CloseSharedMemory(*mem)
  MessageRequester("MyMemory", "Client hat quit gesetzt")
EndIf
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5522
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Yes this code works fine 8)
Thanks for your answer :D

And about the procedure AttachProcess ??
Do you see a problem to open the second DLL in the AttachProcess procedure of the first ?
ImageThe happiness is a road...
Not a destination
knut1
New User
New User
Posts: 8
Joined: Fri Apr 03, 2009 7:22 pm

Post by knut1 »

this problem i have too.
any ideas about the attachprocess....?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

@ts-soft: Nice clean example, thanks for sharing.
BERESHEIT
Post Reply