PureBasic Simple DLL - MC Crashes on Exit  [SOLVED]

Questions about MultiCharts and user contributed studies.
Terabyte
Posts: 8
Joined: 06 Jun 2012

PureBasic Simple DLL - MC Crashes on Exit  [SOLVED]

Postby Terabyte » 03 Feb 2014

Hello Experts,

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;
PureBasic 64 DLL Code and Compiled DLL attached:

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
Attachments
dllsample2_64.dll
(7.5 KiB) Downloaded 394 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: PureBasic Simple DLL - MC Crashes on Exit

Postby Henry MultiСharts » 04 Feb 2014

Hello Terabyte,

We have studied your case on our end. A DLL compiled with Visual Studio does not cause any issues, while the Dll compiled with PureBasic application causes exceptions.

Please compile your Dll with Visual Studio or contact PureBasic directly regarding this issue.

Terabyte
Posts: 8
Joined: 06 Jun 2012

Re: PureBasic Simple DLL - MC Crashes on Exit

Postby Terabyte » 04 Feb 2014

Yes, I concur. I did the same test with same results as you.

It seems that PureBasic is simply not fully compatible in writing DLLs. I have had other problems with PureBasic incompatibilities in the past as well. So I will be switching to Microsoft Visual Studio C++.

Thank you for your rapid response.


Return to “MultiCharts”