【发布时间】:2021-04-05 15:49:05
【问题描述】:
编辑:我想实现 C++(没有限制,使用内在函数、内联、优化),在实现中选择 .NET 上可见的内容(至少 C#)并确实使用它,仅从不可见编译可见资源工作需要什么。
我们可以在 C# 中声明和使用结构和类,但在 C++(或 C++/Cli)中实现它们吗?
现实调整,正确的项目,设置......
第一个文件。 编辑:设置可见内容。
// Random.cs
// Declarations
[StructLayout( Size=8 )] struct Random {
public Random() ;
public Random( long Seed ) ;
public Random( ulong Seed ) ;
public uint randomize { get ; }
public static uint Randomize { get ; }
public int randomize( int Minimal , int Maximal ) ;
public uint randomize( uint Minimal , uint Maximal ) ;
public static int Randomize( int Minimal , int Maximal ) ;
public static uint Randomize( uint Minimal , uint Maximal ) ;
}
第二个文件。 编辑:设置存在的内容(可见的、需要的、不可见的和不需要的)。
// Random.cpp
// Definitions
// +Intrinsics
// +Inlines
# include <intrin.h>
# include <memory.h>
__forceinline unsigned __int64 __generate( void *source ){
// Implementation
}
__forceinline unsigned __int32 __randomize( void *source ){
// Implementation
}
template< typename type > __forceinline type __randomize( void *source , type minimal , type maximal ){
// Implementation
}
Random __global ;
Random::Random(){
unsigned __int64 seed = __rdtsc() ;
memmove( this , &seed , 8 ) ;
}
Random::Random( __int64 seed ){
memmove( this , &seed , 8 ) ;
}
Random::Random( unsigned __int64 seed ){
memmove( this , &seed , 8 ) ;
}
unsigned __int32 Random::randomize::get {
return __randomize( this ) ;
}
unsigned __int32 Random::Randomize::get {
return __randomize( &__global ) ;
}
__int32 Random::randomize( __int32 minimal , __int32 maximal ){
return __randomize( this , minimal , maximal ) ;
}
__int32 Random::Randomize( __int32 minimal , __int32 maximal ){
return __randomize( &__global , minimal , maximal ) ;
}
unsigned __int32 Random::randomize( unsigned __int32 minimal , unsigned __int32 maximal ){
return __randomize( this , minimal , maximal ) ;
}
unsigned __int32 Random::Randomize( unsigned __int32 minimal , unsigned __int32 maximal ){
return __randomize( &__global , minimal , maximal ) ;
}
第三个文件。 编辑:仅使用可见资源,仅编译使用的可见资源(如果只有一种类方法)并且需要将代码转换为可见代码。如果是 dll,则将所有可见的和所有需要的代码编译到它。
// VCsTester.cs
// Application
using System ;
class VCsTester {
static void Main( string[] args ) {
do {
Console.Write( "\b \b\b \b\b \b\b \b\b \b\b\b \b\b \b\b\b \b\b \b\b \b\b\b \b\b \b\b \b\b \b\b \b\b\b \b\b \b\b \b\b \b\b \b\b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b\b \b\b \b\b\b \b\b \b\b \b\b \b\b \b\b\b \b\b \b\b \b\b \b\b \b" ) ;
Console.WriteLine( " Random Value = " + Random.randomize ) ;
Console.Write( "Press space to repeat. Press other key to quit." ) ;
} while( Console.ReadKey( true ).KeyChar == ' ' ) ;
}
}
我们必须使用 C++/CLI 吗? P/调用?没有dll不行吗?
步骤是什么?我发现没有什么比这更明显的了。
【问题讨论】:
-
您可以在这里用葡萄牙语回答:pt.stackoverflow.com/questions/488071
-
制作托管 c++ 应用程序:docs.microsoft.com/en-us/cpp/dotnet/…
-
谢谢,我会看到的。
标签: c# c++ visual-studio c++-cli pinvoke