Author |
Topic: Using API in unmanaged C++ DLL. (8 messages, Page 1 of 1) |
||||
---|---|---|---|---|---|
Moderators: VPfau | |||||
BFeddish Posts: 7 Joined: Aug 07, 2015 |
I have a client that has stock software written in some ancient development environment. I can’t remember the name. It can only call old unmanaged DLL’s and that’s it. A year or so I ago I wrote one in C++ VS2003 so he could communicate with a web service and it took a while but it worked. Now he wants to communicate with the OEC API. The best I could come up with so far was a C++ DLL that called a managed C# DLL that references the API.DLL but the problem is the API returns information, like login failed, etc. in events and those don't appear to be getting called, let alone the fact the C++ really just wants to call a function and get a value and be done with it.
Any suggestions would be appreciated. Thanks, Bryan Brayn Feddish |
||||
CMicciche902 Posts: 367 Joined: |
First, signup for our API account. Then, you can download samples with the following links:
32-bit Samples - http://futures.gaincapital.com/trading/api/documentation.cfm?ClientUpdate=0_5004_1 64-bit Samples - http://futures.gaincapital.com/trading/api/documentation.cfm?ClientUpdate=0_5005_1 Documentation - http://futures.gaincapital.com/api/api/index.html Once you have reviewed the Samples, if you have further questions, let us know. Chris M |
||||
BFeddish Posts: 7 Joined: Aug 07, 2015 |
I have all these samples. I need to call the API from an unmanaged C++ DLL. The samples are all executables.
Bryan Brayn Feddish |
||||
CMicciche902 Posts: 367 Joined: |
You are correct to say the files are executables, but it is an installer of many items. It will however contain DLLs in the C:\Program Files\OEC\OEC API COM 3.5 folder (64-bit) or in x86 folder for 32-bit.
In the C:\Program Files\OEC\OEC API COM 3.5\Samples\Cpp folder, it will contain project files for VS. In the C:\Program Files\OEC\OEC API COM 3.5\Samples\Cpp folder, it will contain Excel COM book file. Chris M |
||||
CMicciche902 Posts: 367 Joined: |
I recommend you read our API docs, if you have not already done so. Getting Started...http://futures.gaincapital.com/api/api/html/95076d7d-0f62-41aa-9628-a14fdd5ce6b2.htm
Chris M |
||||
BFeddish Posts: 7 Joined: Aug 07, 2015 |
I don't see a DLL sample in there, just the C++ exe and Excel.
Thanks Bryan Brayn Feddish |
||||
CMicciche902 Posts: 367 Joined: |
OECAPI is made of three DLLs: API.DLL, CommLib.DLL and ProtoSharp.Core.dll. References to all of them should be added to your project.
Chris M |
||||
BFeddish Posts: 7 Joined: Aug 07, 2015 |
The problem is, since I'm trying to do this inside a DLL I can successfully call the Connect() method from my c++ dll but in this DLL the oecapi_OnLoginFailed or oecapi_OnDisconnected never get triggered.
// Interface declaration. public interface ICalculator { //int Add(int Number1, int Number2); string Connect(string www, int nID, string user, string pass, bool bVal, string strKey); string GetLastVal(string strVal); }; // Interface implementation. public class ManagedClass : ICalculator { //C:\CSP\Ment\TransLib\TransLib\bin\Debug>RegAsm.exe translib.dll /tlb:translib.tlb /codebase static OEC.API.OECClient oecapi = new OEC.API.OECClient(); static string strReturnValue = "Not Set"; public string Connect(string www, int nID, string user, string pass, bool bVal, string strKey) { string strRetVal = ""; try { oecapi.Connect(www, nID, user, pass, bVal); oecapi.OnLoginComplete += new OEC.API.OnLoginCompleteEvent(oecapi_OnLoginComplete); oecapi.OnLoginFailed += new OEC.API.OnLoginFailedEvent(oecapi_OnLoginFailed); oecapi.OnDisconnected += new OEC.API.OnDisconnectedEvent(oecapi_OnDisconnected); if (oecapi.CompleteConnected) { strRetVal = "Connected!"; } else { strReturnValue = "Failed Connect"; strRetVal = strReturnValue; } } catch (Exception ex1) { strRetVal = ex1.Message; } return strRetVal; } public string GetLastVal(string strVal) { return strReturnValue; } static void oecapi_OnLoginComplete() { strReturnValue = string.Format("{0}", oecapi.CompleteConnected); } static void oecapi_OnLoginFailed(OEC.Data.FailReason reason) { strReturnValue = string.Format("{0}", reason); } static void oecapi_OnDisconnected(bool unexpected) { strReturnValue = string.Format("{0}", unexpected ? "unexpected" : "expected"); } } Brayn Feddish |
||||