Singleton pattern example - DLL - "Tag" property  [SOLVED]

Questions about MultiCharts and user contributed studies.
javamarket
Posts: 55
Joined: 10 Jul 2014
Has thanked: 10 times
Been thanked: 18 times

Singleton pattern example - DLL - "Tag" property

Postby javamarket » 13 Sep 2014

A bit of an advanced topic to be sure...

I was looking for some examples of using a recommended (and proven) coding technique to ensure that DLLs are thread safe and callable multiple times from PowerLanguage. Unfortunately the SDK that is referenced from TS is at best sparse. The last document provided (revision date: 9/30/11) indicates use of the InterfaceObject.Tag:
Tag: This property may be used to store or retrieve any
extra data for a particular need. Example: Store
pointer to customized data type objects.
The problem here is that Tag (at least in the version provided by PLKit.dll) is a 32bit int and I am concerned about casting 64bit address spaces and the resultant effects.

Is anyone using a singleton pattern and safely storing pointers to ensure single instances of objects that can provide a bit of a template?

javamarket
Posts: 55
Joined: 10 Jul 2014
Has thanked: 10 times
Been thanked: 18 times

Re: Singleton pattern example - DLL - "Tag" property

Postby javamarket » 14 Sep 2014

Just a follow-up note for anyone who happens to search this concept down.

I have moved to using the IEasyLanguageProperties Items | ItemsByInteger for my needs. As this stores a variant, there is no inbuilt cast available from a Class pointer so I am double casting:

Code: Select all

pELObj->Properties->ItemsByInteger[callerID] = (__int64)myClassPtr;

Code: Select all

myClassPtr= (MyClass*)(__int64)pELObj->Properties->ItemsByInteger[callerID];
where I am manually entering a unique int for callerID. This is working as expected and I believe resolves my concern of the Tag usage. It also allows me to call the DLL multiple times from within a function as I can manage the context with the callerID.

This does beg a question that would make life easier if it exists.
Is there a unique ID for a call to a PowerLanguage function that can be used in place of the callerID (origination agnostic) which I currently manage manually?

Dru
Posts: 107
Joined: 28 Aug 2007
Has thanked: 4 times
Been thanked: 171 times

Re: Singleton pattern example - DLL - "Tag" property  [SOLVED]

Postby Dru » 23 Sep 2014

Is there a unique ID for a call to a PowerLanguage function that can be used in place of the callerID (origination agnostic) which I currently manage manually?

Code: Select all

VARIANT IPowerLanguageObject.TagEx


Return to “MultiCharts”