Re: C# SUCKS - BIG TIME !!! (Arrrgh !!!)



Wow. That's like, well, very angry.

I used the search phrase "managed wrapper C++" on the MSDN site, and it
gave me this first link:

Accessing C++ Code from .NET Framework Objects (Managed Extensions for C++
Specification)

Which is located at (watch for line wrap):

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmxspec/html/vcmg_accessingcodefromframeworkobjects.asp

Then, looking at the table of contents on the left, I noticed it was
part of a larger topic titled:

Part I: Introduction to Wrapping C++ Classes

Which is located at (watch for line wrap):

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmxspec/html/vcmg_overview.asp?frame=true

So all-in-all, it wasn't too hard to find.

You should note that this is syntax in C++ using Managed Extensions
(which was released with .NET 1.1 and before). If you are using .NET 2.0,
then you should use the CLI syntax for creating managed code in C++.

Fortunately, searching for the phrase "cli managed c++ wrapper" on MSDN
gave me this as the second link:

Translation Guide: Moving Your Programs from Managed Extensions for C++ to
C++/CLI

Which is located at (watch for line wrap):

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/TransGuide.asp

I don't know, but when a search engine turns up what you need as the
first or second result, it calls into question how hard one might have
actually looked. It is understandable that you used the wrong search
phrases, but I think that was pointed out to you already.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx


"E.T. Grey" <nebula@xxxxxxxxxxxxxxxxxx> wrote in message
news:dksvnb$ghg$2@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Willy Denoyette [MVP] wrote:
>
> > "E.T. Grey" <nebula@xxxxxxxxxxxxxxxxxx> wrote in message
> news:dkrkai$6n8$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> >
> >> Hi,
> >>
> >> I have a C++ DLL that I want to use from a C# project. I am actually
> usng a lot of advanced C++ features like templates, partial/specialized
> templates, functors and callbacks. I am also using STL containers like
> std::string, std::vector and std::map quite extensively in my C++ DLL API.
> >>
> >> However, I can simplify the API so as to make it easier to use from
> C#. Below, is a very simple "proof of concept" C++ DLL. I would be
> extremely grateful if someone could show me how I can use this Dll from
> C#:
> >>
> >> Here is the code:
> >>
> >> /* C++ code (Header)
> >> (trivial proof of concept DLL */
> >>
> >> #ifdef TESTDLL_EXPORTS
> >> #define CCONV __declspec(dllexport)
> >> #else
> >> #define CCONV __declspec(dllimport)
> >> #endif
> >>
> >> typedef enum {
> >> ONE ,
> >> TWO ,
> >> THREE
> >> } myEnum;
> >>
> >> typedef struct mystruct_ {
> >> int x ;
> >> float y ;
> >> char z[8] ;
> >> } myStruct ;
> >>
> >> typedef int (*INT_FPTR)(const char*, const MyStruct*) ;
> >>
> >> class CCONV MyClass {
> >> public:
> >> MyClass();
> >> MyClass(const MyClass&);
> >> MyClass& operator = (const MyClass&);
> >> ~MyClass();
> >>
> >> private:
> >> //some private variables here ..
> >> };
> >>
> >> class CCONV DClass : public MyClass {
> >> public :
> >> DClass();
> >> DClass(const DClass&);
> >> DClass& operator = (const DClass&);
> >> ~DClass();
> >>
> >> const char* foo(void);
> >> int barney(int, myEnum, const myStruct*); //throws an exception
> >> void register_callback( INT_FPTR ) ;
> >>
> >> private:
> >> INT_FPTR cb ;
> >> };
> >>
> >>
> >> Many Thanks
> >>
> >
> >
> > What do you mean by throws an exception?, "barney" is a C++ member
> function,
>
>
> What is so difficult to understand by this statement?. C++ methods *can*
> throw exceptions - maybe managed C++/C# (or should that be C dumb) classes
> can't ?
>
> > you can't create instances of native C++ classes from C#, so you
> can't call member functions.
> > Your only options are:
> > 1. create a managed C++ class in a managed assembly (using vs2005
> C++/CLI) that wrap your unmanaged C++ class(es).
>
>
> <snip>
> I already knew that. Everybody (including the MS site tells me I need to
> write managed C++ wrapper classes around my C++ classes - but there is no
> useful examples given anywhere - most of the examples are to do with
> calling C functions from C#. So far its been all talk and no examples -
> has anyone *actually* EVER called C++ classes from C#? If it can't be done
> or it has never been tried out in the real world - just be man enough to
> say it instad of issuing the blanket line : "write managed C++ classes
> around your C++ classes". No one as yet (and that included MS itself)
> afaik, has actually provided an example of using C++ classes exported from
> a C++ DLL - so come on : can it be done or NOT ?. If yes (everyone tells
> me it can - but has no examples) - HOW the hell is it done - does anyone
> actually even know?. I provided a simple no brainer C++ DLL and expected
> at least some pseudocode to show how I can call the 2/3 functions from
> C# - apparently, no one really knows how to do this ....
>
>
> Ashura wrote:
>
> > chill man, we r all here to help others!
> > while ya cudnt create instance of c++ class in c#, its a bloody truth.
> > HOWEVER, this NOT so hard to get around.
> >
> > //remove those lines out cuz ya dont need to export the whole
> > //class out from a c++ class
> > #ifdef TESTDLL_EXPORTS #define CCONV __declspec(dllexport) #else
> #define CCONV __declspec(dllimport) #endif
> > NO CHANGES for ya current classes, they r workin just fine
> > //add the following
> > extern "C" __declspec(dllexport) DClass* CreateInstance();
> > extern "C" __declspec(dllexport) DClass* DestroyInstance(DClass* obj);
> >
> > //create the methods to export
> > extern "C" __declspec(dllexport) DClass* CreateInstance()
> > { return new DClass(); }
> >
> > extern "C" __declspec(dllexport) DClass* DestroyInstance(DClass* obj)
> > { delete obj; }
> >
> > /////////////////////////////////////
> > After ya hav done ALL above, im pretty sure ya kno how to deal with
> object instances afterwards, dont ya?
> >
> > ////////////////////////////////////
> > I just roughly put some sample above, it may not workin extactly as
> ya wish but ya hav got the idea.
> >
> > hope this helps
> >
> >
>
> Ok, now we are at least getting somewhere. However, your code (assuming
> that this is the ONLY way forward) proves *precisely* what I had suspected
> all along:
>
> In order to use C++ classes in C#, you have to write a C API (i.e.wrapper)
> around your C++ classes and *then* use the C API from managed C++ - lol
> and lmao !!!, excuse me for my mirth - but one has to admire MS for being
> such a dominat force in the industry despite the fact that it has so many
> half-assed, half baked "technologies" which are so - erm f*@ked up and
> proprietary. C# appears to be nothing more than a blatant plagiarism of
> Java (not to mention a few bits and pieces "borrowed" from C and C++) and
> just enough proprietary crap to ensure that it is not compatable with any
> of the "true" standard languages out there.
>
> This sucks BIG TIME !
>
> PS: Thanks anyway Ashura - at least you tried. But this half cooked
> language (if you can call it that) does not seem to have any saving
> graces.
>
>


.



Relevant Pages

  • Re: Scripting DC Replication
    ... 'Replicate Now', hit okay, then do the other three DC's, what a pain! ... Dim $secondary ...
    (microsoft.public.scripting.wsh)
  • Re: Re:Blue Screen
    ... Could be memory, could be several things. ... Just because Ram is new ... >> (watch the wrap) ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Ongoing HD problem:
    ... read through the second link for SP3 you gave me above. ... it is "Gold" or SP1, use these instructions: ... (watch the wrap, it's a long address) ...
    (microsoft.public.windowsxp.general)
  • Re: OT Sports query for U.K. alt.guitar members
    ... cricket what is a googly? ... Watch for the wrap. ... Barbeques on fire by the chalets past the castle headland ...
    (alt.guitar.beginner)
  • Re: help on getting started in c#
    ... Where do I get the compiler (only available in Visual Studio)? ... framework, and it is installed. ... You can find those at (watch for line wrap): ...
    (microsoft.public.dotnet.languages.csharp)

Quantcast