Login Page - Create Account

Support Board


Date/Time: Sat, 23 Nov 2024 08:29:22 +0000



Post From: ACSIL - DLL cannot be opened for writing

[2019-01-05 13:37:45]
PeterSt - Posts: 36
All,

Assumed this is the last thread about the unloading "issue", here a small addition from a newbie to Sierra, meant for other newbees.

So our DLL gets uploaded to "something". There it is executed once we denote it so with "Add Custom Study". Now it runs.
This fact cause the inability to not being able to compile it with an external tool (like Visual Studio). All right.
In the posts above has been explained how to circumvent that situation. In general this comes down to :
A. Cause the "something" (say Sierra Kernel) to unload the DLL;
B. Compile your latest version of it;
C. Load it back.

My post (and hopefully improvement on it) is about C. I mean, I don't see the procedure for it, and without really knowing how to do it, you could lose ages of time because of too many steps required. However, first off a possible unseen issue :

(I'll take the PowerShell commands for the examples)

$send = [text.encoding]::ascii.getbytes("RELEASE_ALL_DLLS")
[void] $client.send($send, $send.length, $peerIP, $peerPort)

When this part is executed, the DLL/Study will not load back in full. Take the "Draw To Chart Example" to show this, where the colored square in the top left corner will not show any more, after the above has been done and the Study has been reloaded. However, the text "Draw To Chart Example" which shows towards the bottom, is shown all right.
I could find now other way than again restarting Sierra. And this can't be the idea of it.

The (somehow) proposed code like this :

$send = [text.encoding]::ascii.getbytes("RELEASE_ALL_DLLS"
[void] $client.send($send, $send.length, $peerIP, $peerPort)
$send = [text.encoding]::ascii.getbytes("ALLOW_LOAD_ALL_DLLS"))
[void] $client.send($send, $send.length, $peerIP, $peerPort)

doesn't help a bit for the freeing, because right away it is loaded back and you again can not compile (link, actually) it.

In full, this is the code which works :

$client = new-object net.sockets.udpclient(0)

$peerIP = "127.0.0.1"
$peerPort = "22904"

$send = [text.encoding]::ascii.getbytes("RELEASE_ALL_DLLS")
[void] $client.send($send, $send.length, $peerIP, $peerPort)

#The DLL is now freed. Recompile/Link your DLL. Below we will be waiting for a keystroke from you.

write-host "Press any key to continue..."
[void][System.Console]::ReadKey($true)

#Compile done ? then load back all the custom DLL's :

$send = [text.encoding]::ascii.getbytes("ALLOW_LOAD_ALL_DLLS")
[void] $client.send($send, $send.length, $peerIP, $peerPort)

$client.close()

To me it did not seem obvious, but when doing it like this, you won't need to touch anything in Sierra, because your Custom Study well automatically reload as long as it is in your list of Studies for the Chart(s but I tested with one only).

What I did lastly, was obtaining each half of the powershell code in the Pre-Build Event of the Project Properties in Visual Studio and in the Post-Build Event, respectively (I use VS2010). This line goes in the Pre-Build Event :

powershell -executionPolicy bypass -file "c:\ClearDLL.ps1"

(the ClearDLL.ps1 file put in the root of C:\ but it can be anywhere)

which contains this code :

$client = new-object net.sockets.udpclient(0)

$peerIP = "127.0.0.1"
$peerPort = "22904"

$send = [text.encoding]::ascii.getbytes("RELEASE_ALL_DLLS")
[void] $client.send($send, $send.length, $peerIP, $peerPort)

$client.close()

#Repeat the above in this same .ps1 for each Sierra host('sIP address) (untested)

And this line goes in the Post-Build event :

powershell -executionPolicy bypass -file "c:\LoadDLL.ps1"

which contains this code :

$client = new-object net.sockets.udpclient(0)

$peerIP = "127.0.0.1"
$peerPort = "22904"

$send = [text.encoding]::ascii.getbytes("ALLOW_LOAD_ALL_DLLS")
[void] $client.send($send, $send.length, $peerIP, $peerPort)

$client.close()

#Repeat the above in this same .ps1 for each Sierra host('sIP address) (untested)

Notice that the Pre-Build Event was used instead of the Pre-Link Event so the Sierra host has somewhat more time to free the DLL's. If this time appears to be insufficient, some sleep timer has to be build in the ClearDLL.Ps1 (at the end of it).

All we now need to do is recompile/link and instantly our current studies come alive (or stay away when Build errors occurred).
A note of caution : The instantly coming alive is indeed so. And in a live trading environment this could be dangerous, but alas.

If this wasn't known already, I hope this helps someone.
Peter
imageSierra04a.png / V - Attached On 2019-01-05 13:26:13 UTC - Size: 24.41 KB - 510 views
Attachment Deleted.
imageSierra04b.png / V - Attached On 2019-01-05 13:36:14 UTC - Size: 23.28 KB - 441 views