I think he meant "and that can be done in the same C# project?" - to which
the answer is no

For the sake of completeness, I'd like to mention the multimodule capability
of .NET (you compile your C# stuff to a .module, your MC++ stuff to another
.module, and the two are linked together into one single .DLL) but I'm not
aware of any serious use of that technique.  Plus, it's incompatible with
the VS IDE - you'll have to do command line compile / link

-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Eames, Andrew
Sent: Wednesday, August 10, 2005 6:32 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] [Spam:***** SpamScore] Re: [ADVANCED-DOTNET]
[Spam:***** SpamScore] Re: [ADVANCED-DOTNET] Can C# and unmanaged C++
coexist in the same solution? Same project?

Yup - you can have both managed and unmanaged c++ in the same file
  Andrew

-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Owen Cunningham
Sent: Wednesday, August 10, 2005 11:31 AM
To: [email protected]
Subject: [Spam:***** SpamScore] Re: [ADVANCED-DOTNET] [Spam:***** SpamScore]
Re: [ADVANCED-DOTNET] Can C# and unmanaged C++ coexist in the same solution?
Same project?

And that can be done all within the same project?

-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Eames, Andrew
Sent: Wednesday, August 10, 2005 11:27 AM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] [Spam:***** SpamScore] Re:
[ADVANCED-DOTNET] Can C# and unmanaged C++ coexist in the same solution?
Same project?

Just make a managed C++ wrapper class with a static member function, the
implementation of which calls your unmanaged function
  Andrew

-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Bob Provencher
Sent: Wednesday, August 10, 2005 11:21 AM
To: [email protected]
Subject: [Spam:***** SpamScore] Re: [ADVANCED-DOTNET] Can C# and unmanaged
C++ coexist in the same solution? Same project?

Off the top of my head I don't think that can be done.

Are you looking for source or binary compatibility?  You could try to come
up with some C++ macros so your C++ code is valid C#, or write some kind of
preprocessor?

-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Owen Cunningham
Sent: Wednesday, August 10, 2005 11:15 AM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Can C# and unmanaged C++ coexist in the same
solution? Same project?

Thanks for the quick response, Bob.

I may have made this more complicated than it needs to be.

I don't really need a full unmanaged C++ class -- I just need an unmanaged
C++ function. I am at a point where I could build a separate DLL that
exports the function and P/Invoke it from C#, but I really want to avoid
having two projects. I'd like to just be able to have my project Foo contain
two source files, Foo.cs and Foo.cpp.

So I guess my question is, what sort of keywords/directives, if any, would I
need to put in my .CPP file to let the compiler/linker make my unmanaged
function public? And what keywords/directives would I need to put in my .CS
file to let my C# code reference the unmanaged function?

-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Bob Provencher
Sent: Wednesday, August 10, 2005 11:06 AM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Can C# and unmanaged C++ coexist in the same
solution? Same project?

I'm not sure about the namespace issue, but you can call unmanaged C++ from
C# in two ways (that I can think of right now) but both require you to
implement some soft of wrapper to call them through interop.

The first is through COM, by wrapping or implementing your C++ classes as
COM objects.

The second is by creating a standard C Api that wraps your objects.
Generally you would need to provide cdecl function for every public method
of your classes and pass the object as a handle or something in the method,
for example (my C++ may be a little rusty):

class Foo
{

        Foo()
        {
        }

        int Use( int param );

}


extern "C" {
HFOO CreateFoo();
int UseFoo( HFOO h, int param );
};

HFOO CreateFoo()
{
        return (HFOO)( new Foo() );
}

int UseFoo( HFOO hfoo, int param )
{
        Foo* p = (Foo*)hfoo;
        return p->Use( param );
}

If you understand the C++ calling conventions and name mangling you may be
able to call directly into methods without the wrapper but I wouldn't
recommend trying that.

-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Owen Cunningham
Sent: Wednesday, August 10, 2005 10:30 AM
To: [email protected]
Subject: [ADVANCED-DOTNET] Can C# and unmanaged C++ coexist in the same
solution? Same project?

I would like to be able to write an unmanaged C++ class, have it reside
within a namespace already defined in my project/solution, and
instantiate/call it from within C# code in the same namespace.

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com



===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com


BEGIN-ANTISPAM-VOTING-LINKS
------------------------------------------------------
Teach CanIt if this mail (ID 4450533) is spam:
Spam:
http://mail-gw.cognex.com/canit/b.php?c=s&i=4450533&m=43715e7d09fc
Not spam:
http://mail-gw.cognex.com/canit/b.php?c=n&i=4450533&m=43715e7d09fc
Forget vote:
http://mail-gw.cognex.com/canit/b.php?c=f&i=4450533&m=43715e7d09fc
------------------------------------------------------
END-ANTISPAM-VOTING-LINKS

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to