I am using PureBasic x64 to create a very simple DLL for MC x64. It works fine until I close the Workspace, then it crashes MC. The same DLL works fine from Excel x64 and PureBasic claims it is also working fine for them. So I am stumped and hope you can help.
Here's what happens:
1. I open a MC64 chart and insert my study (see below)
2. The study produces the correct results. I can toggle the status multiple times with no problem.
3. I turn the study status OFF which I have confirmed unloads the DLL from memory.
4. Finally, I close the workspace and MC crashes with message "MultiCharts64 has stopped working. A problem caused the program to stop working correctly." VS debugger reports "Unhandled exception at 0x00000000025A2179 in MultiCharts64.exe: 0xC0000005: Access violation executing location 0x00000000025A2179."
I welcome your expertise in solving this mystery.
MC Study:
Code: Select all
DefineDLLFunc: "dllsample2_64.dll", long, "AddLong", long, long;
If Currentbar >= 10 then begin
Print( "- - - ",currentdate:0:0, ", ", currentTime:0:0, " - - -");
Value1 = AddLong(long(L),long(H));
Print("AddLong 5+7=12, Actual = ",L,", ",H,", ",value1);
End;
Code: Select all
EnableExplicit
; * * * Comment out this line and it works fine with no crash
; This is a thread based persistent variable. Every thread has its own.
Threaded MyDouble.d
;
; These 4 procedures are Windows specific
;
; This procedure is called once, when the program loads the library
; for the first time. All init stuffs can be done here (but not DirectX init)
;
ProcedureDLL AttachProcess(Instance)
EndProcedure
; Called when the program release (free) the DLL
;
ProcedureDLL DetachProcess(Instance)
EndProcedure
; Both are called when a thread in a program call or release (free) the DLL
;
ProcedureDLL AttachThread(Instance)
EndProcedure
ProcedureDLL DetachThread(Instance)
EndProcedure
;
; Real code start here..
;
ProcedureDLL.l AddLong(num1.l, num2.l)
Protected Mysum.l
Mysum = num1 + num2
ProcedureReturn Mysum
EndProcedure