It is currently Mon May 20, 2013 9:15 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: how to DIY the userLib structures and Variable
PostPosted: Wed Jan 09, 2013 4:24 pm 
Offline
User
User

Joined: Sat Sep 03, 2011 5:28 am
Posts: 27
As we see,in PB5.00,we can use structure point rect et.directly in our codes.
So,Can we make our personal user structures for direct use like point rect?
could somebody give me a hand?

another. how to declare Variables in a dll file While can be used Overall situation in the dll(between procedures)?
and how to declare Variables in a dll file While can be used Overall situation in the codes that called the dll?

sorry for my poor english.


Top
 Profile  
 
 Post subject: Re: how to DIY the userLib structures and Variable
PostPosted: Wed Jan 09, 2013 6:40 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Feb 17, 2010 12:00 am
Posts: 972
Location: Anderson Island, WA
You can create structures, see "Structure"; to create a shared variable between procedures w/in a dll -- create them as global vars (it's documented). NOTE: that if the application unloads the dll between calls, that variable will be reset.


Top
 Profile  
 
 Post subject: Re: how to DIY the userLib structures and Variable
PostPosted: Fri Jan 11, 2013 6:29 am 
Offline
User
User

Joined: Sat Sep 03, 2011 5:28 am
Posts: 27
jassing wrote:
You can create structures, see "Structure"; to create a shared variable between procedures w/in a dll -- create them as global vars (it's documented). NOTE: that if the application unloads the dll between calls, that variable will be reset.

thanks.
I also want to know whether there is a kind of variable that declarate in a dll and use it in the codes call it.
example:
Code:
;file.dll
;declarate kk.s


Code:
;include file.dll
debug kk ;I want here we can get the kk's content


Top
 Profile  
 
 Post subject: Re: how to DIY the userLib structures and Variable
PostPosted: Fri Jan 11, 2013 7:25 am 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 6465
Couple different ways. Here I'm declaring a global var in a dll and accessing it in two different ways: (1) passing its address in an Init() procedure, after which the var will be accessible via PeekI() and (2) creating a function to return the var, which can be called any time you want the var's value.
Code:
; DLL code:

ProcedureDLL AttachProcess(instance)
 Global this.i = 123
EndProcedure

ProcedureDLL Init()
  ProcedureReturn @this
EndProcedure

ProcedureDLL GetThis()
  ProcedureReturn this
EndProcedure

Code:
; Calling code
Prototype Init()
Prototype GetThis()
OpenLibrary(0, "c:\test.dll")
Init.Init = GetFunction(0, "Init")
Getthis.Getthis = GetFunction(0, "GetThis")
*ptr_i = Init()
Debug PeekI(*ptr_i)*2
Debug GetThis()*2

I have the global declaration inside the AttachProcess function, but it doesn't need to be there. It can just be declared normally at the top of the code.

_________________
Veni, vidi, vici.


Top
 Profile  
 
 Post subject: Re: how to DIY the userLib structures and Variable
PostPosted: Thu Jan 17, 2013 3:08 am 
Offline
User
User

Joined: Sat Sep 03, 2011 5:28 am
Posts: 27
netmaestro wrote:
Couple different ways. Here I'm declaring a global var in a dll and accessing it in two different ways: (1) passing its address in an Init() procedure, after which the var will be accessible via PeekI() and (2) creating a function to return the var, which can be called any time you want the var's value.
Code:
; DLL code:

ProcedureDLL AttachProcess(instance)
 Global this.i = 123
EndProcedure

ProcedureDLL Init()
  ProcedureReturn @this
EndProcedure

ProcedureDLL GetThis()
  ProcedureReturn this
EndProcedure

Code:
; Calling code
Prototype Init()
Prototype GetThis()
OpenLibrary(0, "c:\test.dll")
Init.Init = GetFunction(0, "Init")
Getthis.Getthis = GetFunction(0, "GetThis")
*ptr_i = Init()
Debug PeekI(*ptr_i)*2
Debug GetThis()*2

I have the global declaration inside the AttachProcess function, but it doesn't need to be there. It can just be declared normally at the top of the code.

Thanks for you prefect reply!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye