473,883 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Run C++ code in C#.NET

A business associate told me that I should be able to run C++ code in
C#.NET environment because C++ and C# belong to the same family.

He sent me the code below and asked me to run in C#.NET environment. I
got numerous compiling errors because #include stuff don't exist in
C#! Could anyone tell me if the code below should run in C#.NET?

-------------------------------------------------------------------------------------------------------------------------------

//#define NO_NEWIO

#include <iostream>

/// Include for CONNECT/C++
#include "stdafx.h"
#include "stdafx.cpp "
//#include "sconnect.h "

#include "c:\\data\\Splu s61 Includes\\EasyE ngineConnect.h"
#include "c:\\data\\Splu s61 Includes\\EasyE ngineConnect.cp p"

#include "c:\\data\\Splu s61 Includes\\EasyC haracter.h"
//#include "c:\\data\\Splu s61 Includes\\EasyC haracter.cpp"

#include "c:\\data\\Splu s61 Includes\\EasyM atrix.h"
//#include "c:\\data\\Splu s61 Includes\\EasyM atrix.cpp"

#include "c:\\data\\Splu s61 Includes\\EasyN umeric.h"
//#include "c:\\data\\Splu s61 Includes\\EasyN umeric.cpp"

using namespace std;

int main(int argc, char* argv[])
{

// Connect to S+
EasyEngineConne ct easyconnect_(ar gc, argv);
/// Create matrix 9x9 elem.
//EasyMatrix x;
//x.Create("matri x(1:9, nrow=9, ncol=9)", "x");
// Create matrix 9x9 elem.
//EasyMatrix y;
//y.Create("matri x(1:9, nrow=9, ncol=9)", "y");

CSPobject Y;
if (!Y.Create("vec tor(\"double\", 10.6)"))
{
cout << "Can not create vector." << endl;
return 1;
}

CSPobject X1;
if (!X1.Create("ve ctor(\"double\" ,8.6)"))
{
cout << "Can not create vector." << endl;
return 1;
}
CSPobject X2;
if (!X2.Create("ve ctor(\"double\" ,3.4)"))
{
cout << "Can not create vector." << endl;
return 1;
}

/// Connect to S+
// CSPengineConnec t engineConnect(a rgc, argv); //EasyEngineConne ct
easyconnect_(ar gc, argv);

/// Create matrix 9x9 elem.
CSPmatrix x;
x.Create("matri x(1:9, nrow=9, ncol=9)", "x");

CSPnumeric sx;
sx.Create("1:10 ","x");
CSPnumeric sy = sx * sx;
sy.Assign("y");
// engineConnect.S yncParseEval("z <-lm(y~x)");

/*
CSPengineConnec t engineConnect(a rgc, argv);

CSPobject x;
/// Create matrix 24x400 elem.
x.Create("matri x(1:223, nrow=24, ncol=400)");
//x.Create("matri x(1.2, nrow=, ncol=10)");
CSPobject y;
/// Create matrix 24x400 elem.
y.Create("matri x(231:1, nrow=24, ncol=400)");
/// Assign.
x.Assign("x");
y.Assign("y");
/// Call S+ regression "z<-x+y".
int iSuccess = engineConnect.S yncParseEval("z <-x+y");
/// Error.
if (iSuccess == 0)
{
cout << "Error, Can not call \"z<-(x+y)\"" << endl;
return 1;
}
CSPmatrix z(engineConnect .get("z"));
if (!z.IsValid())
{
cout << "Error, Can not search object z" << endl;
}
/// Print.
for (int i = 1; i <= 5;i++); //z.GetNRow(); ++i)
{
for (int j = 1; j <= z.GetNCol(); ++j)
{
cout << (double)z(i, j) << " ";
}
cout << endl;
}


/*
//Create the connection to S-PLUS
CSPengineConnec t engineConnect(a rgc, argv);
/// Create vector 24.
CSPobject A_vector;
if (!A_vector.Crea te("vector(\"do uble\",10)"))
{
cout << "Can not create vector." << endl;
return 1;
}
CSPobject B_matrix;
if (!B_matrix.Crea te("matrix(1.2 , nrow=10, ncol=10)"))
{
cout << "Can not create matrix." << endl;
return 1;
}
/// C_matrix = B_matrix + A_vector.
CSPmatrix C_matrix(B_matr ix + A_vector) ;
if (C_matrix == NULL)
{
cout << "Can not create matrix." << endl;
}
*/

/*
CSPnumeric sx;
sx.Create("1:10 ","x");
CSPnumeric sy = sx * sx;
sy.Assign("y");
engineConnect.S yncParseEval("z <-lm(y~x)");

*/

/*
/// Print C_matrix.
cout << "Print C_matrix = B_matrix + A_vector." << endl << endl;
for (int i = 1; i <= C_matrix.nrow() ; ++i)
{
for (int j = 1; j <= C_matrix.ncol() ; ++j)
{
cout << (double)C_matri x(i,j) << " "; //< Out to console.
}
cout << endl;
}

cout << endl << endl;

getchar();

/// Call procedure S+.

CSPcharacter returnObj;
/// Create a integer vector with one element
/// representing one argument to pass to function 'objects'
CSPinteger args("1");
/// Create a CSPcall object
CSPcall sCall;
/// Call function S+ (objects()).
cout << "Call function S+ (objects(1))... ." << endl << endl;
sCall.Create("o bjects", args);
/// Call.
returnObj = sCall.Eval(); // objects(1)
if (returnObj == NULL)
{
cout << "Function objects S+ failed" << endl;
return 1;
}

/// Get quantity.
int quantity = returnObj.lengt h();
cout << "Quantity objects : " << quantity << endl;
/// Print objects.
for (i = 0; i < quantity; ++i)
{
cout << " [ " << i+1 << " ] " << (char *)returnObj[i] << endl;
}
*/

/*
//Create the connection to S-PLUS
g_engineConnect .Create( argc, argv);

//Create S object with name "x" in the current database.
//Same as x<-1:10 at the command line.
CSPnumeric sx;
sx.Create("1:10 ","x");

//Squaring sx, which is the same as S expression sy <- x*x in a local
frame,
//but here we set it to local C++ variable sy.

CSPnumeric sy = sx * sx;

// Assign the result as S object with name "y" in the current
database.
sy.Assign("y");

//Evaluate z<-lm(y~x)
g_engineConnect .SyncParseEval( "z<-lm(y~x)");

maybe ------------------- CSPobject Eval ("z<-lm(y~x)");
//second example
CSPevaluator s;

CSPcharacter message("'hello '");
message.Print() ;

//CSPmatrix M("matrix(1:4,r now=2)");
//M.Print();
*/

printf("Normal Termination\n") ;
return 0;
}

Oct 28 '08
10 7933
If your function in C++ is (char * a, s_object * b, long c), then your
declare statement should be (string a, IntPtr b, int c).
"Curious" <fi********@yah oo.comwrote in message
news:a9******** *************** ***********@q30 g2000prq.google groups.com...
On Nov 3, 10:23 am, "Family Tree Mike"
<FamilyTreeM... @ThisOldHouse.c omwrote:
That is a very different question than you started. Yes, you can compile a
dll and call it from c#. http://www.pinvoke.net/has examples on how to
call windows api dlls. You will do something similar with your associates
dll.

Your associate must be "fun" to work with :(.

"Curious" <fir5tsi...@yah oo.comwrote in message

news:16******** *************** ***********@g17 g2000prg.google groups.com...
My business associate insists that he can run C++ functions from C#
code.
Will it be possible to compile C++ code (managed code) into a .dll,
and reference the .dll from C#.NET code, and call C++ code in the
library
Family Tree Mike,

How would this work? The parameter types in C++ methods are different
from the data types in C#. For instance, I have the following
parameter types in C++:

char *
s_object *
long

What types shall I define for the parameters in C# to be passed to the
C++ so that they'll be recognized as types char *, s_object *, and
long?

Nov 4 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
5317
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
109
5983
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any question that identifies the warning signs to look out for, the things that most easily and clearly identify the author of code as something less than a master of the art. I did not find an FAQ that answered it, but I think the FAQ
0
2103
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to allow it ro run then it will execute, the code execution depends on the permission provided to the assembly. If the code is not trusted wnough to run or it attempts to perform an action which doe not have the required permissions then its execution...
171
7848
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little overkill. I use Dreamweaver to do my design and find it a bit of a hassle to have multiple files open...
4
2123
by: KenFehling | last post by:
Hello. I am wondering if there exists a piece of software that takes multiple .js files that are nicely indented and commented and create one big tightly packed .js file. I'm hoping the one file would be less of a burden for the user's browser to download. I guess the final code output by this hypothetical program could maybe even just be on one long line unless that would create problems. Maybe there is some kind of optimal line...
88
8116
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
7
3434
by: blackrosezy | last post by:
#include char *code; void main() { char buf = "book";
2
4834
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be required: <%@ Register TagPrefix="UC" TagName="MyUserCtrl" Src="MyUC.ascx" %> Assuming that the ASPX page doesn't use a code-behind, I can access the properties, events etc. of the user control in the ASPX page in this way (assume that the ASPX page...
1
1545
by: ahammad | last post by:
Hello, I have written a fairly complex parsing tool that is used to parse information from company documents. The program works very well, but in order to insure that all the data is copied properly, I had to remove some of the things that are not part of the data, but are simply headings. Here is what I mean: *Heading <CODE1> = <COMMAND1> <CODE2> = <COMMAND2> The program reads in each line, and separates <CODE1> from <COMMAND1> at...
66
7486
by: Jon Skeet [C# MVP] | last post by:
I'm sure the net will be buzzing with this news fairly soon, but just in case anyone hasn't seen it yet: Microsoft are going to make the source code for the .NET framework (parts of it, including the BCL, ASP.NET and LINQ) available both for viewing and debugging into. I won't go into all the details here, as they're covered on Scott Guthrie's blog:
0
9942
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11142
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9574
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7971
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7129
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3233
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.