Hello There, Guest!
View New Posts  |  View Today's Posts
C++ .Lib access from C#? I have a weird question

  • 0 Vote(s) - 0 Average


12-11-2015, 07:43 AM #1
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

C++ .Lib access from C#? I have a weird question
Alright, this is by far one of the more interesting programming dilemmas I've ever been in. It's partly due to my inexperience with C++. I have quite a few things that may or may not allow me to do some of the things I want so I'm partly looking for some ideas as well.

First, here's the task. I'm working on creating plugins for Camfrog, the video chat application. They have an SDK and some sample code done in C++ that I'm working on going through at the moment. Most of the things I will be doing is text based, so it's not CRUCIAL that I create apps in C#. I'd simply prefer to do them in C# because I'm WAY more comfortable with it and I could turn out some very nice plugins A LOT quicker.

First option: Figure out how to compile the .lib files provided by the SDK to DLL and reference them from C#. I'm not sure if this will even be possible since the Bot application is written in C++, I'm not sure if it would even accept a non-native DLL to be loaded as a plugin.

Second option: If I was unable to do that, I thought about doing some sort of socket connection that sends all commands to a C# application, then returns the instruction to be carried out by the C++ plugin. This would be sort of easy, providing that I can find a simple enough socket library to use.

Third option: just quit being lazy and brush up on C++. This would be ideal, and might be what I end up doing.

I appreciate ANY perpective that someone could shed on this. The SDK documentation says something about a low-level implementation that can be called from high level languages, but I haven't found much documentation on how to expose methods to .Net in order do do such a thing.

I've uploaded the SDK documentation here if anyone cares to take a look:
http://devsite.in/files/help.rar

Here are the SDK files that come with the bot:
http://devsite.in/files/sdk_files.rar


Again, any ideas or help is much appreciated.

12-11-2015, 04:09 PM #2
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

RE: C++ .Lib access from C#? I have a weird question
Alright, well I've managed to successfully build a plugin in C++. Holy poop though, going through all of this stuff when you're not familiar with the compiler and what not is a pain. I'm using VS2015, and the sdk .Libs were compiled with a lower version of VS. So, I had to get that project updated/recompiled. Among other things, like the boost libraries needing to be built 4 different ways.

So, now... I guess the point I'm at is how should I set this thing up? Sockets to connect to a C# console program that is listening on a port for instructions? I'm wondering how difficult that'd be. For now, I'm going to continue to use C++. It's a good opportunity for me to brush up on my skills. But I'm afraid if I want to do anything advanced it would take me FOREVER to do in C++ when it would be so much easier for me in C#.

I'm wondering if maybe instead of doing that, if I could maybe write a managed class, and reference it from C++? Then I could pass variables to it and return the string response to send back.
This post was last modified: 12-11-2015, 04:13 PM by KoBE.

12-12-2015, 04:05 AM #3
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

RE: C++ .Lib access from C#? I have a weird question
So, I've decided to go down the call C# code from C++. I'm looking into making the C# dll COM Visible and hoping that it works.

12-12-2015, 10:01 AM #4
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

RE: C++ .Lib access from C#? I have a weird question
That didn't work so well. I could get the code to see the C# methods but for whatever reason I could never get it to call the method without erroring.

I then decided to look into NamedPipes to talk between the two. But GOD FOR ****ing SAKES anything is straightforward. I can get two C++ applications to talk, but when C# is the server.. nope. I'm sure it has something to do with security somewhere. But I can't find poop about setting it. I'm about to blow a gasket dealing with this poop. Lol. I'm spoiled by C# and now I'm feeling the effects of not a lot of poop already programmed for me.

12-12-2015, 11:06 PM #5
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

RE: C++ .Lib access from C#? I have a weird question
Another update.

I've finally got a decent solution working for my needs at the moment. I am going to need to adjust it soon, but for now I'm using a local socket connection to connect to a C# server. The plugin simply forwards the byte array it would normally use to do things to the C# application. From there I am going to handle all of the nitty gritty stuff and send back the byte array response that would normally have been built by the plugin. That part of the application I'm actually really proud of.

The downfall is that I'm only able to do receive responses AFTER sending a packet first. What I want to do eventually is either have some sort of asynchronous call back that I can use to listen the whole time, or perhaps open a synchronous method that sits on a different thread.

I'm just glad it's working and I can start pumping out some basic plugins in the mean time.

12-13-2015, 02:49 AM #6
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: C++ .Lib access from C#? I have a weird question
Between managed and native involves a bit more setup and some extra stuff to be loaded. I'm confused on the latest solution in your last update though. I'm not sure how to interpret your wording to understand exactly what you're doing..


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲

12-13-2015, 11:40 PM #7
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

RE: C++ .Lib access from C#? I have a weird question
The c++ plugin is loaded into an existing application. The plugin is sent byte arrays which is then formatted into a message and handled by the plugin... what I'm doing is sending that byte array over a Tcp connection to a C# server that is listening for it. My C# application then responds with the appropriate byte array that the plugin would have built instead. So, the plugin is basically a middleman that is forwarding messages between the actual application and my C# implementation.

And, I've got over the problem about needing it to be async. Turns out it the plugin can listen to a message that is sent every 100 ms. So, I can pick up any non-sent messages from a que and not miss much time.

12-14-2015, 05:21 PM #8
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: C++ .Lib access from C#? I have a weird question
You could create your own functionality similar to a TCP/IP stack. Essentially you have one part reading the data into a large pending buffer, and from there you send data to a second buffer where it's packaged up to be sent to the C# server. Same thing on the receive side where you'd have pending buffers.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲




Forum Jump:


Possibly Related Threads...
Thread Author Replies Views Last Post
   Logstalgia - Web Access Log Visual AceInfinity 0 934 09-14-2014, 08:04 PM
Last Post: AceInfinity


Users browsing this thread: 1 Guest(s)