diff --git a/.gitignore b/.gitignore index 5dd2fc257..1851f67a5 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,8 @@ # Build results [Bb]uild/ +[Bb]uild32/ +[Bb]uild64/ [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ diff --git a/CMakeLists.txt b/CMakeLists.txt index e8bc1fdbb..aa7f42237 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,8 +185,12 @@ set(TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR}) if ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") set(TARGET_ARCH "amd64") + configure_file(k4a.props.in ${CMAKE_CURRENT_SOURCE_DIR}/src/csharp/k4a.x64.props) + configure_file(StubGenerator.xml.in ${CMAKE_CURRENT_SOURCE_DIR}/src/csharp/StubGenerator.x64.xml) elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") set(TARGET_ARCH "x86") + configure_file(k4a.props.in ${CMAKE_CURRENT_SOURCE_DIR}/src/csharp/k4a.x86.props) + configure_file(StubGenerator.xml.in ${CMAKE_CURRENT_SOURCE_DIR}/src/csharp/StubGenerator.x86.xml) else() message(FATAL_ERROR "Unknown architecture with size of void* = ${CMAKE_SIZEOF_VOID_P}") endif() diff --git a/StubGenerator.xml.in b/StubGenerator.xml.in new file mode 100644 index 000000000..a500aa281 --- /dev/null +++ b/StubGenerator.xml.in @@ -0,0 +1,8 @@ + + @PROJECT_BINARY_DIR@ + @PROJ_DIR@ + @CMAKE_CXX_COMPILER@ + @CMAKE_LINKER@ + $ENV{INCLUDE} + $ENV{LIB} + \ No newline at end of file diff --git a/k4a.props.in b/k4a.props.in new file mode 100644 index 000000000..e5cb06b5d --- /dev/null +++ b/k4a.props.in @@ -0,0 +1,5 @@ + + + @PROJECT_BINARY_DIR@ + + \ No newline at end of file diff --git a/src/csharp/.gitignore b/src/csharp/.gitignore new file mode 100644 index 000000000..d20ee89a2 --- /dev/null +++ b/src/csharp/.gitignore @@ -0,0 +1,6 @@ +## Ignore CMake generated files that enable the CSharp solution to find and interact with the CMake built files. + +/k4a.*.props + +/StubGenerator.*.json +/StubGenerator.*.xml diff --git a/src/csharp/K4a.sln b/src/csharp/K4a.sln index effea27bd..a39d7c6bb 100644 --- a/src/csharp/K4a.sln +++ b/src/csharp/K4a.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28407.52 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.572 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AzureKinect.Examples.WPFViewer", "Microsoft.AzureKinect.Examples.WPFViewer\Microsoft.AzureKinect.Examples.WPFViewer.csproj", "{CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}" EndProject @@ -25,122 +25,84 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AzureKinect.Examp EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Debug|x64.ActiveCfg = Debug|Any CPU - {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Debug|x64.Build.0 = Debug|Any CPU - {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Debug|x86.ActiveCfg = Debug|Any CPU - {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Debug|x86.Build.0 = Debug|Any CPU - {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Release|Any CPU.Build.0 = Release|Any CPU - {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Release|x64.ActiveCfg = Release|Any CPU - {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Release|x64.Build.0 = Release|Any CPU - {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Release|x86.ActiveCfg = Release|Any CPU - {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Release|x86.Build.0 = Release|Any CPU - {847B31D5-C253-4766-BF81-032F4670589D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {847B31D5-C253-4766-BF81-032F4670589D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Debug|x64.ActiveCfg = Debug|x64 + {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Debug|x64.Build.0 = Debug|x64 + {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Debug|x86.ActiveCfg = Debug|x86 + {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Debug|x86.Build.0 = Debug|x86 + {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Release|x64.ActiveCfg = Release|x64 + {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Release|x64.Build.0 = Release|x64 + {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Release|x86.ActiveCfg = Release|x86 + {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4}.Release|x86.Build.0 = Release|x86 {847B31D5-C253-4766-BF81-032F4670589D}.Debug|x64.ActiveCfg = Debug|Any CPU {847B31D5-C253-4766-BF81-032F4670589D}.Debug|x64.Build.0 = Debug|Any CPU {847B31D5-C253-4766-BF81-032F4670589D}.Debug|x86.ActiveCfg = Debug|Any CPU {847B31D5-C253-4766-BF81-032F4670589D}.Debug|x86.Build.0 = Debug|Any CPU - {847B31D5-C253-4766-BF81-032F4670589D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {847B31D5-C253-4766-BF81-032F4670589D}.Release|Any CPU.Build.0 = Release|Any CPU {847B31D5-C253-4766-BF81-032F4670589D}.Release|x64.ActiveCfg = Release|Any CPU {847B31D5-C253-4766-BF81-032F4670589D}.Release|x64.Build.0 = Release|Any CPU {847B31D5-C253-4766-BF81-032F4670589D}.Release|x86.ActiveCfg = Release|Any CPU {847B31D5-C253-4766-BF81-032F4670589D}.Release|x86.Build.0 = Release|Any CPU - {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Debug|x64.ActiveCfg = Debug|Any CPU - {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Debug|x64.Build.0 = Debug|Any CPU - {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Debug|x86.ActiveCfg = Debug|Any CPU - {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Debug|x86.Build.0 = Debug|Any CPU - {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Release|Any CPU.Build.0 = Release|Any CPU + {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Debug|x64.ActiveCfg = Debug|x64 + {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Debug|x64.Build.0 = Debug|x64 + {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Debug|x86.ActiveCfg = Debug|x86 + {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Debug|x86.Build.0 = Debug|x86 {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Release|x64.ActiveCfg = Release|x64 {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Release|x64.Build.0 = Release|x64 - {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Release|x86.ActiveCfg = Release|Any CPU - {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Release|x86.Build.0 = Release|Any CPU - {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Debug|x64.ActiveCfg = Debug|Any CPU - {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Debug|x64.Build.0 = Debug|Any CPU - {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Debug|x86.ActiveCfg = Debug|Any CPU - {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Debug|x86.Build.0 = Debug|Any CPU - {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Release|Any CPU.Build.0 = Release|Any CPU - {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Release|x64.ActiveCfg = Release|Any CPU - {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Release|x64.Build.0 = Release|Any CPU - {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Release|x86.ActiveCfg = Release|Any CPU - {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Release|x86.Build.0 = Release|Any CPU - {FCD1E629-1E96-4BDD-A247-35B50F31137A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FCD1E629-1E96-4BDD-A247-35B50F31137A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Release|x86.ActiveCfg = Release|x86 + {41510BD0-7F25-470B-A1DC-12E1DB1AB3B7}.Release|x86.Build.0 = Release|x86 + {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Debug|x64.ActiveCfg = Debug|x64 + {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Debug|x64.Build.0 = Debug|x64 + {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Debug|x86.ActiveCfg = Debug|x86 + {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Debug|x86.Build.0 = Debug|x86 + {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Release|x64.ActiveCfg = Release|x64 + {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Release|x64.Build.0 = Release|x64 + {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Release|x86.ActiveCfg = Release|x86 + {9C78ECE9-FDCF-4E72-979A-6C93E1201DA9}.Release|x86.Build.0 = Release|x86 {FCD1E629-1E96-4BDD-A247-35B50F31137A}.Debug|x64.ActiveCfg = Debug|Any CPU {FCD1E629-1E96-4BDD-A247-35B50F31137A}.Debug|x64.Build.0 = Debug|Any CPU {FCD1E629-1E96-4BDD-A247-35B50F31137A}.Debug|x86.ActiveCfg = Debug|Any CPU {FCD1E629-1E96-4BDD-A247-35B50F31137A}.Debug|x86.Build.0 = Debug|Any CPU - {FCD1E629-1E96-4BDD-A247-35B50F31137A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FCD1E629-1E96-4BDD-A247-35B50F31137A}.Release|Any CPU.Build.0 = Release|Any CPU {FCD1E629-1E96-4BDD-A247-35B50F31137A}.Release|x64.ActiveCfg = Release|Any CPU {FCD1E629-1E96-4BDD-A247-35B50F31137A}.Release|x64.Build.0 = Release|Any CPU {FCD1E629-1E96-4BDD-A247-35B50F31137A}.Release|x86.ActiveCfg = Release|Any CPU {FCD1E629-1E96-4BDD-A247-35B50F31137A}.Release|x86.Build.0 = Release|Any CPU - {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Debug|x64.ActiveCfg = Debug|Any CPU - {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Debug|x64.Build.0 = Debug|Any CPU - {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Debug|x86.ActiveCfg = Debug|Any CPU - {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Debug|x86.Build.0 = Debug|Any CPU - {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Release|Any CPU.Build.0 = Release|Any CPU - {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Release|x64.ActiveCfg = Release|Any CPU - {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Release|x64.Build.0 = Release|Any CPU - {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Release|x86.ActiveCfg = Release|Any CPU - {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Release|x86.Build.0 = Release|Any CPU - {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Debug|x64.ActiveCfg = Debug|Any CPU - {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Debug|x64.Build.0 = Debug|Any CPU - {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Debug|x86.ActiveCfg = Debug|Any CPU - {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Debug|x86.Build.0 = Debug|Any CPU - {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Release|Any CPU.Build.0 = Release|Any CPU - {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Release|x64.ActiveCfg = Release|Any CPU - {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Release|x64.Build.0 = Release|Any CPU - {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Release|x86.ActiveCfg = Release|Any CPU - {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Release|x86.Build.0 = Release|Any CPU - {4762DD42-3CF3-4742-9AEA-5D39781FD2A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4762DD42-3CF3-4742-9AEA-5D39781FD2A6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Debug|x64.ActiveCfg = Debug|x64 + {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Debug|x64.Build.0 = Debug|x64 + {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Debug|x86.ActiveCfg = Debug|x86 + {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Debug|x86.Build.0 = Debug|x86 + {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Release|x64.ActiveCfg = Release|x64 + {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Release|x64.Build.0 = Release|x64 + {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Release|x86.ActiveCfg = Release|x86 + {6D4EC05A-3A81-4B92-8881-96F499F5986B}.Release|x86.Build.0 = Release|x86 + {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Debug|x64.ActiveCfg = Debug|x64 + {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Debug|x64.Build.0 = Debug|x64 + {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Debug|x86.ActiveCfg = Debug|x86 + {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Debug|x86.Build.0 = Debug|x86 + {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Release|x64.ActiveCfg = Release|x64 + {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Release|x64.Build.0 = Release|x64 + {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Release|x86.ActiveCfg = Release|x86 + {E1B3CC41-BC1C-47B7-A6A6-AA50E6994C05}.Release|x86.Build.0 = Release|x86 {4762DD42-3CF3-4742-9AEA-5D39781FD2A6}.Debug|x64.ActiveCfg = Debug|Any CPU {4762DD42-3CF3-4742-9AEA-5D39781FD2A6}.Debug|x64.Build.0 = Debug|Any CPU {4762DD42-3CF3-4742-9AEA-5D39781FD2A6}.Debug|x86.ActiveCfg = Debug|Any CPU {4762DD42-3CF3-4742-9AEA-5D39781FD2A6}.Debug|x86.Build.0 = Debug|Any CPU - {4762DD42-3CF3-4742-9AEA-5D39781FD2A6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4762DD42-3CF3-4742-9AEA-5D39781FD2A6}.Release|Any CPU.Build.0 = Release|Any CPU {4762DD42-3CF3-4742-9AEA-5D39781FD2A6}.Release|x64.ActiveCfg = Release|Any CPU {4762DD42-3CF3-4742-9AEA-5D39781FD2A6}.Release|x64.Build.0 = Release|Any CPU {4762DD42-3CF3-4742-9AEA-5D39781FD2A6}.Release|x86.ActiveCfg = Release|Any CPU {4762DD42-3CF3-4742-9AEA-5D39781FD2A6}.Release|x86.Build.0 = Release|Any CPU - {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Debug|x64.ActiveCfg = Debug|Any CPU - {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Debug|x64.Build.0 = Debug|Any CPU - {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Debug|x86.ActiveCfg = Debug|Any CPU - {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Debug|x86.Build.0 = Debug|Any CPU - {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Release|Any CPU.Build.0 = Release|Any CPU - {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Release|x64.ActiveCfg = Release|Any CPU - {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Release|x64.Build.0 = Release|Any CPU - {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Release|x86.ActiveCfg = Release|Any CPU - {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Release|x86.Build.0 = Release|Any CPU + {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Debug|x64.ActiveCfg = Debug|x64 + {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Debug|x64.Build.0 = Debug|x64 + {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Debug|x86.ActiveCfg = Debug|x86 + {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Debug|x86.Build.0 = Debug|x86 + {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Release|x64.ActiveCfg = Release|x64 + {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Release|x64.Build.0 = Release|x64 + {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Release|x86.ActiveCfg = Release|x86 + {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/csharp/Microsoft.AzureKinect.Examples.WPFViewer/Microsoft.AzureKinect.Examples.WPFViewer.csproj b/src/csharp/Microsoft.AzureKinect.Examples.WPFViewer/Microsoft.AzureKinect.Examples.WPFViewer.csproj index 2cb561db7..602a327e8 100644 --- a/src/csharp/Microsoft.AzureKinect.Examples.WPFViewer/Microsoft.AzureKinect.Examples.WPFViewer.csproj +++ b/src/csharp/Microsoft.AzureKinect.Examples.WPFViewer/Microsoft.AzureKinect.Examples.WPFViewer.csproj @@ -1,9 +1,10 @@  + Debug - AnyCPU + x64 {CCD99E9D-1EE2-41F5-AD3F-4110A466A9A4} WinExe K4aWpfTestApplication @@ -14,23 +15,38 @@ 4 true true + $(BaseOutputPath)$(AssemblyName)\ - - AnyCPU + + x64 true full false - bin\Debug\ DEBUG;TRACE prompt 4 - false - - AnyCPU + + x64 + pdbonly + true + TRACE + prompt + 4 + + + x86 + true + full + false + DEBUG;TRACE + prompt + 4 + + + x86 pdbonly true - bin\Release\ TRACE prompt 4 @@ -106,15 +122,15 @@ - + k4a.dll PreserveNewest - + libusb-1.0.dll PreserveNewest - + depthengine_1_0.dll PreserveNewest diff --git a/src/csharp/Microsoft.AzureKinect.Examples.WinForms/Microsoft.AzureKinect.Examples.WinForms.csproj b/src/csharp/Microsoft.AzureKinect.Examples.WinForms/Microsoft.AzureKinect.Examples.WinForms.csproj index 511343ada..c5d45ccda 100644 --- a/src/csharp/Microsoft.AzureKinect.Examples.WinForms/Microsoft.AzureKinect.Examples.WinForms.csproj +++ b/src/csharp/Microsoft.AzureKinect.Examples.WinForms/Microsoft.AzureKinect.Examples.WinForms.csproj @@ -1,9 +1,10 @@  + Debug - AnyCPU + x64 {8A14FB66-07CD-4E4C-A533-89DE0AFF4FCB} WinExe Microsoft.AzureKinect.Examples.WinForms @@ -12,23 +13,38 @@ 512 true true + $(BaseOutputPath)$(AssemblyName)\ - - AnyCPU + + x64 true full false - bin\Debug\ DEBUG;TRACE prompt 4 - false - - AnyCPU + + x64 + pdbonly + true + TRACE + prompt + 4 + + + x86 + true + full + false + DEBUG;TRACE + prompt + 4 + + + x86 pdbonly true - bin\Release\ TRACE prompt 4 @@ -87,15 +103,15 @@ - + k4a.dll PreserveNewest - + libusb-1.0.dll PreserveNewest - + depthengine_1_0.dll PreserveNewest diff --git a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator.Test/Microsoft.AzureKinect.Test.StubGenerator.Test.csproj b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator.Test/Microsoft.AzureKinect.Test.StubGenerator.Test.csproj index 0f9066dda..e7de62e7f 100644 --- a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator.Test/Microsoft.AzureKinect.Test.StubGenerator.Test.csproj +++ b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator.Test/Microsoft.AzureKinect.Test.StubGenerator.Test.csproj @@ -1,10 +1,21 @@ + netcoreapp2.1 false + + x64;x86 + $(BaseOutputPath)$(AssemblyName)\ + + + + appsettings.xml + PreserveNewest + + diff --git a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator.Test/StubTests.cs b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator.Test/StubTests.cs index 88dbff28b..76eee2c9c 100644 --- a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator.Test/StubTests.cs +++ b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator.Test/StubTests.cs @@ -1,14 +1,14 @@ using System; -using NUnit.Framework; -using System.Runtime.InteropServices; using System.Diagnostics; +using System.Runtime.InteropServices; using Microsoft.AzureKinect.Test.StubGenerator; +using NUnit.Framework; namespace Tests { #pragma warning disable IDE1006 // Naming Styles - class TestNativeMethods + internal class TestNativeMethods { public enum k4a_result_t { @@ -45,13 +45,13 @@ protected override bool ReleaseHandle() public class Tests { - readonly StubbedModule k4a; + private readonly StubbedModule k4a; public Tests() { NativeInterface k4ainterface = NativeInterface.Create( - @"d:\git\Azure-Kinect-Sensor-SDK\build\bin\k4a.dll", - @"D:\git\Azure-Kinect-Sensor-SDK\include\k4a\k4a.h"); + EnvironmentInfo.CalculateFileLocation(@"%K4A_BINARY_DIR%\bin\k4a.dll"), + EnvironmentInfo.CalculateFileLocation(@"%K4A_SOURCE_DIR%\include\k4a\k4a.h")); k4a = StubbedModule.Create("k4a", k4ainterface); } @@ -94,7 +94,7 @@ uint32_t k4a_device_get_installed_count() [Test] public void BasicMarshalling() { - + foreach (UInt32 index in new uint[] { 0, 100, 0xffffffff }) { k4a.SetImplementation($@" diff --git a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/CodeString.cs b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/CodeString.cs index 5902b2941..47815b4e6 100644 --- a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/CodeString.cs +++ b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/CodeString.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Text; namespace Microsoft.AzureKinect.Test.StubGenerator { @@ -22,20 +20,29 @@ private CodeString() /// /// Create a CodeString with some C code /// - /// + /// The C code string to represent. public CodeString(string code) { - AssignCode(code, 2); + AssignCode(code); } private string code = ""; - // Performs the asignment and looks back frameDepth stack frames - // for the origin information - private void AssignCode(string code, int frameDepth) + /// + /// Performs the assignment of the code block and looks through the stack to find the origin information, filename and line number. + /// + /// The C code string to represent. + private void AssignCode(string code) { + int frameDepth = 0; var trace = new System.Diagnostics.StackTrace(true); var frame = trace.GetFrame(frameDepth); + + while (frame.GetMethod().DeclaringType == typeof(CodeString)) + { + frame = trace.GetFrame(++frameDepth); + } + SourceLineNumber = frame.GetFileLineNumber(); SourceFileName = frame.GetFileName(); @@ -50,7 +57,7 @@ public string Code } set { - AssignCode(code, 2); + AssignCode(code); } } @@ -65,7 +72,7 @@ public static implicit operator string(CodeString s) public static implicit operator CodeString(string s) { CodeString c = new CodeString(); - c.AssignCode(s, 2); + c.AssignCode(s); return c; } diff --git a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Compiler.cs b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Compiler.cs index 479a03691..d76e18ed6 100644 --- a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Compiler.cs +++ b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Compiler.cs @@ -1,12 +1,11 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Diagnostics; -using System.Linq; +using System.IO; +using System.Text; namespace Microsoft.AzureKinect.Test.StubGenerator { - class Compiler + internal class Compiler { /// /// Compiles a DLL @@ -15,9 +14,9 @@ class Compiler /// Path of output DLL /// Path of output import .lib /// Compiler Options - public static void CompileModule(string[] sourceFiles, - string outputBinary, - string impLib, + public static void CompileModule(string[] sourceFiles, + string outputBinary, + string impLib, CompilerOptions options = null, string additionalFlags = null, string[] additionalLibraries = null, @@ -26,7 +25,6 @@ public static void CompileModule(string[] sourceFiles, options = options ?? CompilerOptions.GetDefault(); string moduleName = outputBinary; - // Set up compiler arguments StringBuilder compilerArguments = new StringBuilder(); compilerArguments.Append(options.CompilerFlags); @@ -49,17 +47,18 @@ public static void CompileModule(string[] sourceFiles, compilerArguments.Append($" \"{sourceFilePath}\""); } } - foreach (string includePath in options.IncludePaths) + foreach (DirectoryInfo includePath in options.IncludePaths) { - compilerArguments.Append($" \"/I{includePath}\""); + compilerArguments.Append($" \"/I{includePath.FullName}\""); } // Linker options compilerArguments.Append(" /link"); - foreach (string libraryPath in options.LibraryPaths) + foreach (DirectoryInfo libraryPath in options.LibraryPaths) { - compilerArguments.Append($" \"/LIBPATH:{libraryPath}\""); + compilerArguments.Append($" \"/LIBPATH:{libraryPath.FullName}\""); } + compilerArguments.Append($" \"/OUT:{moduleName}\""); if (impLib != null) { @@ -78,10 +77,10 @@ public static void CompileModule(string[] sourceFiles, } // Start the compiler process - ProcessStartInfo startInfo = new ProcessStartInfo(options.CompilerPath) + ProcessStartInfo startInfo = new ProcessStartInfo(options.CompilerPath.FullName) { Arguments = compilerArguments.ToString(), - WorkingDirectory = options.TempPath, + WorkingDirectory = options.TempPath.FullName, RedirectStandardOutput = true }; @@ -99,7 +98,8 @@ public static void CompileModule(string[] sourceFiles, throw new Exception("Compilation failed: " + output); } } - } catch (System.ComponentModel.Win32Exception ex) + } + catch (System.ComponentModel.Win32Exception ex) { if ((uint)ex.ErrorCode == 0x80004005) { diff --git a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/CompilerOptions.cs b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/CompilerOptions.cs index f9edfccd1..7dde1aa21 100644 --- a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/CompilerOptions.cs +++ b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/CompilerOptions.cs @@ -1,121 +1,129 @@ -using System; -using System.Collections.Generic; +using System.IO; using System.Text; namespace Microsoft.AzureKinect.Test.StubGenerator { public class CompilerOptions { - public static CompilerOptions defaultOptions = new CompilerOptions(); - public static CompilerOptions GetDefault() + private static CompilerOptions defaultOptions = new CompilerOptions(); + + public CompilerOptions() { - return defaultOptions; + this.CompilerPath = EnvironmentInfo.CalculateFileLocation(@"%CMAKE_CXX_COMPILER%"); + this.LinkerPath = EnvironmentInfo.CalculateFileLocation(@"%CMAKE_LINKER%"); + this.CompilerFlags = "/DWIN32 /D_WINDOWS /W3 /GR /EHa /Od /Zi"; + + this.Libraries = new string[] + { + "kernel32.lib", + "user32.lib", + "gdi32.lib", + "winspool.lib", + "shell32.lib", + "ole32.lib", + "oleaut32.lib", + "uuid.lib", + "comdlg32.lib", + "advapi32.lib" + }; + + this.IncludePaths = new DirectoryInfo[] + { + EnvironmentInfo.CalculateDirectoryLocation(@"%K4A_SOURCE_DIR%\include"), + EnvironmentInfo.CalculateDirectoryLocation(@"%K4A_BINARY_DIR%\src\sdk\include"), + EnvironmentInfo.CalculateDirectoryLocation(@"%K4A_SOURCE_DIR%\src\csharp\K4aStub") + }; + + this.LibraryPaths = new DirectoryInfo[] { }; + + string baseTempPath = Path.Combine(Path.GetTempPath(), "AzureKinect"); + this.BinaryPath = new DirectoryInfo(Path.Combine(baseTempPath, @"binaries")); + this.TempPath = new DirectoryInfo(Path.Combine(baseTempPath, @"compilation")); + + this.StubFile = new FileInfo("Stub.cpp"); } - public static void SetDefault(CompilerOptions options) + + private CompilerOptions(CompilerOptions other) { - defaultOptions = options; + this.BinaryPath = other.BinaryPath; + this.CompilerFlags = other.CompilerFlags; + this.CompilerPath = other.CompilerPath; + this.IncludePaths = other.IncludePaths; + this.Libraries = other.Libraries; + this.LibraryPaths = other.LibraryPaths; + this.LinkerPath = other.LinkerPath; + this.StubFile = other.StubFile; + this.TempPath = other.TempPath; + this.CodeHeader = other.CodeHeader; } - //public string CompilerPath { get; set; } = @"C:/Program Files (x86)/Microsoft Visual Studio/Preview/Enterprise/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe"; - public string CompilerPath { get; set; } = @"cl.exe"; - //public string LinkerPath { get; set; } = @"C:/Program Files (x86)/Microsoft Visual Studio/Preview/Enterprise/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/link.exe"; - public string LinkerPath { get; set; } = @"link.exe"; - - - public string CompilerFlags { get; set; } = "/DWIN32 /D_WINDOWS /W3 /GR /EHa /Od /Zi"; - - public string[] Libraries { get; set; } = new string[] { - "kernel32.lib", - "user32.lib", - "gdi32.lib", - "winspool.lib", - "shell32.lib", - "ole32.lib", - "oleaut32.lib", - "uuid.lib", - "comdlg32.lib", - "advapi32.lib" - }; - /* - public string[] IncludePaths { get; set; } = new string[] { - @"D:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.20.27027\include", - @"D:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.20.27027\atlmfc\include", - @"D:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Auxiliary\VS\include", - @"C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt", - @"C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um", - @"C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared", - @"C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\winrt", - @"C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\cppwinrt", - @"C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\Include\um", - @"D:\git\Azure-Kinect-Sensor-SDK\include", - @"D:\git\Azure-Kinect-Sensor-SDK\build\src\sdk\include", - @"D:\git\Azure-Kinect-Sensor-SDK\src\csharp\K4aStub" - }; - */ - - public string[] IncludePaths { get; set; } = new string[] { - @"D:\git\Azure-Kinect-Sensor-SDK\include", - @"D:\git\Azure-Kinect-Sensor-SDK\build\src\sdk\include", - @"D:\git\Azure-Kinect-Sensor-SDK\src\csharp\K4aStub" - }; - - /* - public string[] LibraryPaths { get; set; } = new string[] - { - @"D:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.20.27027\lib\x64", - @"D:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.20.27027\atlmfc\lib\x64", - @"D:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Auxiliary\VS\lib\x64", - @"C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\ucrt\x64", - @"C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\um\x64", - @"C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64", - @"C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\Lib\um\x64", - }; - */ - - public string[] LibraryPaths { get; set; } = new string[] { }; - - public string BinaryPath { get; set; } = @"C:\temp\binaries"; - public string TempPath { get; set; } = @"C:\temp\compilation"; - - public string StubFile { get; set; } = "Stub.cpp"; + public FileInfo CompilerPath { get; set; } + + public FileInfo LinkerPath { get; set; } + + public string CompilerFlags { get; set; } + + public string[] Libraries { get; set; } + + public DirectoryInfo[] IncludePaths { get; set; } + + public DirectoryInfo[] LibraryPaths { get; set; } + + public DirectoryInfo BinaryPath { get; set; } + + public DirectoryInfo TempPath { get; set; } + + public FileInfo StubFile { get; set; } + public CodeString CodeHeader { get; set; } = @" #define k4a_EXPORTS #include ""k4a\k4a.h"" "; + public static CompilerOptions GetDefault() + { + return defaultOptions; + } + + public static void SetDefault(CompilerOptions options) + { + defaultOptions = options; + } + // Gets the hash of options that may impact the output of the compiled modules public byte[] GetOptionsHash() { + StringBuilder summaryString = new StringBuilder(); + var md5 = System.Security.Cryptography.MD5.Create(); - byte[] hash = md5.ComputeHash(System.Text.Encoding.Unicode.GetBytes( - CompilerPath + ";" + - CompilerFlags + ";" + - Libraries + ";" + - IncludePaths + ";" + - LibraryPaths - )); + summaryString.AppendFormat("{0};", this.CompilerPath.FullName); + summaryString.AppendFormat("{0};", this.LinkerPath.FullName); + summaryString.AppendFormat("{0};", this.CompilerFlags); + + foreach (string library in this.Libraries) + { + summaryString.AppendFormat("{0};", library); + } + + foreach (DirectoryInfo directory in this.IncludePaths) + { + summaryString.AppendFormat("{0};", directory.FullName); + } + + foreach (DirectoryInfo directory in this.LibraryPaths) + { + summaryString.AppendFormat("{0};", directory.FullName); + } + byte[] hash = md5.ComputeHash(Encoding.Unicode.GetBytes(summaryString.ToString())); return hash; } public CompilerOptions Copy() { - return new CompilerOptions() - { - BinaryPath = this.BinaryPath, - CompilerFlags = this.CompilerFlags, - CompilerPath = this.CompilerPath, - IncludePaths = this.IncludePaths, - Libraries = this.Libraries, - LibraryPaths = this.LibraryPaths, - LinkerPath = this.LinkerPath, - StubFile = this.StubFile, - TempPath = this.TempPath, - CodeHeader = this.CodeHeader - - }; + return new CompilerOptions(this); } } } diff --git a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/EnvironmentInfo.cs b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/EnvironmentInfo.cs new file mode 100644 index 000000000..5144405c5 --- /dev/null +++ b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/EnvironmentInfo.cs @@ -0,0 +1,52 @@ +using System; +using System.IO; +using System.Xml; + +namespace Microsoft.AzureKinect.Test.StubGenerator +{ + public static class EnvironmentInfo + { + private static object SyncRoot = new object(); + private static bool IsInitialized = false; + + public static void LoadEnvironment() + { + if (EnvironmentInfo.IsInitialized) + { + return; + } + + lock (EnvironmentInfo.SyncRoot) + { + if (EnvironmentInfo.IsInitialized) + { + return; + } + + XmlDocument appSettings = new XmlDocument(); + appSettings.Load("appsettings.xml"); + + Environment.SetEnvironmentVariable("K4A_BINARY_DIR", appSettings.DocumentElement["K4A_BINARY_DIR"].InnerXml); + Environment.SetEnvironmentVariable("K4A_SOURCE_DIR", appSettings.DocumentElement["K4A_SOURCE_DIR"].InnerXml); + Environment.SetEnvironmentVariable("CMAKE_CXX_COMPILER", appSettings.DocumentElement["CMAKE_CXX_COMPILER"].InnerXml); + Environment.SetEnvironmentVariable("CMAKE_LINKER", appSettings.DocumentElement["CMAKE_LINKER"].InnerXml); + Environment.SetEnvironmentVariable("INCLUDE", appSettings.DocumentElement["INCLUDE"].InnerXml); + Environment.SetEnvironmentVariable("LIB", appSettings.DocumentElement["LIB"].InnerXml); + + EnvironmentInfo.IsInitialized = true; + } + } + + public static FileInfo CalculateFileLocation(string filename) + { + EnvironmentInfo.LoadEnvironment(); + return new FileInfo(Environment.ExpandEnvironmentVariables(filename)); + } + + public static DirectoryInfo CalculateDirectoryLocation(string filename) + { + EnvironmentInfo.LoadEnvironment(); + return new DirectoryInfo(Environment.ExpandEnvironmentVariables(filename)); + } + } +} diff --git a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Hash.cs b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Hash.cs index d24a64c85..539f4ff29 100644 --- a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Hash.cs +++ b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Hash.cs @@ -1,23 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; +using System.Linq; using System.Runtime.Serialization; +using System.Text; namespace Microsoft.AzureKinect.Test.StubGenerator { /// - /// Hashes an arbitrary object + /// Hashes an arbitrary object. /// - class Hash + internal class Hash { /// - /// Serialize an object to XML and compute its hash + /// Serialize an object to XML and compute its hash. /// /// /// /// - private static byte[] HashSerializedObject(T @object) + private static byte[] HashSerializedObject(T @object) { DataContractSerializer xs = new DataContractSerializer(typeof(T)); using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream()) @@ -32,6 +30,7 @@ private static byte[] HashBytes(byte[] input) var md5 = System.Security.Cryptography.MD5.Create(); return md5.ComputeHash(input); } + private Hash(byte[] hash) { this.hash = hash; @@ -42,11 +41,16 @@ public static Hash GetHash(T @object) return new Hash(HashSerializedObject(@object)); } - public static Hash operator+(Hash left, Hash right) + public static Hash GetHash(CompilerOptions options) + { + return new Hash(options.GetOptionsHash()); + } + + public static Hash operator +(Hash left, Hash right) { return new Hash(HashBytes(left.hash.Concat(right.hash).ToArray())); } - + public static implicit operator string(Hash h) { return h.ToString(); diff --git a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Microsoft.AzureKinect.Test.StubGenerator.csproj b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Microsoft.AzureKinect.Test.StubGenerator.csproj index e11b7f898..8177218b0 100644 --- a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Microsoft.AzureKinect.Test.StubGenerator.csproj +++ b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Microsoft.AzureKinect.Test.StubGenerator.csproj @@ -1,4 +1,5 @@ + netstandard2.0 @@ -15,5 +16,4 @@ PreserveNewest - diff --git a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/ModuleImplementation.cs b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/ModuleImplementation.cs index a6453e0dc..e4f08c73b 100644 --- a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/ModuleImplementation.cs +++ b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/ModuleImplementation.cs @@ -16,13 +16,13 @@ private ModuleImplementation(string path, IntPtr hModule, IReadOnlyDictionary exports = new List(); + if (!System.IO.File.Exists(path)) + { + throw new System.IO.FileNotFoundException("Failed to analyze module, file not found.", path); + } + + if (!options.TempPath.Exists) + { + options.TempPath.Create(); + } + var regex = new System.Text.RegularExpressions.Regex(@"^\s+\d+\s+[\dA-Fa-f]+\s+[0-9A-Fa-f]{8}\s+([^\s]*).*?$", System.Text.RegularExpressions.RegexOptions.Multiline); // Start the compiler process - ProcessStartInfo startInfo = new ProcessStartInfo(options.LinkerPath) + ProcessStartInfo startInfo = new ProcessStartInfo(options.LinkerPath.FullName) { Arguments = $"/dump \"{path}\" /exports", - WorkingDirectory = options.TempPath, + WorkingDirectory = options.TempPath.FullName, RedirectStandardOutput = true, RedirectStandardError = true, RedirectStandardInput = true @@ -54,13 +63,13 @@ public static ModuleInfo Analyze(string path, CompilerOptions options = null) } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine("exception info"); - + System.Diagnostics.Debug.WriteLine(ex, "exception info"); + throw new InvalidOperationException("Failed to analyze module", ex); } return new ModuleInfo(exports.ToArray()); } - - public string[] Exports { get; } + + public string[] Exports { get; } } } diff --git a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/NativeInterface.cs b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/NativeInterface.cs index c6064ff8d..974b7de0d 100644 --- a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/NativeInterface.cs +++ b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/NativeInterface.cs @@ -1,21 +1,21 @@ using System; using System.Collections.Generic; -using System.Text; +using System.IO; using System.Text.RegularExpressions; namespace Microsoft.AzureKinect.Test.StubGenerator { public class NativeInterface { - public NativeInterface(string modulePath, string headerPath, IReadOnlyList functions) + public NativeInterface(FileInfo modulePath, FileInfo headerPath, IReadOnlyList functions) { this.HeaderPath = headerPath; this.ModulePath = modulePath; this.Functions = functions; } - public string HeaderPath { get; } - public string ModulePath { get; } + public FileInfo HeaderPath { get; } + public FileInfo ModulePath { get; } public IReadOnlyList Functions { get; } /// @@ -23,12 +23,12 @@ public NativeInterface(string modulePath, string headerPath, IReadOnlyList /// /// - public static NativeInterface Create(string modulePath, string headerPath) + public static NativeInterface Create(FileInfo modulePath, FileInfo headerPath) { List functions = new List(); // Get the exports from the module - ModuleInfo module = ModuleInfo.Analyze(modulePath); + ModuleInfo module = ModuleInfo.Analyze(modulePath.FullName); List exports = new List(module.Exports); //Regex functionRegex = new Regex(@"^\s*K4A_EXPORT\s+(?\S+)\s+(?[a-zA-Z0-9_]+)\s*\((?[^\)]*)\)", RegexOptions.Multiline); @@ -49,9 +49,7 @@ public static NativeInterface Create(string modulePath, string headerPath) Regex parameterRegex = new Regex(@"^\s*(?.*?)(?[a-zA-Z0-9_]+)\s*$"); - - - using (var header = System.IO.File.OpenText(headerPath)) + using (var header = File.OpenText(headerPath.FullName)) { string headerData = header.ReadToEnd().Replace("\r\n", "\n"); @@ -92,7 +90,7 @@ public static NativeInterface Create(string modulePath, string headerPath) } else { - throw new Exception("Header declares a function not found in module exports"); + throw new Exception($"Header declares a function not found in module exports. Function \"{info.Declaration}\" was not found in exports."); } } } diff --git a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Stub.cpp b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Stub.cpp index 911b5a66a..31854de79 100644 --- a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Stub.cpp +++ b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/Stub.cpp @@ -31,7 +31,7 @@ STUB_EXPORT int Stub_GetCallCount(char *functionName) if (callCount.find(functionName) == callCount.end()) { return 0; - } + } return callCount[functionName]; } diff --git a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/StubbedModule.cs b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/StubbedModule.cs index 8626bcf4e..7fc9ae70b 100644 --- a/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/StubbedModule.cs +++ b/src/csharp/Microsoft.AzureKinect.Test.StubGenerator/StubbedModule.cs @@ -1,27 +1,22 @@ using System; using System.Collections.Generic; -using System.Text; +using System.IO; using System.Linq; -using System.Diagnostics; -using System.Text.RegularExpressions; +using System.Text; namespace Microsoft.AzureKinect.Test.StubGenerator { - - - public class StubbedModule { public CompilerOptions CompilerOptions { get; } - public string ModuleName { get; } + public string ModuleName { get; } - readonly Dictionary currentFunctionImplementations = new Dictionary(); - readonly Dictionary implementedModules = new Dictionary(); + private readonly Dictionary currentFunctionImplementations = new Dictionary(); + private readonly Dictionary implementedModules = new Dictionary(); private void GenerateStub(string modulePath, NativeInterface @interface, CompilerOptions options) { - // Generate the stub function definitions CodeString stubCode = new CodeString(options.CodeHeader); foreach (FunctionInfo def in @interface.Functions) @@ -42,9 +37,9 @@ private void GenerateStub(string modulePath, NativeInterface @interface, Compile } - string sourceFilePath = System.IO.Path.Combine(options.TempPath, "stubfunctions.cpp"); - - using (var filestream = System.IO.File.CreateText(sourceFilePath)) + string sourceFilePath = Path.Combine(options.TempPath.FullName, "stubfunctions.cpp"); + + using (var filestream = File.CreateText(sourceFilePath)) { filestream.WriteLine("#include \"stub.h\""); filestream.WriteLine($"// Defined at {options.CodeHeader.SourceFileName} line {options.CodeHeader.SourceLineNumber}"); @@ -54,15 +49,15 @@ private void GenerateStub(string modulePath, NativeInterface @interface, Compile } - System.IO.File.Copy("Stub.cpp", System.IO.Path.Combine(options.TempPath, "Stub.cpp"), true); - System.IO.File.Copy("Stub.h", System.IO.Path.Combine(options.TempPath, "Stub.h"), true); - System.IO.File.Copy("StubImplementation.h", System.IO.Path.Combine(options.TempPath, "StubImplementation.h"), true); + System.IO.File.Copy("Stub.cpp", Path.Combine(options.TempPath.FullName, "Stub.cpp"), true); + System.IO.File.Copy("Stub.h", Path.Combine(options.TempPath.FullName, "Stub.h"), true); + System.IO.File.Copy("StubImplementation.h", Path.Combine(options.TempPath.FullName, "StubImplementation.h"), true); - string stubImportLib = System.IO.Path.Combine(options.TempPath, "stubimport.lib"); + string stubImportLib = Path.Combine(options.TempPath.FullName, "stubimport.lib"); CompilerOptions modifiedOptions = options.Copy(); modifiedOptions.CompilerFlags += " /DStubExport"; - + Compiler.CompileModule(new string[] { sourceFilePath, "Stub.cpp" }, modulePath, stubImportLib, modifiedOptions); @@ -71,7 +66,7 @@ private void GenerateStub(string modulePath, NativeInterface @interface, Compile _ = NativeMethods.LoadLibrary(modulePath); } - public NativeInterface NativeInterface { get; } + public NativeInterface NativeInterface { get; } private static readonly Dictionary stubbedModules = new Dictionary(); public static StubbedModule Get(string moduleName) @@ -102,34 +97,46 @@ private StubbedModule(string moduleName, NativeInterface @interface, CompilerOpt { throw new Exception("Module name should not include file extension"); } - + this.ModuleName = moduleName; this.CompilerOptions = options; this.NativeInterface = @interface; - try - { - System.IO.Directory.Delete(options.TempPath); - - } catch + if (options.TempPath.Exists) { + try + { + options.TempPath.Delete(true); + options.TempPath.Refresh(); + } + catch (Exception ex) + { + Console.WriteLine("Exception: {0}", ex); + } } - System.IO.Directory.CreateDirectory(options.TempPath); - try - { - System.IO.Directory.Delete(options.BinaryPath); - } - catch + if (options.BinaryPath.Exists) { + try + { + options.BinaryPath.Delete(true); + options.BinaryPath.Refresh(); + } + catch (Exception ex) + { + Console.WriteLine("Exception: {0}", ex); + } } - System.IO.Directory.CreateDirectory(options.BinaryPath); - string executingDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); - string modulePath = System.IO.Path.Combine(executingDirectory, moduleName + ".dll"); - - GenerateStub(modulePath, @interface, options); + options.TempPath.Create(); + options.TempPath.Refresh(); + options.BinaryPath.Create(); + options.BinaryPath.Refresh(); + + string executingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); + string modulePath = Path.Combine(executingDirectory, moduleName + ".dll"); + GenerateStub(modulePath, @interface, options); } internal int GetTotalCallCount(string function) diff --git a/src/csharp/Microsoft.AzureKinect.UnitTests/CalibrationFunctionTests.cs b/src/csharp/Microsoft.AzureKinect.UnitTests/CalibrationFunctionTests.cs index 5060efb13..6423cf656 100644 --- a/src/csharp/Microsoft.AzureKinect.UnitTests/CalibrationFunctionTests.cs +++ b/src/csharp/Microsoft.AzureKinect.UnitTests/CalibrationFunctionTests.cs @@ -1,13 +1,12 @@ -using NUnit.Framework; -using Microsoft.AzureKinect.Test.StubGenerator; -using Microsoft.AzureKinect; +using Microsoft.AzureKinect.Test.StubGenerator; +using NUnit.Framework; namespace Microsoft.AzureKinect.UnitTests { public class CalibrationFunctionTests { - readonly StubbedModule NativeK4a; + private readonly StubbedModule NativeK4a; public CalibrationFunctionTests() { @@ -15,9 +14,8 @@ public CalibrationFunctionTests() if (NativeK4a == null) { NativeInterface k4ainterface = NativeInterface.Create( - @"d:\git\Azure-Kinect-Sensor-SDK\build\bin\k4a.dll", - @"D:\git\Azure-Kinect-Sensor-SDK\include\k4a\k4a.h"); - + EnvironmentInfo.CalculateFileLocation(@"%K4A_BINARY_DIR%\bin\k4a.dll"), + EnvironmentInfo.CalculateFileLocation(@"%K4A_SOURCE_DIR%\include\k4a\k4a.h")); NativeK4a = StubbedModule.Create("k4a", k4ainterface); } @@ -26,7 +24,7 @@ public CalibrationFunctionTests() [Test] public void CalibrationGetFromRaw() { - + } } } diff --git a/src/csharp/Microsoft.AzureKinect.UnitTests/CaptureFunctionTests.cs b/src/csharp/Microsoft.AzureKinect.UnitTests/CaptureFunctionTests.cs index 6d28fa756..517dfc06e 100644 --- a/src/csharp/Microsoft.AzureKinect.UnitTests/CaptureFunctionTests.cs +++ b/src/csharp/Microsoft.AzureKinect.UnitTests/CaptureFunctionTests.cs @@ -1,12 +1,11 @@ -using NUnit.Framework; -using Microsoft.AzureKinect.Test.StubGenerator; -using Microsoft.AzureKinect; +using Microsoft.AzureKinect.Test.StubGenerator; +using NUnit.Framework; namespace Microsoft.AzureKinect.UnitTests { public class CaptureFunctionTests { - readonly StubbedModule NativeK4a; + private readonly StubbedModule NativeK4a; public CaptureFunctionTests() { @@ -14,9 +13,8 @@ public CaptureFunctionTests() if (NativeK4a == null) { NativeInterface k4ainterface = NativeInterface.Create( - @"d:\git\Azure-Kinect-Sensor-SDK\build\bin\k4a.dll", - @"D:\git\Azure-Kinect-Sensor-SDK\include\k4a\k4a.h"); - + EnvironmentInfo.CalculateFileLocation(@"%K4A_BINARY_DIR%\bin\k4a.dll"), + EnvironmentInfo.CalculateFileLocation(@"%K4A_SOURCE_DIR%\include\k4a\k4a.h")); NativeK4a = StubbedModule.Create("k4a", k4ainterface); } @@ -29,7 +27,7 @@ public void Setup() } // Helper function to implement basic open/close behavior - void SetOpenCloseImplementation() + private void SetOpenCloseImplementation() { NativeK4a.SetImplementation(@" @@ -50,7 +48,7 @@ void k4a_device_close(k4a_device_t device_handle) }}"); } - System.WeakReference CreateWithWeakReference(System.Func factory) + private System.WeakReference CreateWithWeakReference(System.Func factory) { return new System.WeakReference(factory()); } diff --git a/src/csharp/Microsoft.AzureKinect.UnitTests/DeviceFunctionTests.cs b/src/csharp/Microsoft.AzureKinect.UnitTests/DeviceFunctionTests.cs index 595bf4cc8..65d07abed 100644 --- a/src/csharp/Microsoft.AzureKinect.UnitTests/DeviceFunctionTests.cs +++ b/src/csharp/Microsoft.AzureKinect.UnitTests/DeviceFunctionTests.cs @@ -1,11 +1,10 @@ -using NUnit.Framework; using Microsoft.AzureKinect.Test.StubGenerator; -using Microsoft.AzureKinect; +using NUnit.Framework; namespace Microsoft.AzureKinect.UnitTests { /// - /// These tests vailidate the calling and marshalling behavior of the native functions in the C# wrapper + /// These tests validate the calling and marshaling behavior of the native functions in the C# wrapper /// /// For any p/invoke function the tests should validate /// a) Input parameters are appropriately passed through @@ -16,7 +15,7 @@ namespace Microsoft.AzureKinect.UnitTests /// public class DeviceFunctionTests { - readonly StubbedModule NativeK4a; + private readonly StubbedModule NativeK4a; public DeviceFunctionTests() { @@ -24,14 +23,13 @@ public DeviceFunctionTests() if (NativeK4a == null) { NativeInterface k4ainterface = NativeInterface.Create( - @"d:\git\Azure-Kinect-Sensor-SDK\build\bin\k4a.dll", - @"D:\git\Azure-Kinect-Sensor-SDK\include\k4a\k4a.h"); - + EnvironmentInfo.CalculateFileLocation(@"%K4A_BINARY_DIR%\bin\k4a.dll"), + EnvironmentInfo.CalculateFileLocation(@"%K4A_SOURCE_DIR%\include\k4a\k4a.h")); NativeK4a = StubbedModule.Create("k4a", k4ainterface); } } - + [SetUp] public void Setup() { @@ -39,7 +37,7 @@ public void Setup() } // Helper function to implement basic open/close behavior - void SetOpenCloseImplementation() + private void SetOpenCloseImplementation() { NativeK4a.SetImplementation(@" @@ -137,8 +135,7 @@ void k4a_device_close(k4a_device_t device_handle) }); } - - System.WeakReference CreateWithWeakReference(System.Func factory) + private System.WeakReference CreateWithWeakReference(System.Func factory) { return new System.WeakReference(factory()); } @@ -152,7 +149,7 @@ public void DeviceGarbageCollection() Assert.AreEqual(0, count.Calls("k4a_device_open")); Assert.AreEqual(0, count.Calls("k4a_device_close")); - + System.WeakReference dev = CreateWithWeakReference(() => { Device d = Device.Open(0); @@ -172,7 +169,7 @@ public void DeviceGarbageCollection() Assert.AreEqual(false, dev.IsAlive); - + // k4a_device_close should have been called automatically Assert.AreEqual(1, count.Calls("k4a_device_open")); Assert.AreEqual(1, count.Calls("k4a_device_close")); @@ -227,7 +224,8 @@ k4a_buffer_result_t k4a_device_get_serialnum(k4a_device_t device_handle, device.Dispose(); - Assert.Throws(typeof(System.ObjectDisposedException), () => { + Assert.Throws(typeof(System.ObjectDisposedException), () => + { _ = device.SerialNum; }); @@ -360,7 +358,7 @@ public void DeviceGetRawCalibrationFailure() { SetOpenCloseImplementation(); - + NativeK4a.SetImplementation(@" k4a_buffer_result_t k4a_device_get_raw_calibration(k4a_device_t device_handle, uint8_t *data, @@ -484,11 +482,11 @@ k4a_result_t k4a_device_get_calibration(k4a_device_t device_handle, k4a_depth_mo for (int i = 0; i < 9; i++) { - Assert.AreEqual((float)i * 1.2f, calibration.depth_camera_calibration.extrinsics.rotation[i]); + Assert.AreEqual(i * 1.2f, calibration.depth_camera_calibration.extrinsics.rotation[i]); } for (int i = 0; i < 3; i++) { - Assert.AreEqual((float)i * 1.3f, calibration.depth_camera_calibration.extrinsics.translation[i]); + Assert.AreEqual(i * 1.3f, calibration.depth_camera_calibration.extrinsics.translation[i]); } Assert.AreEqual(81, calibration.depth_camera_calibration.intrinsics.parameter_count); @@ -496,7 +494,7 @@ k4a_result_t k4a_device_get_calibration(k4a_device_t device_handle, k4a_depth_mo for (int i = 0; i < calibration.depth_camera_calibration.intrinsics.parameters.Length; i++) { - Assert.AreEqual((float)i * 1.4f, calibration.depth_camera_calibration.intrinsics.parameters[i]); + Assert.AreEqual(i * 1.4f, calibration.depth_camera_calibration.intrinsics.parameters[i]); } Assert.AreEqual(91, calibration.depth_camera_calibration.resolution_width); Assert.AreEqual(92, calibration.depth_camera_calibration.resolution_height); @@ -530,7 +528,7 @@ void k4a_device_stop_cameras(k4a_device_t device_handle) STUB_ASSERT(device_handle == (k4a_device_t)0x1234ABCD); } "); - + device.StartCameras(new DeviceConfiguration { ColorResolution = ColorResolution.r1440p, @@ -549,15 +547,15 @@ void k4a_device_stop_cameras(k4a_device_t device_handle) }); device.Dispose(); - + Assert.Throws(typeof(System.ObjectDisposedException), () => { device.GetCalibration(DepthMode.NFOV_Unbinned, ColorResolution.r1440p); }); - + } - + } [Test] @@ -583,7 +581,7 @@ k4a_result_t k4a_device_get_calibration(k4a_device_t device_handle, k4a_depth_mo { Calibration calibration = device.GetCalibration(DepthMode.NFOV_Unbinned, ColorResolution.r1440p); }); - + } } @@ -636,7 +634,7 @@ void k4a_capture_release(k4a_capture_t capture_handle) Assert.AreEqual(0, count.Calls("k4a_capture_release")); capture = device.GetCapture(2345); - + Assert.AreEqual(1, count.Calls("k4a_device_get_capture")); Assert.AreEqual(0, count.Calls("k4a_capture_release")); @@ -653,7 +651,7 @@ void k4a_capture_release(k4a_capture_t capture_handle) } - + } @@ -681,10 +679,11 @@ k4a_wait_result_t k4a_device_get_capture(k4a_device_t device_handle, k4a_capture Assert.AreEqual(0, count.Calls("k4a_device_get_capture")); Assert.AreEqual(0, count.Calls("k4a_capture_release")); - Assert.Throws(typeof(System.TimeoutException), () => { + Assert.Throws(typeof(System.TimeoutException), () => + { using (Capture capture = device.GetCapture(2345)) { - + } }); @@ -732,7 +731,8 @@ k4a_wait_result_t k4a_device_get_capture(k4a_device_t device_handle, k4a_capture Assert.AreEqual(0, count.Calls("k4a_device_get_capture")); Assert.AreEqual(0, count.Calls("k4a_capture_release")); - Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => { + Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => + { using (Capture capture = device.GetCapture(2345)) { @@ -779,7 +779,7 @@ k4a_wait_result_t k4a_device_get_capture(k4a_device_t device_handle, k4a_capture } } - + [Test] public void DeviceSetColorControl() @@ -808,7 +808,8 @@ k4a_result_t k4a_device_set_color_control(k4a_device_t device_handle, k4a_color_ device.Dispose(); - Assert.Throws(typeof(System.ObjectDisposedException), () => { + Assert.Throws(typeof(System.ObjectDisposedException), () => + { device.SetColorControl(ColorControlCommand.PowerlineFrequency, ColorControlMode.Manual, 2345); }); } @@ -837,7 +838,8 @@ k4a_result_t k4a_device_set_color_control(k4a_device_t device_handle, k4a_color_ using (Device device = Device.Open(0)) { Assert.AreEqual(0, count.Calls("k4a_device_set_color_control")); - Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => { + Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => + { device.SetColorControl(ColorControlCommand.PowerlineFrequency, ColorControlMode.Manual, 2345); }); Assert.AreEqual(1, count.Calls("k4a_device_set_color_control")); @@ -918,7 +920,8 @@ k4a_result_t k4a_device_get_color_control(k4a_device_t device_handle, k4a_color_ using (Device device = Device.Open(0)) { Assert.AreEqual(0, count.Calls("k4a_device_get_color_control")); - Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => { + Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => + { device.GetColorControl(ColorControlCommand.PowerlineFrequency, out ColorControlMode mode); }); Assert.AreEqual(1, count.Calls("k4a_device_get_color_control")); @@ -1010,7 +1013,8 @@ k4a_wait_result_t k4a_device_get_imu_sample(k4a_device_t device_handle, k4a_imu_ { Assert.AreEqual(0, count.Calls("k4a_device_get_imu_sample")); - Assert.Throws(typeof(System.TimeoutException), () => { + Assert.Throws(typeof(System.TimeoutException), () => + { ImuSample sample = device.GetImuSample(2345); }); @@ -1040,7 +1044,8 @@ k4a_wait_result_t k4a_device_get_imu_sample(k4a_device_t device_handle, k4a_imu_ { Assert.AreEqual(0, count.Calls("k4a_device_get_imu_sample")); - Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => { + Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => + { ImuSample sample = device.GetImuSample(2345); }); @@ -1151,12 +1156,14 @@ k4a_result_t k4a_device_get_sync_jack( CallCount count = NativeK4a.CountCalls(); using (Device device = Device.Open(0)) { - - Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => { + + Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => + { bool instate = device.SyncInJackConnected; }); - Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => { + Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => + { bool instate = device.SyncOutJackConnected; }); } @@ -1255,7 +1262,8 @@ k4a_result_t k4a_device_get_version( "); { CallCount count = NativeK4a.CountCalls(); - Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => { + Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => + { using (Device device = Device.Open(0)) { HardwareVersion version = device.Version; @@ -1409,7 +1417,7 @@ k4a_device_t device_handle Assert.AreEqual(1, count.Calls("k4a_device_start_imu")); device.Dispose(); - + Assert.Throws(typeof(System.ObjectDisposedException), () => { device.StartImu(); @@ -1437,7 +1445,8 @@ k4a_device_t device_handle CallCount count = NativeK4a.CountCalls(); using (Device device = Device.Open(0)) { - Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => { + Assert.Throws(typeof(Microsoft.AzureKinect.Exception), () => + { device.StartImu(); }); diff --git a/src/csharp/Microsoft.AzureKinect.UnitTests/Microsoft.AzureKinect.UnitTests.csproj b/src/csharp/Microsoft.AzureKinect.UnitTests/Microsoft.AzureKinect.UnitTests.csproj index 7afce0432..2bf1458a9 100644 --- a/src/csharp/Microsoft.AzureKinect.UnitTests/Microsoft.AzureKinect.UnitTests.csproj +++ b/src/csharp/Microsoft.AzureKinect.UnitTests/Microsoft.AzureKinect.UnitTests.csproj @@ -1,10 +1,21 @@  + netcoreapp2.1 false + + x64;x86 + $(BaseOutputPath)$(AssemblyName)\ + + + + appsettings.xml + PreserveNewest + + diff --git a/src/csharp/Microsoft.AzureKinect.WPF/Microsoft.AzureKinect.WPF.csproj b/src/csharp/Microsoft.AzureKinect.WPF/Microsoft.AzureKinect.WPF.csproj index 999117799..ef525769a 100644 --- a/src/csharp/Microsoft.AzureKinect.WPF/Microsoft.AzureKinect.WPF.csproj +++ b/src/csharp/Microsoft.AzureKinect.WPF/Microsoft.AzureKinect.WPF.csproj @@ -1,5 +1,6 @@  + Debug @@ -17,18 +18,18 @@ true full false - bin\Debug\ DEBUG;TRACE prompt 4 + bin\Debug\ pdbonly true - bin\Release\ TRACE prompt 4 + bin\Release\ diff --git a/src/csharp/Microsoft.AzureKinect/Microsoft.AzureKinect.csproj b/src/csharp/Microsoft.AzureKinect/Microsoft.AzureKinect.csproj index 003c39428..56c055fba 100644 --- a/src/csharp/Microsoft.AzureKinect/Microsoft.AzureKinect.csproj +++ b/src/csharp/Microsoft.AzureKinect/Microsoft.AzureKinect.csproj @@ -1,12 +1,13 @@  + netstandard2.0 + latest - + true - D:\git\Azure-Kinect-Sensor-SDK\src\csharp\Microsoft.AzureKinect\Microsoft.AzureKinect.xml + Microsoft.AzureKinect.xml - diff --git a/src/csharp/Microsoft.AzureKinect/NativeMethods.cs b/src/csharp/Microsoft.AzureKinect/NativeMethods.cs index f805dee37..ee8481724 100644 --- a/src/csharp/Microsoft.AzureKinect/NativeMethods.cs +++ b/src/csharp/Microsoft.AzureKinect/NativeMethods.cs @@ -1,7 +1,6 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Runtime.InteropServices; +using System.Text; using Microsoft.AzureKinect.Native; namespace Microsoft.AzureKinect @@ -76,7 +75,7 @@ protected override bool ReleaseHandle() public class k4a_transformation_t : Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid { - private k4a_transformation_t() : base (true) + private k4a_transformation_t() : base(true) { } @@ -185,7 +184,7 @@ public struct k4a_device_configuration_t #region Functions - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_calibration_2d_to_2d( Calibration calibration, @@ -196,7 +195,7 @@ public static extern k4a_result_t k4a_calibration_2d_to_2d( out Float2 target_point2d, out bool valid); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_calibration_2d_to_3d( Calibration calibration, @@ -207,7 +206,7 @@ public static extern k4a_result_t k4a_calibration_2d_to_3d( out Float3 target_point3d, out bool valid); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_calibration_3d_to_2d( Calibration calibration, @@ -217,7 +216,7 @@ public static extern k4a_result_t k4a_calibration_3d_to_2d( out Float2 target_point2d, out bool valid); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_calibration_3d_to_3d( Calibration calibration, @@ -227,7 +226,7 @@ public static extern k4a_result_t k4a_calibration_3d_to_3d( out Float3 target_point3d, out bool valid); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_calibration_get_from_raw( byte[] raw_calibration, @@ -236,23 +235,23 @@ public static extern k4a_result_t k4a_calibration_get_from_raw( ColorResolution color_resolution, out Calibration calibration); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_transformation_t k4a_transformation_create(Calibration calibration); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_transformation_destroy(IntPtr transformation_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_transformation_depth_image_to_color_camera( k4a_transformation_t transformation_handle, k4a_image_t depth_image, k4a_image_t transformed_depth_image); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_transformation_color_image_to_depth_camera( k4a_transformation_t transformation_handle, @@ -260,7 +259,7 @@ public static extern k4a_result_t k4a_transformation_color_image_to_depth_camera k4a_image_t color_image, k4a_image_t transformed_color_image); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_transformation_depth_image_to_point_cloud( k4a_transformation_t transformation_handle, @@ -268,58 +267,58 @@ public static extern k4a_result_t k4a_transformation_depth_image_to_point_cloud( Calibration.DeviceType camera, k4a_image_t xyz_image); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_device_close(IntPtr device_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_capture_create(out k4a_capture_t capture_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_image_t k4a_capture_get_color_image(k4a_capture_t capture_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_image_t k4a_capture_get_depth_image(k4a_capture_t capture_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_image_t k4a_capture_get_ir_image(k4a_capture_t capture_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern float k4a_capture_get_temperature_c(k4a_capture_t capture_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_capture_set_color_image(k4a_capture_t capture_handle, k4a_image_t image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_capture_set_depth_image(k4a_capture_t capture_handle, k4a_image_t image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_capture_set_ir_image(k4a_capture_t capture_handle, k4a_image_t image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_capture_set_temperature_c(k4a_capture_t capture_handle, float temperature_c); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_capture_reference(IntPtr capture_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_capture_release(IntPtr capture_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_image_create(ImageFormat format, int width_pixels, @@ -329,7 +328,7 @@ public static extern k4a_result_t k4a_image_create(ImageFormat format, public delegate void k4a_memory_destroy_cb_t(IntPtr buffer, IntPtr context); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_image_create_from_buffer( ImageFormat format, @@ -343,19 +342,19 @@ public static extern k4a_result_t k4a_image_create_from_buffer( out k4a_image_t image_handle ); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_image_reference(IntPtr image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_image_release(IntPtr image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern UInt32 k4a_device_get_installed_count(); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_device_get_calibration( k4a_device_t device_handle, @@ -364,128 +363,128 @@ public static extern k4a_result_t k4a_device_get_calibration( out Calibration calibration); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_wait_result_t k4a_device_get_capture( k4a_device_t device_handle, out k4a_capture_t capture_handle, Int32 timeout_in_ms); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_wait_result_t k4a_device_get_imu_sample( k4a_device_t device_handle, out ImuSample imu_sample, Int32 timeout_in_ms); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_device_get_sync_jack( k4a_device_t device_handle, out bool sync_in_jack_connected, out bool sync_out_jack_connected); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_device_get_version( k4a_device_t device_handle, out k4a_hardware_version_t version); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_buffer_result_t k4a_device_get_raw_calibration(k4a_device_t device_handle, [Out] byte[] data, ref UIntPtr data_size); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_device_set_color_control(k4a_device_t device_handle, ColorControlCommand command, ColorControlMode mode, Int32 value); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_device_get_color_control(k4a_device_t device_handle, ColorControlCommand command, out ColorControlMode mode, out Int32 value); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_device_start_cameras(k4a_device_t device_handle, k4a_device_configuration_t config); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_device_stop_cameras(k4a_device_t device_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_device_start_imu(k4a_device_t device_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_device_stop_imu(k4a_device_t device_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_result_t k4a_device_open(UInt32 index, out k4a_device_t device_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern k4a_buffer_result_t k4a_device_get_serialnum(k4a_device_t device_handle, StringBuilder serial_number, ref UIntPtr data_size); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern UInt64 k4a_image_get_exposure_usec(k4a_image_t image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_image_set_exposure_time_usec(k4a_image_t image_handle, UInt64 value); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern ImageFormat k4a_image_get_format(k4a_image_t image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern int k4a_image_get_height_pixels(k4a_image_t image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern int k4a_image_get_width_pixels(k4a_image_t image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern int k4a_image_get_stride_bytes(k4a_image_t image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern UIntPtr k4a_image_get_size(k4a_image_t image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern UInt32 k4a_image_get_iso_speed(k4a_image_t image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_image_set_iso_speed(k4a_image_t image_handle, UInt32 value); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern UInt32 k4a_image_get_white_balance(k4a_image_t image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_image_set_white_balance(k4a_image_t image_handle, UInt32 value); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern UInt64 k4a_image_get_timestamp_usec(k4a_image_t image_handle); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern void k4a_image_set_timestamp_usec(k4a_image_t image_handle, UInt64 value); - [DllImport("k4a")] + [DllImport("k4a", CallingConvention = CallingConvention.Cdecl)] [NativeReference] public static extern IntPtr k4a_image_get_buffer(k4a_image_t image_handle); diff --git a/src/csharp/StubValidator/StubValidator.csproj b/src/csharp/StubValidator/StubValidator.csproj index b4c01a7b8..a242a2ccb 100644 --- a/src/csharp/StubValidator/StubValidator.csproj +++ b/src/csharp/StubValidator/StubValidator.csproj @@ -1,9 +1,20 @@  + Exe netcoreapp2.1 + + x64;x86 + $(BaseOutputPath)$(AssemblyName)\ + + + + appsettings.xml + PreserveNewest + + diff --git a/src/csharp/WrapperTests/Microsoft.AzureKinect.FunctionalTests.csproj b/src/csharp/WrapperTests/Microsoft.AzureKinect.FunctionalTests.csproj index 871719f02..d8a245c07 100644 --- a/src/csharp/WrapperTests/Microsoft.AzureKinect.FunctionalTests.csproj +++ b/src/csharp/WrapperTests/Microsoft.AzureKinect.FunctionalTests.csproj @@ -1,21 +1,23 @@ + netcoreapp2.1 false - AnyCPU;x64 + x64;x86 + $(BaseOutputPath)$(AssemblyName)\ - + PreserveNewest - + PreserveNewest - + PreserveNewest diff --git a/src/csharp/k4a.props b/src/csharp/k4a.props new file mode 100644 index 000000000..6c4077eea --- /dev/null +++ b/src/csharp/k4a.props @@ -0,0 +1,16 @@ + + + + + + + + + $(K4aBinaryDirectory)\bin\$(Configuration)\$(Platform)\ + + + \ No newline at end of file