Calling DLL functions help.

Created at 08 Aug 2024, 21:35
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
RI

rick2010

Joined 08.08.2024

Calling DLL functions help.
08 Aug 2024, 21:35


Hi, I have a MT5 EA that calls a couple of DLL functions and I need to port this EA into I guess what is called a cBot for cTrader. Is it possible to call DLL functions from a cBot? Any limitations on calling DLL's that I should be aware of? TIA


@rick2010
Replies

PanagiotisCharalampous
09 Aug 2024, 06:17

Hi there,

cBots are based on .Net. Therefore you can only call dll files based on managed code. If your dll is based on managed code, you should be able to use it.

Best regards,

Panagiotis


@PanagiotisCharalampous

rick2010
10 Aug 2024, 15:42 ( Updated at: 11 Aug 2024, 07:12 )

RE: Calling DLL functions help.

PanagiotisCharalampous said: 

Hi there,

cBots are based on .Net. Therefore you can only call dll files based on managed code. If your dll is based on managed code, you should be able to use it.

Best regards,

Panagiotis

Thanks for the reply. I figured that was the case. I got a DLL written in managed C/C++. I need to be able to call this DLL from the cBot. I guess the only way to do that is to create a .Net DLL proxy that will call my C++ DLL?


@rick2010

PanagiotisCharalampous
12 Aug 2024, 04:58

RE: RE: Calling DLL functions help.

rick2010 said: 

PanagiotisCharalampous said: 

Hi there,

cBots are based on .Net. Therefore you can only call dll files based on managed code. If your dll is based on managed code, you should be able to use it.

Best regards,

Panagiotis

Thanks for the reply. I figured that was the case. I got a DLL written in managed C/C++. I need to be able to call this DLL from the cBot. I guess the only way to do that is to create a .Net DLL proxy that will call my C++ DLL?

Check the article below. It should help 

https://learn.microsoft.com/en-us/dotnet/framework/interop/consuming-unmanaged-dll-functions


@PanagiotisCharalampous

PanagiotisCharalampous
12 Aug 2024, 04:58

RE: RE: Calling DLL functions help.

rick2010 said: 

PanagiotisCharalampous said: 

Hi there,

cBots are based on .Net. Therefore you can only call dll files based on managed code. If your dll is based on managed code, you should be able to use it.

Best regards,

Panagiotis

Thanks for the reply. I figured that was the case. I got a DLL written in managed C/C++. I need to be able to call this DLL from the cBot. I guess the only way to do that is to create a .Net DLL proxy that will call my C++ DLL?

Check the article below. It should help 

https://learn.microsoft.com/en-us/dotnet/framework/interop/consuming-unmanaged-dll-functions


@PanagiotisCharalampous

rick2010
12 Aug 2024, 21:16 ( Updated at: 13 Aug 2024, 04:58 )

RE: RE: RE: Calling DLL functions help.

PanagiotisCharalampous said: 

rick2010 said: 

PanagiotisCharalampous said: 

Hi there,

cBots are based on .Net. Therefore you can only call dll files based on managed code. If your dll is based on managed code, you should be able to use it.

Best regards,

Panagiotis

Thanks for the reply. I figured that was the case. I got a DLL written in managed C/C++. I need to be able to call this DLL from the cBot. I guess the only way to do that is to create a .Net DLL proxy that will call my C++ DLL?

Check the article below. It should help 

https://learn.microsoft.com/en-us/dotnet/framework/interop/consuming-unmanaged-dll-functions

Thanks


@rick2010

rick2010
13 Aug 2024, 22:10 ( Updated at: 14 Aug 2024, 09:58 )

RE: RE: RE: RE: Calling DLL functions help.

rick2010 said: 

PanagiotisCharalampous said: 

rick2010 said: 

PanagiotisCharalampous said: 

Hi there,

cBots are based on .Net. Therefore you can only call dll files based on managed code. If your dll is based on managed code, you should be able to use it.

Best regards,

Panagiotis

Thanks for the reply. I figured that was the case. I got a DLL written in managed C/C++. I need to be able to call this DLL from the cBot. I guess the only way to do that is to create a .Net DLL proxy that will call my C++ DLL?

Check the article below. It should help 

https://learn.microsoft.com/en-us/dotnet/framework/interop/consuming-unmanaged-dll-functions

Thanks

