473,378 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

C++ v C#

I have a class library in C++ and it has hundreds of methods each having
scores of static variables. Evidently, I cannot reference this library in a
C# project so I must convert (right?).

In converting the class library to c# I'll need to eliminate the static
variables (right?). To do so, I could declare them at class level or I could
break the library into several classes. Is there any other way? This is a
VERY heavy task with this library.

Do Microsoft developers code in C# or are they secretly using C++?

Aug 20 '07 #1
17 1503
MS has a number of products implemented in a number of technologies, C++
and C# included. There is no one language that they code all of their
product offerings in.

As for converting class libraries, there is really no need to do that.
You can always create a COM wrapper around the classes you expose, and then
reference that in your .NET projects, or create a managed wrapper and then
reference that.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"mr peanut" <mr******@discussions.microsoft.comwrote in message
news:FF**********************************@microsof t.com...
>I have a class library in C++ and it has hundreds of methods each having
scores of static variables. Evidently, I cannot reference this library in
a
C# project so I must convert (right?).

In converting the class library to c# I'll need to eliminate the static
variables (right?). To do so, I could declare them at class level or I
could
break the library into several classes. Is there any other way? This is a
VERY heavy task with this library.

Do Microsoft developers code in C# or are they secretly using C++?

Aug 20 '07 #2
Where can I learn how to do this COM wrapper?

"Nicholas Paldino [.NET/C# MVP]" wrote:
MS has a number of products implemented in a number of technologies, C++
and C# included. There is no one language that they code all of their
product offerings in.

As for converting class libraries, there is really no need to do that.
You can always create a COM wrapper around the classes you expose, and then
reference that in your .NET projects, or create a managed wrapper and then
reference that.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"mr peanut" <mr******@discussions.microsoft.comwrote in message
news:FF**********************************@microsof t.com...
I have a class library in C++ and it has hundreds of methods each having
scores of static variables. Evidently, I cannot reference this library in
a
C# project so I must convert (right?).

In converting the class library to c# I'll need to eliminate the static
variables (right?). To do so, I could declare them at class level or I
could
break the library into several classes. Is there any other way? This is a
VERY heavy task with this library.

Do Microsoft developers code in C# or are they secretly using C++?


Aug 20 '07 #3
"mr peanut" <mr******@discussions.microsoft.comwrote in message
news:C1**********************************@microsof t.com...
Where can I learn how to do this COM wrapper?

"Nicholas Paldino [.NET/C# MVP]" wrote:
> MS has a number of products implemented in a number of technologies,
C++
and C# included. There is no one language that they code all of their
product offerings in.

As for converting class libraries, there is really no need to do
that.
You can always create a COM wrapper around the classes you expose, and
then
reference that in your .NET projects, or create a managed wrapper and
then
reference that.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"mr peanut" <mr******@discussions.microsoft.comwrote in message
news:FF**********************************@microso ft.com...
>I have a class library in C++ and it has hundreds of methods each having
scores of static variables. Evidently, I cannot reference this library
in
a
C# project so I must convert (right?).

In converting the class library to c# I'll need to eliminate the static
variables (right?). To do so, I could declare them at class level or I
could
break the library into several classes. Is there any other way? This is
a
VERY heavy task with this library.

Do Microsoft developers code in C# or are they secretly using C++?


Not to state the obvious, but did you try doing a Google search on COM
wrapper. Surely your answer lies somewhere in the 2.75 million results,
probably 7 or 8 times in the first 10 results.

Aug 20 '07 #4
Hummm, Let's think about that. Now Google has some related resources (some of
which are for sale), and some outright misinformation (some of which is for
sale), some unrelated resources with the terms COM and wrapper.

How to identify a resource which is reliable and immediately applicable to
the subject at hand? I like asking an expert. And what better place to find
one than in this forum?

I'm still interested in some expert direction on this (besides go to H...).
"pedrito" wrote:
"mr peanut" <mr******@discussions.microsoft.comwrote in message
news:C1**********************************@microsof t.com...
Where can I learn how to do this COM wrapper?

"Nicholas Paldino [.NET/C# MVP]" wrote:
MS has a number of products implemented in a number of technologies,
C++
and C# included. There is no one language that they code all of their
product offerings in.

As for converting class libraries, there is really no need to do
that.
You can always create a COM wrapper around the classes you expose, and
then
reference that in your .NET projects, or create a managed wrapper and
then
reference that.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"mr peanut" <mr******@discussions.microsoft.comwrote in message
news:FF**********************************@microsof t.com...
I have a class library in C++ and it has hundreds of methods each having
scores of static variables. Evidently, I cannot reference this library
in
a
C# project so I must convert (right?).

In converting the class library to c# I'll need to eliminate the static
variables (right?). To do so, I could declare them at class level or I
could
break the library into several classes. Is there any other way? This is
a
VERY heavy task with this library.

Do Microsoft developers code in C# or are they secretly using C++?


Not to state the obvious, but did you try doing a Google search on COM
wrapper. Surely your answer lies somewhere in the 2.75 million results,
probably 7 or 8 times in the first 10 results.

Aug 20 '07 #5

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:uo**************@TK2MSFTNGP04.phx.gbl...
MS has a number of products implemented in a number of technologies,
C++ and C# included. There is no one language that they code all of their
product offerings in.

As for converting class libraries, there is really no need to do that.
You can always create a COM wrapper around the classes you expose, and
then reference that in your .NET projects, or create a managed wrapper and
then reference that.
Recompiling with the C++/CLI compiler and some judicious use of "ref class"
would be much easier than either conversion to C# or a wrapper.
Aug 20 '07 #6
mr peanut wrote:
Hummm, Let's think about that. Now Google has some related resources (some of
which are for sale), and some outright misinformation (some of which is for
sale), some unrelated resources with the terms COM and wrapper.

How to identify a resource which is reliable and immediately applicable to
the subject at hand? I like asking an expert. And what better place to find
one than in this forum?

I'm still interested in some expert direction on this (besides go to H...).
>>>>
Not to state the obvious, but did you try doing a Google search on COM
wrapper. Surely your answer lies somewhere in the 2.75 million results,
probably 7 or 8 times in the first 10 results.

Well, if you want expert *direction*, I'd suggest the nearest technical
school.. Here, you'll get input from peers, some with more or less
experience than you do.. The MVPs are a great source, then again doing a
bit of the legwork yourself (say, doing an advanced google group search,
targetting this NG or others like it and searching specifically for COM
wrappers or some such, since I really doubt you're the first to ever
bring it up) is definitely worth the effort..

HTH
P.
Aug 20 '07 #7
From my experience, in most cases, would be a complete and utter
disaster, as usually there are patterns with memory allocation as well as
lifetime issues (due to the introduction of GC) which change completely with
a transition to .NET.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:ug**************@TK2MSFTNGP03.phx.gbl...
>
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:uo**************@TK2MSFTNGP04.phx.gbl...
> MS has a number of products implemented in a number of technologies,
C++ and C# included. There is no one language that they code all of
their product offerings in.

As for converting class libraries, there is really no need to do that.
You can always create a COM wrapper around the classes you expose, and
then reference that in your .NET projects, or create a managed wrapper
and then reference that.

Recompiling with the C++/CLI compiler and some judicious use of "ref
class" would be much easier than either conversion to C# or a wrapper.

Aug 21 '07 #8
Nicholas Paldino [.NET/C# MVP] wrote:
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
>Recompiling with the C++/CLI compiler and some judicious use of "ref
class" would be much easier than either conversion to C# or a
wrapper.

From my experience, in most cases, would be a complete and utter
disaster, as usually there are patterns with memory allocation as
well as lifetime issues (due to the introduction of GC) which change
completely with a transition to .NET.
But isn't that missing the whole point of using C++/CLI for interop? You
don't transition the existing code to .NET. Rather, you build a bridge
between the two worlds. Not that it can't be fraught with pitfalls (which
it certainly can), but in many cases, particularly if the C++ code was well
designed, it's quite possible to build a very usable interop layer without
disturbing the C++ code much (if at all).

-cd
Aug 21 '07 #9
I don't believe it is missing the point. The suggestion was "judicious"
use of "ref class", which will lead exactly to the pitfalls that I mentioned
in my post.

I am in agreement that a well designed class library will help, and that
CLI is a good thing.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:eG**************@TK2MSFTNGP05.phx.gbl...
Nicholas Paldino [.NET/C# MVP] wrote:
>"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
>>Recompiling with the C++/CLI compiler and some judicious use of "ref
class" would be much easier than either conversion to C# or a
wrapper.

From my experience, in most cases, would be a complete and utter
disaster, as usually there are patterns with memory allocation as
well as lifetime issues (due to the introduction of GC) which change
completely with a transition to .NET.

But isn't that missing the whole point of using C++/CLI for interop? You
don't transition the existing code to .NET. Rather, you build a bridge
between the two worlds. Not that it can't be fraught with pitfalls (which
it certainly can), but in many cases, particularly if the C++ code was
well designed, it's quite possible to build a very usable interop layer
without disturbing the C++ code much (if at all).

-cd

Aug 21 '07 #10
"mr peanut" <mr******@discussions.microsoft.comwrote in message
news:51**********************************@microsof t.com...
Hummm, Let's think about that. Now Google has some related resources (some
of
which are for sale), and some outright misinformation (some of which is
for
sale), some unrelated resources with the terms COM and wrapper.

How to identify a resource which is reliable and immediately applicable to
the subject at hand? I like asking an expert. And what better place to
find
one than in this forum?

I'm still interested in some expert direction on this (besides go to
H...).

Sorry, I didn't mean it to be a "go to h" kind of comment so much as a hint:
Do a google search on COM Wrapper

The first result:

http://www.codeproject.com/csharp/SafeCOMWrapper.asp

CodeProject isn't always great, but it's a pretty detailed description fo a
Disposable wrapper which will give you a lot of ideas of how to do a general
wrapper, written by someone who clearly knows what he's doing.

The 5th or 6th item is here:

http://forums.microsoft.com/MSDN/Sho...81150&SiteID=1

is a post in which someone asks: "I have a unmanaged code which I want to
use in C# application...How can I create a COM wrapper to use in that
code...If someone can give some example...."

The response is this link:
http://msdn2.microsoft.com/en-us/library/ms173184.aspx

