API Support Forum
OEC API > API Support > C++ Example for .Net
Author Topic: C++ Example for .Net
(15 messages, Page 1 of 1)
Moderators: VPfau
LCarter2
Posts: 20
Joined: Jun 13, 2013


Posted: Jul 25, 2013 @ 01:45 PM             Msg. 1 of 15
Are there any examples for C++ using the .Net solution (as opposed to the COM solution)?

Leigh Carter
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Jul 25, 2013 @ 01:48 PM             Msg. 2 of 15
Unfortunately, we don't have it. Maybe, some of other developers could share.

Victor Vins
Lead Software Developer
LCarter2
Posts: 20
Joined: Jun 13, 2013


Posted: Jul 25, 2013 @ 01:57 PM             Msg. 3 of 15
Hi Victor,

I tried creating a simple test program (based on the C# connection example), but I am getting a System.IO.IOException occurring in the CommLib.dll

See the debug output below.

I am sure it is something simple, but since this error is occurring int the CommLib.dll, it is very difficult for me to trouble shoot.

Maybe you could point me in the right direction?

'OEC.exe': Loaded 'C:\dev\OEC\Debug\OEC.exe', Symbols loaded.
'OEC.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\mscoree.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\msvcp110d.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\msvcr110d.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoreei.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\msvcr110_clr0400.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\bf2ecabcd96ec8238dc385b0a3ffa084\mscorlib.ni.dll', No native symbols in symbol file.
'OEC.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', Symbols loaded.
'OEC.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Symbols loaded.
'OEC.exe' (Managed (v4.0.30319)): Loaded 'C:\dev\OEC\Debug\OEC.exe', Symbols loaded.
'OEC.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clrjit.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\diasymreader.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System\9c7c3cd390aa067130df3a89c0d3b6e4\System.ni.dll', No native symbols in symbol file.
'OEC.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll', Symbols loaded.
'OEC.exe': Loaded 'ImageAtBase0x100b0000', Loading disabled by Include/Exclude setting.
'OEC.exe': Loaded 'ImageAtBase0xb60000', Loading disabled by Include/Exclude setting.
'OEC.exe': Unloaded 'ImageAtBase0x100b0000'
'OEC.exe': Loaded 'C:\Windows\SysWOW64\cryptsp.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\rsaenh.dll', Symbols loaded (source information stripped).
'OEC.exe' (Managed (v4.0.30319)): Loaded 'C:\dev\OEC\Debug\API.dll'
'OEC.exe': Loaded 'ImageAtBase0xfcf0000', Loading disabled by Include/Exclude setting.
'OEC.exe': Loaded 'ImageAtBase0xc50000', Loading disabled by Include/Exclude setting.
'OEC.exe': Unloaded 'ImageAtBase0xfcf0000'
'OEC.exe' (Managed (v4.0.30319)): Loaded 'C:\dev\OEC\Debug\CommLib.dll'
'OEC.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Drawing\9cab1291edbd51be678afdaf86c643c4\System.Drawing.ni.dll', No native symbols in symbol file.
'OEC.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Windows.Forms\94fc97289ba0902a9237cdbfc19cdcc1\System.Windows.Forms.ni.dll', No native symbols in symbol file.
'OEC.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Symbols loaded.
'OEC.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Symbols loaded.
'OEC.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Program Files (x86)\DigitalPersona\Bin\DpOFeedb.dll', Cannot find or open the PDB file.
'OEC.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\userenv.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\profapi.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Program Files (x86)\DigitalPersona\Bin\DpOSet.dll', Cannot find or open the PDB file.
'OEC.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\nlssorting.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\IPHLPAPI.DLL', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\nsi.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\winnsi.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\dnsapi.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\ws2_32.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\dhcpcsvc.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\dhcpcsvc6.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Management\1a5cea3827896983ebf576ca86090cc3\System.Management.ni.dll', No native symbols in symbol file.
'OEC.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Management\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Management.dll', Symbols loaded.
'OEC.exe': Loaded 'C:\Windows\SysWOW64\RpcRtRemote.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\WMINet_Utils.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\clbcatq.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\wbem\wmiutils.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\wbemcomn.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\wbem\wbemprox.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\wbem\wbemsvc.dll', Symbols loaded (source information stripped).
The thread 'Win32 Thread' (0x1c6c) has exited with code 0 (0x0).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\wbem\fastprox.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\ntdsapi.dll', Symbols loaded (source information stripped).
The thread 'Win32 Thread' (0x18f8) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x2b9c) has exited with code 0 (0x0).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\bcrypt.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\psapi.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Configuration\d87de4bbcefb0a67eaae225f35964a4f\System.Configuration.ni.dll', No native symbols in symbol file.
'OEC.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Symbols loaded.
'OEC.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Xml\858e88af3a72319bdce4f6e1f9492f46\System.Xml.ni.dll', No native symbols in symbol file.
'OEC.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll', Symbols loaded.
'OEC.exe': Loaded 'C:\Windows\SysWOW64\mswsock.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\WSHTCPIP.DLL', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\wship6.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Program Files (x86)\Common Files\microsoft shared\Windows Live\WLIDNSP.DLL', Cannot find or open the PDB file.
'OEC.exe': Loaded 'C:\Windows\SysWOW64\rasadhlp.dll', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'C:\Windows\SysWOW64\FWPUCLNT.DLL', Symbols loaded (source information stripped).
'OEC.exe': Loaded 'ImageAtBase0xf160000', Loading disabled by Include/Exclude setting.
'OEC.exe': Loaded 'ImageAtBase0x47b0000', Loading disabled by Include/Exclude setting.
'OEC.exe': Unloaded 'ImageAtBase0xf160000'
'OEC.exe' (Managed (v4.0.30319)): Loaded 'C:\dev\OEC\Debug\ProtoSharp.Core.dll'
A first chance exception of type 'System.IO.IOException' occurred in CommLib.dll
A first chance exception of type 'System.IO.IOException' occurred in CommLib.dll
The thread 'Reader Price' (0xf44) has exited with code 0 (0x0).
The thread 'Reader Order' (0x1a84) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xf44) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1a84) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x2bfc) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x27f4) has exited with code 0 (0x0).
The thread '<No Name>' (0x2838) has exited with code 0 (0x0).
The thread '<No Name>' (0x1394) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x2838) has exited with code 0 (0x0).
The thread '<No Name>' (0x2370) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1394) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1130) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x2370) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x2038) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1f88) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1548) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1710) has exited with code -1073741510 (0xc000013a).
The thread 'Win32 Thread' (0xcc8) has exited with code -1073741510 (0xc000013a).
The thread 'Win32 Thread' (0x2528) has exited with code -1073741510 (0xc000013a).
The thread 'Win32 Thread' (0xe98) has exited with code -1073741510 (0xc000013a).
The thread 'Win32 Thread' (0x208c) has exited with code -1073741510 (0xc000013a).
The thread 'Win32 Thread' (0xbf8) has exited with code -1073741510 (0xc000013a).
The thread 'Win32 Thread' (0x224c) has exited with code -1073741510 (0xc000013a).
The program '[10528] OEC.exe: Native' has exited with code -1073741510 (0xc000013a).
The program '[10528] OEC.exe: Managed (v4.0.30319)' has exited with code -1073741510 (0xc000013a).

