Setting up program Global values from DLL

Just starting out? Need help? Post your questions and find answers here.
Chirantha
User
User
Posts: 54
Joined: Sat Jul 16, 2005 7:22 pm

Setting up program Global values from DLL

Post by Chirantha »

Hi,

I need to define some global values from the DLL. But its not working

The code in program

Code: Select all

dllh=OpenLibrary(#PB_Any,"firstdll.dll")
Debug dllh
Debug CallFunction(dllh,"SetGlobalval")

MessageRequester("Test",DLLreturn$)
End
The code in DLL

Code: Select all

ProcedureDLL SetGlobalval()
  Global DLLreturn$
  DLLreturn$="I set the value!"
  ProcedureReturn 1
EndProcedure
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

a Global in a DLL is only global within the DLL.

you should not need to define a Global inside a DLL to be accessable in the calling program.
if you think you need it, your concept is wrong.
oh... and have a nice day.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You can of course return the address of the global variable and then use one of the Peek functions or even use a pointer to get a hold of the data etc.

As Kaeru says though, returning a global from a dll is not really a great idea! :wink:
I may look like a mule, but I'm not a complete ass.
Post Reply