I created a .NET DLL wrapper class that calls my unmanaged C++ DLL functions ok. I added the code below to the cBot and it compiles fine in cTrader but when I run the cBot it says it can't find the DLL even though the DLL is in the same directory?

    internal static class NativeMethods {
    
        [DllImport("Client.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern bool connClient(uint id, char[] username, char[] password);
    }

13/08/2024 22:06:42.127 | Info | CBot instance [Client_CBOT, EURUSD, h1] started.
13-08-2024 22:06:42.908 | Error | Crashed in OnStart with DllNotFoundException: Unable to load DLL 'Client.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)

Any ideas? Do I have to use the .NET DLL wrapper… doesn't make sense to do that when cBot is built in .NET?


@rick2010

PanagiotisCharalampous
14 Aug 2024, 10:13

RE: RE: RE: RE: RE: Calling DLL functions help.

rick2010 said: 

rick2010 said: 

PanagiotisCharalampous said: 

rick2010 said: 

PanagiotisCharalampous said: 

Hi there,

cBots are based on .Net. Therefore you can only call dll files based on managed code. If your dll is based on managed code, you should be able to use it.

Best regards,

Panagiotis

Thanks for the reply. I figured that was the case. I got a DLL written in managed C/C++. I need to be able to call this DLL from the cBot. I guess the only way to do that is to create a .Net DLL proxy that will call my C++ DLL?

Check the article below. It should help 

https://learn.microsoft.com/en-us/dotnet/framework/interop/consuming-unmanaged-dll-functions

Thanks

I created a .NET DLL wrapper class that calls my unmanaged C++ DLL functions ok. I added the code below to the cBot and it compiles fine in cTrader but when I run the cBot it says it can't find the DLL even though the DLL is in the same directory?

    internal static class NativeMethods {
    
        [DllImport("Client.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern bool connClient(uint id, char[] username, char[] password);
    }

13/08/2024 22:06:42.127 | Info | CBot instance [Client_CBOT, EURUSD, h1] started.
13-08-2024 22:06:42.908 | Error | Crashed in OnStart with DllNotFoundException: Unable to load DLL 'Client.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)

Any ideas? Do I have to use the .NET DLL wrapper… doesn't make sense to do that when cBot is built in .NET?

Make sure your dll is copied to the output directory. Check the Copy Local property and make sure is set to true

 


@PanagiotisCharalampous

rick2010
14 Aug 2024, 17:46 ( Updated at: 15 Aug 2024, 05:20 )

RE: RE: RE: RE: RE: RE: Calling DLL functions help.

PanagiotisCharalampous said: 

rick2010 said: 

rick2010 said: 

PanagiotisCharalampous said: 

rick2010 said: 

PanagiotisCharalampous said: 

Hi there,

cBots are based on .Net. Therefore you can only call dll files based on managed code. If your dll is based on managed code, you should be able to use it.

Best regards,

Panagiotis

Thanks for the reply. I figured that was the case. I got a DLL written in managed C/C++. I need to be able to call this DLL from the cBot. I guess the only way to do that is to create a .Net DLL proxy that will call my C++ DLL?

Check the article below. It should help 

https://learn.microsoft.com/en-us/dotnet/framework/interop/consuming-unmanaged-dll-functions

Thanks

I created a .NET DLL wrapper class that calls my unmanaged C++ DLL functions ok. I added the code below to the cBot and it compiles fine in cTrader but when I run the cBot it says it can't find the DLL even though the DLL is in the same directory?

    internal static class NativeMethods {
    
        [DllImport("Client.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern bool connClient(uint id, char[] username, char[] password);
    }

13/08/2024 22:06:42.127 | Info | CBot instance [Client_CBOT, EURUSD, h1] started.
13-08-2024 22:06:42.908 | Error | Crashed in OnStart with DllNotFoundException: Unable to load DLL 'Client.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)

Any ideas? Do I have to use the .NET DLL wrapper… doesn't make sense to do that when cBot is built in .NET?

Make sure your dll is copied to the output directory. Check the Copy Local property and make sure is set to true

 

Thanks but can you attach a bigger screenshot? I don't know where that setting is…


@rick2010

PanagiotisCharalampous
15 Aug 2024, 05:44

RE: RE: RE: RE: RE: RE: RE: Calling DLL functions help.

rick2010 said: 

PanagiotisCharalampous said: 

rick2010 said: 

rick2010 said: 

PanagiotisCharalampous said: 

rick2010 said: 

PanagiotisCharalampous said: 

Hi there,

cBots are based on .Net. Therefore you can only call dll files based on managed code. If your dll is based on managed code, you should be able to use it.

Best regards,

Panagiotis

Thanks for the reply. I figured that was the case. I got a DLL written in managed C/C++. I need to be able to call this DLL from the cBot. I guess the only way to do that is to create a .Net DLL proxy that will call my C++ DLL?

Check the article below. It should help 

https://learn.microsoft.com/en-us/dotnet/framework/interop/consuming-unmanaged-dll-functions

Thanks

I created a .NET DLL wrapper class that calls my unmanaged C++ DLL functions ok. I added the code below to the cBot and it compiles fine in cTrader but when I run the cBot it says it can't find the DLL even though the DLL is in the same directory?

    internal static class NativeMethods {
    
        [DllImport("Client.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern bool connClient(uint id, char[] username, char[] password);
    }

13/08/2024 22:06:42.127 | Info | CBot instance [Client_CBOT, EURUSD, h1] started.
13-08-2024 22:06:42.908 | Error | Crashed in OnStart with DllNotFoundException: Unable to load DLL 'Client.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)

Any ideas? Do I have to use the .NET DLL wrapper… doesn't make sense to do that when cBot is built in .NET?

Make sure your dll is copied to the output directory. Check the Copy Local property and make sure is set to true

 

Thanks but can you attach a bigger screenshot? I don't know where that setting is…

It's from the reference's properties. Click on the reference and check it's properties.

 


@PanagiotisCharalampous