Re: Including C# file in a VC++.NET project
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Mon, 5 Dec 2005 13:49:02 +0100
"Holger Grund" <hg@xxxxxxxxxxxxxxx> wrote in message
news:%23R2is7S%23FHA.472@xxxxxxxxxxxxxxxxxxxxxxx
> "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx> wrote
>
>> This doesn't work:
>>> csc /t:module csmod.cs /r:cppmod.netmodule
>> can't work, cppmod.netmodule is not an assembly, you should use
>> /addmodule:cppmod.netmodule
> Oh, I see. But that's a crappy implementation in C#. Netmodules
> carry the metadata and I just want to pull the definitions.
>
Not sure if I'm following here, the /r option is used to add a "reference"
to an assembly, but a "netmodule" is not an assembly, it doesn't carry an
"assembly manifest" in it's metadata.
The reason that /addmodule fails to add a 'non-safe' netmodule to an assemby
(module) is that C# doesn't allow you to 'produce' non verifiable assemblies
(modules), I would not call this crapy.
> "/addmodule" is not what I want. The C++ linker should be
> able to resolve metadata references (so there's only one
> module with CLR metadata)
>
> Just remove the /NOASSEMBLY and use a reference to
>
> Ok, here's an example (with some trickery to resolve the recursive
> dependencies, the entry point should, OC be provided by the
> CRT for unsafe code)
>
> // cppmod.cpp
> public ref struct CPlusPlus {
> static void Func() {
> System::Console::WriteLine(__FUNCTION__);
> }
> };
>
> #ifdef FINAL
> #using "csmod.netmodule"
> int main(){
> CSharp::Main();
> }
> #endif
>
> // csmod.cs
> class CSharp {
> internal static void Main() {
> System.Console.WriteLine("CSharp.Main 1");
> CPlusPlus.Func();
> System.Console.WriteLine("CSharp.Main 2");
> }
> }
>
> // build with
> cl /c /clr cppmod.cpp
> link /DLL cppmod.obj
Well, here you built a full assembly (the matadata contains the assembly
manifest), this makes the csc happy, csmod.netmodule only has an external
reference to the cppmod.dll.
> csc /t:module /r:cppmod.dll csmod.cs
> cl /c /DFINAL /clr cppmod.cpp
> link /LTCG cppmod.obj csmod.netmodule
>
Ok, using this trick you can build a mixed mode (non verifiable) assembly.
Note, I did add the following at the end of the build, in order to get rid
of the manifest and netmodule files.
mt -manifest cppmod.exe.manifest /nologo /outputresource:"cppmod.exe;#2"
del *.manifest
del *.netmodule
> I'm not sure whether the C# can really import assembly
> scope definitions (may it can be tricked with the friends attribute).
>
Shouldn't be a problem, see if I have some sample hanging arround.
Willy.
.
- References:
- Including C# file in a VC++.NET project
- From: David Ching
- Re: Including C# file in a VC++.NET project
- From: Willy Denoyette [MVP]
- Re: Including C# file in a VC++.NET project
- From: Holger Grund
- Re: Including C# file in a VC++.NET project
- From: Willy Denoyette [MVP]
- Re: Including C# file in a VC++.NET project
- From: Holger Grund
- Including C# file in a VC++.NET project
- Prev by Date: Re: Followup: Native win32 apps still require .NET runtime?
- Next by Date: Re: Followup: Native win32 apps still require .NET runtime?
- Previous by thread: Re: Including C# file in a VC++.NET project
- Next by thread: Re: Including C# file in a VC++.NET project
- Index(es):
Relevant Pages
|