Leigh Carter
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Jul 25, 2013 @ 02:18 PM             Msg. 4 of 15
It is hard to say what could it be. Could you wrap it to try/catch and check content of IOException?

Victor Vins
Lead Software Developer
LCarter2
Posts: 20
Joined: Jun 13, 2013


Posted: Jul 25, 2013 @ 02:28 PM             Msg. 5 of 15
Unfortunately, it never gets into my sample code.

I don't get any callback to onLoginComplete() or onLoginFailed(FailReason reason)

I only noticed the IOException in the output window.

Here is the source code:

#include "stdafx.h"
#include <sstream>
#include <iostream>
#include <string>

#using <System.dll>

using namespace System;

using namespace OEC::API;
using namespace OEC::Data;
using namespace std;

void onLoginComplete()
{
cerr << "Login Complete!" << endl;
}

void onLoginFailed(FailReason reason)
{
cerr << "Login Failed!" << endl; //reason.ToString() << endl;
}

void onDisconnected(bool unexpected)
{
cerr << "Disconnected! " << endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
cerr << "INITIALIZING" << endl;

OECClient client;
client.UUID = "9e61a8bc-0a31-4542-ad85-33ebab0e4e86";

cerr << "CONNECTING" << endl;
client.Connect("api.openecry.com", 9200, "vic", "vic", true);
client.OnLoginComplete += gcnew OnLoginCompleteEvent(&onLoginComplete);
client.OnLoginFailed += gcnew OnLoginFailedEvent(&onLoginFailed);
client.OnDisconnected += gcnew OnDisconnectedEvent(&onDisconnected);

cerr << "Waiting for input" << endl;

string input = "";
getline(cin, input);
cerr << "Exiting" << endl;

return 0;
}

Leigh Carter
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Jul 25, 2013 @ 04:27 PM             Msg. 6 of 15
CommLib.dll catches these exceptions internally, they shouldn't stop the application. They are raised when OEC server breaks connection (password was incorrect in my case).

To make you code working, you need to add some kind of Windows message pumping (System.Windows.Forms.Application.Run() in the sample)

Victor Vins
Lead Software Developer
LCarter2
Posts: 20
Joined: Jun 13, 2013


Posted: Jul 29, 2013 @ 10:15 AM             Msg. 7 of 15
Thanks Victor,

I was able to setup a windows event loop to workaround this.