Which takes you to the MSDN Interoperability (C# Programming Guide)

If you don't consider that expert information, you're certainyl not going to
find any here.

I found all that in a quick google search when you asked the question, which
is why I asked if you had done a google search on COM Wrapper.

This isn't even my question, it's yours... I think the point Philipe made in
the follow up was precisely my point: "The MVPs are a great source, then
again doing a
bit of the legwork yourself (say, doing an advanced google group search,
targetting this NG or others like it and searching specifically for COM
wrappers or some such, since I really doubt you're the first to ever
bring it up) is definitely worth the effort.."
Aug 21 '07 #11
Nicholas Paldino [.NET/C# MVP] wrote:
I don't believe it is missing the point. The suggestion was
"judicious" use of "ref class", which will lead exactly to the pitfalls
that I mentioned in my post.
What do you mean exactly. That Dispose must be explicitly called if
unmanaged resources are wrapped with a "ref class" ?

IMHO the situation is more worse with COM wrappers, where additionally
reference counting is involved.
[...]
Andre
Aug 21 '07 #12
mr peanut wrote:
I have a class library in C++ and it has hundreds of methods each having
scores of static variables. Evidently, I cannot reference this library in a
C# project so I must convert (right?).
Don't think so. IMHO the best solution would be to use C++/CLI and wrap
the C++ classes with managed ones.
The MS VS C++ is capable of compiling native and managed code to a
single assembly. You could even link C#, C++/CLI and C++ into a single
assembly (executable), though this can be only accomplished by using the
linker from the command line.
[...]
Andre
Aug 21 '07 #13
Andre,

Just slapping ref class on all of your classes isn't going to solve the
problem. Some classes depend on deterministic finalization, and some
classes have methods that dictate patterns of memory allocation/release (by
returning pointers) which require a little more thinking.

I don't think that the solution is worse from a conceptual view with COM
wrappers, as the model of reference counting and deterministic finalization
go well together, IMO. I do think that the implementation of COM wrappers
though can be a PITA.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andre Kaufmann" <an*********************@t-online.dewrote in message
news:eQ**************@TK2MSFTNGP05.phx.gbl...
Nicholas Paldino [.NET/C# MVP] wrote:
> I don't believe it is missing the point. The suggestion was
"judicious" use of "ref class", which will lead exactly to the pitfalls
that I mentioned in my post.

What do you mean exactly. That Dispose must be explicitly called if
unmanaged resources are wrapped with a "ref class" ?

IMHO the situation is more worse with COM wrappers, where additionally
reference counting is involved.
>[...]

Andre

Aug 21 '07 #14

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:en**************@TK2MSFTNGP03.phx.gbl...
Andre,

Just slapping ref class on all of your classes isn't going to solve the
"slapping ref class on all of your classes" is exactly what "judicious" does
not mean. Judicious use would be converted the outermost, publicly visible
class to a ref class, and leaving all of the internal helper stuff native.
problem. Some classes depend on deterministic finalization, and some
classes have methods that dictate patterns of memory allocation/release
(by returning pointers) which require a little more thinking.
So you leave the delete calls in place, which causes -- surprise surprise,
deterministic finalization. So do stack semantics. C++/CLI has this
problem solved in a way that is very compatible with native code and far
superior to C#.
>
I don't think that the solution is worse from a conceptual view with
COM wrappers, as the model of reference counting and deterministic
finalization go well together, IMO. I do think that the implementation of
COM wrappers though can be a PITA.
A "ref class" wrapper is far superior to COM (in terms of error reporting,
assembly signing, partial trust sandboxing, and performance just to name a
few ways).

Anyway, COM reference counting isn't deterministic when used from .NET.
IUnknown.Release will be called only when the referent object is collected,
which in .NET is not determistic without adding explicit Dispose calls.
Aug 22 '07 #15


define a calss and reply

*** Sent via Developersdex http://www.developersdex.com ***
Aug 23 '07 #16
Nicholas Paldino [.NET/C# MVP] wrote:

Nicholas,
Andre,

Just slapping ref class on all of your classes isn't going to solve the
problem. Some classes depend on deterministic finalization, and some
classes have methods that dictate patterns of memory allocation/release (by
returning pointers) which require a little more thinking.
I rather thought of wrapping the internal classes with a single or few
ref classes, exposing an interface to access internal functionality.
A C++ class returning a pointer, must be wrapped by a ref class wrapping
the returned pointer.
I know it's not that simple, but IMHO the simplest and straight
forwardest solution of porting to / using native C++ code from a managed
application.
I don't think that the solution is worse from a conceptual view with COM
wrappers, as the model of reference counting and deterministic finalization
go well together, IMO. I do think that the implementation of COM wrappers
though can be a PITA.
Well, at least I had problems with a COM callback, passing a huge number
of COM objects per second to a C# application. Which held all references
, even if I explicitly released and Disposed the COM objects. Perhaps it
was a problem of .NET 1.1 or a general one, because I read about that
this might indeed raise problems and should be prevented.
Andre
Aug 23 '07 #17
Sorry, I don’t understand.

"KALAIARASU BP" wrote:
>

define a calss and reply

*** Sent via Developersdex http://www.developersdex.com ***
Aug 23 '07 #18

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

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.