Rank: Member
Groups: Registered, Registered Users Joined: 7/10/2006(UTC) Posts: 25
|
Here's a question that may have to be answered by an Equis programmer (do they visit this forum?).
I'm trying to add a feature to Trade System Designer that will allow a System to access the data from a different security while it's running. For instance, you can have the "Euro 30 minute" security get the data from the "Euro Daily" security to do things like moving averages and such.
This works fine in my stand-alone application, using MSFL, but when I run the same code but use MSK to access the data instead, it crashes.
The first thing that comes to mind is a threading issue. Perhaps the data in one security is getting changed after the second security has started to access it? If this is the case, is there a way around this? Perhaps using some mutexes (that would of course already have to exist in MetaStock)?
Has this been done before by anyone else? Can it be done?
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/28/2005(UTC) Posts: 276 Location: Salt Lake City, UT
|
Yes, some of us visit the forum.
My first guess might be that your copy of MetaStock and the MSFL from your MetaStock Developer's Kit are different versions. One version of MSFL cannot access a folder locked by another version of the MSFL. Your stand alone app is probably the only version of MSFL running on that folder at the time. Make sure your MetaStock and MDK are the same version if they're going to be accessing the same folder at the same time.
|
|
|
|
Rank: Member
Groups: Registered, Registered Users Joined: 7/10/2006(UTC) Posts: 25
|
Does that apply to the MSK as well? My standalone app, using MSFL does not crash (and like you say, no other app is accessing the data). It's when I use my compiled DLL (using MSK) inside of MetaStock that crashes. The DLL does not use MSFL (it's not even linked in).
I am using MetaStock Pro FX version 9.2 and version 8.0 of the MDK.
Thanks
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/28/2005(UTC) Posts: 276 Location: Salt Lake City, UT
|
I don't know what you mean by MSK. I had been guessing that meant MetaStock.
Yes, if MetaStock 9.2 is accessing the folder, MSFL from MDK will not be able to (and vice versa).
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/28/2005(UTC) Posts: 276 Location: Salt Lake City, UT
|
If your DLL isn't using MSFL, how is it trying to get data from another security?
|
|
|
|
Rank: Member
Groups: Registered, Registered Users Joined: 7/10/2006(UTC) Posts: 25
|
Sorry, I guess I meant MSX. I got MSK from the subtitle of the forum, and I didn't verify that it was correct. I had to crack open the book to get the correct term. :)
I'm getting the data from one security to another using a common data structure in my DLL which has pointers to all the MSXDataRec structures for all the open securities.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/28/2005(UTC) Posts: 276 Location: Salt Lake City, UT
|
Ah, okay. That makes sense.
No, what I was saying wouldn't apply then. MetaStock's MSFL would be the only copy accessing folders. Your problem then would be how you go about knowing which structures are open and still valid. When MSFL (whether from MetaStock or MDK) is writing to a data file, it must lock it and make it so other instances of MSFL can't access it before it starts writing. You cannot have something reading at the same time as something else is writing. With MSX, you're being passed all the data that there was at the time your DLL was called. When the data is next updated, you'll be passed all that data again.
Someone on this forum has done something similar to this in the past, but they tried using MSFL. I don't recall if they were ever successfull.
|
|
|
|
Rank: Member
Groups: Registered, Registered Users Joined: 7/10/2006(UTC) Posts: 25
|
Do you know if the MSXDataRec structures internal to MetaStock get reallocated as time goes by? Or perhaps the pfValue arrays inside the MSXDataInfoRec structure do?
I can't think of another reason why this would cause a crash, other than the memory becoming invalid via a realloc of some sort. Every time Execute is called (an exported function in my DLL) I re-save the pointer to the MSXDataRec, but if it's getting invalidated in another thread, that would explain the crashes.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/28/2005(UTC) Posts: 276 Location: Salt Lake City, UT
|
The pointers to MSXDataRec are probably being deallocated at the end of the call to the MSX DLL, since there's no point to keep it around. It's not a threading issue. You're not supposed to be holding onto pointers, since they're not guaranteed to still be there in a different call.
You'd be better off saving the actual data you were passed instead of a reference to it. Then you could access that data as much as you like.
|
|
|
|
Rank: Member
Groups: Registered, Registered Users Joined: 7/10/2006(UTC) Posts: 25
|
That's what it's looking like I'm going to have to do. I was just hoping to avoid any unnecessary memcpys.
Thanks for your help, Branden.
|
|
|
|
Users browsing this topic |
Guest (Hidden)
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.