Login Page - Create Account

Support Board


Date/Time: Thu, 28 Mar 2024 19:24:11 +0000



[Programming Help] - help on some basics of calling external DLL

View Count: 2412

[2018-04-16 17:36:56]
Andy Sureway - Posts: 93
Good morning, can I get some help on loading an external DLL file?

I have been following the following instructions.
ACSIL Programming Concepts: Making Function Calls to External DLLs

My specific questions are:
which of the following is correct, if the external dll name is MathLibrary.dll?
LoadLibrary("MathLibrary.dll")
LoadLibrary("MathLibrary")
LoadLibrary(TEXT("MathLibrary.dll"))
LoadLibrary(TEXT("MathLibrary"))
Where should I put Math.dll? Under the Data directory or the ACS_Source directory?

I have searched the support board, and hasn't find a similar topic down to this basic level. Thanks a lot!
[2018-04-16 19:04:18]
Andy Sureway - Posts: 93
A related question is, is it possible to link with static .lib under Sierra Chart? If so, what are the steps? Thanks!
[2018-04-16 19:45:37]
Sierra Chart Engineering - Posts: 104368
Use this:
LoadLibrary("MathLibrary.dll")

You can put this either in the Sierra Chart main installation folder or into the Data subfolder assuming that is set as the current Data Files Folder.

A related question is, is it possible to link with static .lib under Sierra Chart? If so, what are the steps? Thanks!
Yes. If you are using the Remote Build command, then there is an edit box on the Build Advanced Custom Studies DLL window to specify additional compiler parameters.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2018-04-16 19:55:19
[2018-04-16 19:55:23]
Sierra Chart Engineering - Posts: 104368
The prior post has been updated.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2018-04-16 19:59:11]
Sierra Chart Engineering - Posts: 104368
Actually upon looking into the Additional Compiler Parameters setting, that is not currently implemented. It will be implemented in the next release. Apparently this is an issue which has arisen some time ago.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2018-04-16 21:40:38]
Andy Sureway - Posts: 93
Many thanks for your answers!
[2018-04-17 03:39:16]
Andy Sureway - Posts: 93
It looks like I need more of your help on this topic.

Basically, I just followed the DDL example in the following link.
https://www.codeguru.com/cpp/cpp/cpp_mfc/tutorials/article.php/c9855/DLL-Tutorial-For-Beginners.htm

I have made a go with Visual C++ 2017. And I modified the code for Sierra Charts slightly, and tried to put DLL_Tutorial.dll in the Data Subfolder or the main installation folder. No success at all. (The study always plots a value of 10, which is the value when the dll is not loaded successfully.)

Could you please take a look? Thanks a lot!

Both the cpp file and the dll files are uploaded her.
attachmentDLL_Tutorial.dll - Attached On 2018-04-17 03:38:20 UTC - Size: 44.5 KB - 323 views
attachmentApplication.cpp - Attached On 2018-04-17 03:38:34 UTC - Size: 2.44 KB - 316 views
Attachment Deleted.
[2018-04-17 03:52:40]
Andy Sureway - Posts: 93
Here is an updated cpp file which writes the failure messages to the log file, and also more compatible to SierraChart style.

Thanks!
Private File
[2018-04-17 03:53:45]
Andy Sureway - Posts: 93
BTW, I am on build 1727.
[2018-04-17 04:26:55]
Sierra Chart Engineering - Posts: 104368
What we see wrong is that this line:

HINSTANCE hInstLibrary = LoadLibrary("DLL_Tutorial.dll");

Needs to be contained within the study function itself. Not outside of it. Otherwise, we would not expect it to execute. Surprising you did not get a compiler error.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2018-04-17 04:27:35
[2018-04-17 05:03:31]
Andy Sureway - Posts: 93
Thanks a lot! I just corrected it with the latest version in the attachment. However, the dll file is still not loaded.
Date Time Of Last Edit: 2018-04-17 05:10:08
attachmentApplication.cpp - Attached On 2018-04-17 05:09:47 UTC - Size: 2.45 KB - 341 views
[2018-04-17 05:08:34]
Andy Sureway - Posts: 93
Also I notice that the Log messages are generated twice each time the study is added.

For example the attached figure showed the messages were repeated by 2 seconds apart.
imageScreen Shot 2018-04-16 at 10.06.28 PM.png / V - Attached On 2018-04-17 05:08:10 UTC - Size: 30.92 KB - 455 views
[2018-04-17 05:23:35]
Sierra Chart Engineering - Posts: 104368
You must look at the return error from LoadLibrary and see what the problem is. That is not something we can help with.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2018-04-17 05:59:55]
Andy Sureway - Posts: 93
Thanks a lot! I just got the error code, which is 193 (0xC1) %1 is not a valid Win32 application. Looks like that there is something wrong with the dll file.
[2018-04-17 06:19:45]
Sierra Chart Engineering - Posts: 104368
One thing to check is make sure that you are not using the 64-bit version of Sierra Chart but instead the 32-bit version.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2018-04-17 07:01:25]
Andy Sureway - Posts: 93
Thanks for your tip!

The Sierra Chart on my end is 64-bit version. Then I am wondering whether it was because I had wrong configuration for Visual Studio. I am very new to it. Just checked: the previous dll file was built for Win32. Should I change it to x64 or other configuration?

Also I am wondering whether the keyword --- extern "c" --- in the cpp file has any impact?

The following is the code for DLL_Tutorial.cpp. Thanks a lot!

#include <iostream>
#include "DLL_Tutorial.h"

#define DLL_EXPORT

extern "C"
{
DECLDIR int Add( int a, int b )
{
return( a + b );
}

DECLDIR void Function( void )
{
std::cout << "DLL Called!" << std::endl;
}
}
[2018-04-17 14:01:55]
Andy Sureway - Posts: 93
Another information is I am working on Mac via Parallels. Don't know whether this could be a root cause? Thanks!
[2018-04-17 15:00:09]
Andy Sureway - Posts: 93
I am going to follow the example shown here, and report the result later of the day.

https://www.sierrachart.com/index.php?page=doc/UsingVisualCPlusPlus.php
[2018-04-17 17:44:59]
Andy Sureway - Posts: 93
Just wanted to update that I had a go following the SierraChart's tutorial.

https://www.sierrachart.com/index.php?page=doc/UsingVisualCPlusPlus.php

Need to mention that the platform needs to be set as x64, otherwise SierraChart won't recognize the DLL file.
[2018-04-17 19:10:50]
Sierra Chart Engineering - Posts: 104368
You do need to compile the DLL as a 64-bit DLL when using the 64-bit version of Sierra Chart.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account