Page 1 of 1

Dll call another DLL

Posted: Thu Aug 28, 2008 7:45 am
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

Posted: Thu Aug 28, 2008 10:12 am
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:

Posted: Sun Aug 31, 2008 8:25 pm
by Kwai chang caine
Nobody can help me ???? :cry:

"I'm poor lonesome cowboy......."
Image

Posted: Sun Aug 31, 2008 10:25 pm
by Mistrel
Shared memory using a file map is the easiest method. You can also try streaming your array using a pipe.

Posted: Sun Aug 31, 2008 10:32 pm
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

Posted: Tue Sep 02, 2008 10:51 am
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 ?

Posted: Thu Apr 09, 2009 10:07 am
by knut1
this problem i have too.
any ideas about the attachprocess....?

Posted: Thu Apr 09, 2009 2:59 pm
by netmaestro
@ts-soft: Nice clean example, thanks for sharing.