Now I am having a problem accessing parameters from events. It looks like the memory is being deallocated prior to calling my event.

For example, the OnSymbolLookupReceived() event, the ContractList parameter gives an access violation as soon as I try to access the Count field (ie contracts->Count).

I had this issue on prior projects with COM programming in C++. In that case I had to initialize the COM module properly and ensure that all COM calls were made from a single thread that was initialized with CoInitialize() method.

Is there something similar that needs to be done for .Net?

Leigh Carter
VPfau
Moderator
Posts: 164
Joined:


Posted: Jul 30, 2013 @ 10:51 AM             Msg. 8 of 15
I changed a little your code to make a symbol lookup call. I don't see any exceptions. Take a look:

#include "stdafx.h"
#include <sstream>
#include <iostream>
#include <string>
#include <msclr\marshal.h>
#include <msclr\marshal_cppstd.h>

#using <System.dll>

using namespace System;

using namespace OEC::API;
using namespace OEC::Data;
using namespace std;
using namespace msclr::interop;

ref class Global
{
public:
static OECClient^ client = nullptr;
};

void onLoginComplete()
{
cerr << "Login Complete!" << endl;

cerr << "Looking up all ES contracts" << endl;
OEC::API::SymbolLookupCriteria^ criteria = gcnew OEC::API::SymbolLookupCriteria();
criteria->Mode = OEC::Data::SymbolLookupMode::SymbolStartsWith;
criteria->SearchText = "ES";
Global::client->SymbolLookup(criteria);
}

void onLoginFailed(FailReason reason)
{
cerr << "Login Failed!" << endl; //reason.ToString() << endl;
}

void onDisconnected(bool unexpected)
{
cerr << "Disconnected! " << endl;
}

void onSymbolLookup(OEC::API::SymbolLookupCriteria^ criteria, ContractList^ contracts)
{
cerr << "Lookup done!" << endl;

cerr << "Count: " << contracts->Count <<endl;
if (contracts->Count == 0) return;

cerr << "Contracts: ";
for each(OEC::API::Contract^ contract in contracts)
cerr << marshal_as<string>(contract->Symbol) << "; ";
cerr << endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
cerr << "INITIALIZING" << endl;

Global::client = gcnew OECClient();
OECClient% client = *Global::client;

client.UUID = "9e61a8bc-0a31-4542-ad85-33ebab0e4e86";

cerr << "CONNECTING" << endl;
client.Connect("api.openecry.com", 9200, "vic", "vic", true);
client.OnLoginComplete += gcnew OnLoginCompleteEvent(&onLoginComplete);
client.OnLoginFailed += gcnew OnLoginFailedEvent(&onLoginFailed);
client.OnDisconnected += gcnew OnDisconnectedEvent(&onDisconnected);
client.OnSymbolLookupReceived += gcnew OnSymbolLookupEvent(&onSymbolLookup);

System::Windows::Forms::Application::Run();
}


Vitaliy Pfau
LCarter2
Posts: 20
Joined: Jun 13, 2013


Posted: Aug 15, 2013 @ 11:34 AM             Msg. 9 of 15
Unfortunately, this still does not work for me.
I tried putting the Symbol Lookup in the onLoginComplete and it still does not work :(

Leigh Carter
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Aug 15, 2013 @ 11:37 AM             Msg. 10 of 15
Could you please check if our sample code above is working on your side?

Victor Vins
Lead Software Developer
LCarter2
Posts: 20
Joined: Jun 13, 2013


Posted: Aug 15, 2013 @ 11:55 AM             Msg. 11 of 15
The sample you are providing is not of much use to me.

I am creating a command line application, so I have created a separate event thread that processes messages with its own windows message loop.

The main thread accepts commands and posts events to the message loop. All of the calls to the OECClient are made through the event thread. For some reason when the parameters are passed to the OECEvents handler, the memory is deallocated.

I am sure it has something to do with the way memory is managed in .Net. The solution is probably very simple, but I can't find any information online that indicates what needs to be done (or declared).

I have implemented COM based applications in the same way without any issues...
Unfortunately, I am stuck at this point.

Leigh Carter
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Aug 15, 2013 @ 11:58 AM             Msg. 12 of 15
Could you please share your multi-threading sample?

Victor Vins
Lead Software Developer
LCarter2
Posts: 20
Joined: Jun 13, 2013


Posted: Aug 15, 2013 @ 12:01 PM             Msg. 13 of 15
There does not appear to be a way to attach a file. Could I email it to you?

Leigh Carter
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Aug 15, 2013 @ 12:03 PM             Msg. 14 of 15
Yes, sure. Please send it to api@openecry.com

Victor Vins
Lead Software Developer
LCarter2
Posts: 20
Joined: Jun 13, 2013


Posted: Aug 15, 2013 @ 12:08 PM             Msg. 15 of 15
OK, I just sent it...

Leigh Carter