Skip to content

Commit 3b0cb65

Browse files
committed
init
0 parents  commit 3b0cb65

12 files changed

+461
-0
lines changed

Diff for: .gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/src/CSharpLibrary/bin
2+
/src/CSharpLibrary/obj
3+
/src/NativeWrapper/Debug
4+
/src/NativeWrapper/x64
5+
/src/NativeWrapper/*.user
6+
/src/TestApp/obj
7+
/src/TestApp/bin
8+
/.vs
9+
/src/NativeWrapper/Win32

Diff for: GenericsCppCLI.sln

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30709.132
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpLibrary", "src\CSharpLibrary\CSharpLibrary.csproj", "{B833D715-F283-43A0-B975-66D0193C7EAB}"
7+
EndProject
8+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NativeWrapper", "src\NativeWrapper\NativeWrapper.vcxproj", "{856E383D-C1D4-46AD-B18E-1481C1052D1E}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "src\TestApp\TestApp.csproj", "{32FC0540-8ACA-413E-9872-757C84614BD4}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|x64 = Debug|x64
15+
Debug|x86 = Debug|x86
16+
Release|x64 = Release|x64
17+
Release|x86 = Release|x86
18+
EndGlobalSection
19+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20+
{B833D715-F283-43A0-B975-66D0193C7EAB}.Debug|x64.ActiveCfg = Debug|Any CPU
21+
{B833D715-F283-43A0-B975-66D0193C7EAB}.Debug|x64.Build.0 = Debug|Any CPU
22+
{B833D715-F283-43A0-B975-66D0193C7EAB}.Debug|x86.ActiveCfg = Debug|Any CPU
23+
{B833D715-F283-43A0-B975-66D0193C7EAB}.Debug|x86.Build.0 = Debug|Any CPU
24+
{B833D715-F283-43A0-B975-66D0193C7EAB}.Release|x64.ActiveCfg = Release|Any CPU
25+
{B833D715-F283-43A0-B975-66D0193C7EAB}.Release|x64.Build.0 = Release|Any CPU
26+
{B833D715-F283-43A0-B975-66D0193C7EAB}.Release|x86.ActiveCfg = Release|Any CPU
27+
{B833D715-F283-43A0-B975-66D0193C7EAB}.Release|x86.Build.0 = Release|Any CPU
28+
{856E383D-C1D4-46AD-B18E-1481C1052D1E}.Debug|x64.ActiveCfg = Debug|x64
29+
{856E383D-C1D4-46AD-B18E-1481C1052D1E}.Debug|x64.Build.0 = Debug|x64
30+
{856E383D-C1D4-46AD-B18E-1481C1052D1E}.Debug|x86.ActiveCfg = Debug|Win32
31+
{856E383D-C1D4-46AD-B18E-1481C1052D1E}.Debug|x86.Build.0 = Debug|Win32
32+
{856E383D-C1D4-46AD-B18E-1481C1052D1E}.Release|x64.ActiveCfg = Release|x64
33+
{856E383D-C1D4-46AD-B18E-1481C1052D1E}.Release|x64.Build.0 = Release|x64
34+
{856E383D-C1D4-46AD-B18E-1481C1052D1E}.Release|x86.ActiveCfg = Release|Win32
35+
{856E383D-C1D4-46AD-B18E-1481C1052D1E}.Release|x86.Build.0 = Release|Win32
36+
{32FC0540-8ACA-413E-9872-757C84614BD4}.Debug|x64.ActiveCfg = Debug|x64
37+
{32FC0540-8ACA-413E-9872-757C84614BD4}.Debug|x64.Build.0 = Debug|x64
38+
{32FC0540-8ACA-413E-9872-757C84614BD4}.Debug|x86.ActiveCfg = Debug|x64
39+
{32FC0540-8ACA-413E-9872-757C84614BD4}.Debug|x86.Build.0 = Debug|x64
40+
{32FC0540-8ACA-413E-9872-757C84614BD4}.Release|x64.ActiveCfg = Release|x64
41+
{32FC0540-8ACA-413E-9872-757C84614BD4}.Release|x64.Build.0 = Release|x64
42+
{32FC0540-8ACA-413E-9872-757C84614BD4}.Release|x86.ActiveCfg = Release|x86
43+
{32FC0540-8ACA-413E-9872-757C84614BD4}.Release|x86.Build.0 = Release|x86
44+
EndGlobalSection
45+
GlobalSection(SolutionProperties) = preSolution
46+
HideSolutionNode = FALSE
47+
EndGlobalSection
48+
GlobalSection(ExtensibilityGlobals) = postSolution
49+
SolutionGuid = {E67B2EA2-B4AD-4BAB-B1A1-3B7BD4AF972D}
50+
EndGlobalSection
51+
EndGlobal

Diff for: src/CSharpLibrary/CSharpLibrary.csproj

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>

Diff for: src/CSharpLibrary/Vector.cs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace CSharpLibrary
5+
{
6+
public struct Vector<T>
7+
{
8+
public T[] Data;
9+
public int Offset;
10+
public int Stride;
11+
public int Count;
12+
13+
public Vector(int count)
14+
{
15+
Data = new T[count];
16+
Count = count;
17+
Stride = 1;
18+
Offset = 0;
19+
}
20+
21+
// Comment this to resolve error C2079 when compiling the C++/CLI project
22+
public IEnumerable<T> Elements
23+
{
24+
get
25+
{
26+
var i = Offset;
27+
var step = Stride;
28+
for (int xe = i + Count * Stride; i != xe; i += step)
29+
yield return Data[i];
30+
}
31+
}
32+
33+
// Workaround for compile error C2079
34+
public IEnumerable<T> ElementsWithHelper
35+
{
36+
get { return Helper(Data, Offset, Stride, Count); }
37+
}
38+
39+
static IEnumerable<T> Helper(T[] data, int offset, int stride, int count)
40+
{
41+
var i = offset;
42+
for (int xe = i + count * stride; i != xe; i += stride)
43+
yield return data[i];
44+
}
45+
}
46+
}

Diff for: src/NativeWrapper/NativeWrapper.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "NativeWrapper.h"
2+
3+
void NativeWrapper::MyWrapper::Process(Vector<float>^ vec)
4+
{
5+
auto cnt = vec->Count; // this line causes compile error C2079
6+
Console::WriteLine("Processing {0} elements", cnt);
7+
}

Diff for: src/NativeWrapper/NativeWrapper.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
using namespace System;
4+
using namespace CSharpLibrary;
5+
6+
namespace NativeWrapper {
7+
public ref class MyWrapper
8+
{
9+
public:
10+
MyWrapper() {}
11+
12+
void Process(Vector<float>^ vec);
13+
};
14+
}

Diff for: src/NativeWrapper/NativeWrapper.vcxproj

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<ProjectGuid>{856E383D-C1D4-46AD-B18E-1481C1052D1E}</ProjectGuid>
24+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
25+
<Keyword>ManagedCProj</Keyword>
26+
<RootNamespace>NativeWrapper</RootNamespace>
27+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
28+
</PropertyGroup>
29+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
30+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
31+
<ConfigurationType>DynamicLibrary</ConfigurationType>
32+
<UseDebugLibraries>true</UseDebugLibraries>
33+
<PlatformToolset>v142</PlatformToolset>
34+
<CLRSupport>true</CLRSupport>
35+
<CharacterSet>Unicode</CharacterSet>
36+
</PropertyGroup>
37+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
38+
<ConfigurationType>DynamicLibrary</ConfigurationType>
39+
<UseDebugLibraries>false</UseDebugLibraries>
40+
<PlatformToolset>v142</PlatformToolset>
41+
<CLRSupport>true</CLRSupport>
42+
<CharacterSet>Unicode</CharacterSet>
43+
</PropertyGroup>
44+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
45+
<ConfigurationType>DynamicLibrary</ConfigurationType>
46+
<UseDebugLibraries>true</UseDebugLibraries>
47+
<PlatformToolset>v142</PlatformToolset>
48+
<CLRSupport>true</CLRSupport>
49+
<CharacterSet>Unicode</CharacterSet>
50+
</PropertyGroup>
51+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
52+
<ConfigurationType>DynamicLibrary</ConfigurationType>
53+
<UseDebugLibraries>false</UseDebugLibraries>
54+
<PlatformToolset>v142</PlatformToolset>
55+
<CLRSupport>true</CLRSupport>
56+
<CharacterSet>Unicode</CharacterSet>
57+
</PropertyGroup>
58+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
59+
<ImportGroup Label="ExtensionSettings">
60+
</ImportGroup>
61+
<ImportGroup Label="Shared">
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
73+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
74+
</ImportGroup>
75+
<PropertyGroup Label="UserMacros" />
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
77+
<OutDir>$(ProjectDir)$(Platform)\$(Configuration)\</OutDir>
78+
</PropertyGroup>
79+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
80+
<OutDir>$(ProjectDir)$(Platform)\$(Configuration)\</OutDir>
81+
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
83+
<IntDir>$(Platform)\$(Configuration)\</IntDir>
84+
<OutDir>$(ProjectDir)$(Platform)\$(Configuration)\</OutDir>
85+
</PropertyGroup>
86+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
87+
<IntDir>$(Platform)\$(Configuration)\</IntDir>
88+
<OutDir>$(ProjectDir)$(Platform)\$(Configuration)\</OutDir>
89+
</PropertyGroup>
90+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
91+
<ClCompile>
92+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
93+
<PrecompiledHeaderFile>
94+
</PrecompiledHeaderFile>
95+
<WarningLevel>Level3</WarningLevel>
96+
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
97+
</ClCompile>
98+
<Link>
99+
<AdditionalDependencies />
100+
</Link>
101+
</ItemDefinitionGroup>
102+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
103+
<ClCompile>
104+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
105+
<PrecompiledHeaderFile>
106+
</PrecompiledHeaderFile>
107+
<WarningLevel>Level3</WarningLevel>
108+
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
109+
</ClCompile>
110+
<Link>
111+
<AdditionalDependencies />
112+
</Link>
113+
</ItemDefinitionGroup>
114+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
115+
<ClCompile>
116+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
117+
<PrecompiledHeaderFile>
118+
</PrecompiledHeaderFile>
119+
<WarningLevel>Level3</WarningLevel>
120+
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
121+
</ClCompile>
122+
<Link>
123+
<AdditionalDependencies />
124+
</Link>
125+
</ItemDefinitionGroup>
126+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
127+
<ClCompile>
128+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
129+
<PrecompiledHeaderFile>
130+
</PrecompiledHeaderFile>
131+
<WarningLevel>Level3</WarningLevel>
132+
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
133+
</ClCompile>
134+
<Link>
135+
<AdditionalDependencies />
136+
</Link>
137+
</ItemDefinitionGroup>
138+
<ItemGroup>
139+
<ClInclude Include="NativeWrapper.h" />
140+
</ItemGroup>
141+
<ItemGroup>
142+
<ClCompile Include="NativeWrapper.cpp" />
143+
</ItemGroup>
144+
<ItemGroup>
145+
<Reference Include="System" />
146+
<Reference Include="System.Data" />
147+
<Reference Include="System.Xml" />
148+
</ItemGroup>
149+
<ItemGroup>
150+
<ProjectReference Include="..\CSharpLibrary\CSharpLibrary.csproj">
151+
<Project>{b833d715-f283-43a0-b975-66d0193c7eab}</Project>
152+
</ProjectReference>
153+
</ItemGroup>
154+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
155+
<ImportGroup Label="ExtensionTargets">
156+
</ImportGroup>
157+
</Project>

Diff for: src/NativeWrapper/NativeWrapper.vcxproj.filters

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="NativeWrapper.h">
19+
<Filter>Header Files</Filter>
20+
</ClInclude>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClCompile Include="NativeWrapper.cpp">
24+
<Filter>Source Files</Filter>
25+
</ClCompile>
26+
</ItemGroup>
27+
</Project>

Diff for: src/TestApp/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
5+
</startup>
6+
</configuration>

Diff for: src/TestApp/Program.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using CSharpLibrary;
2+
using NativeWrapper;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace TestApp
10+
{
11+
class Program
12+
{
13+
static void Main(string[] args)
14+
{
15+
var ext = new MyWrapper();
16+
var vec = new Vector<float>(100);
17+
ext.Process(vec);
18+
Console.ReadKey();
19+
}
20+
}
21+
}

Diff for: src/TestApp/Properties/AssemblyInfo.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("TestApp")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("TestApp")]
13+
[assembly: AssemblyCopyright("Copyright © 2020")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("32fc0540-8aca-413e-9872-757c84614bd4")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)