Skip to content

Commit 0f12f0c

Browse files
move dllload and Filherper to shared lib
1 parent 1e91969 commit 0f12f0c

File tree

14 files changed

+288
-35
lines changed

14 files changed

+288
-35
lines changed

Samples/BatchSupport/BatchSupport/BatchSupport.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@
7474
<ClCompile>
7575
<Optimization>Disabled</Optimization>
7676
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
77+
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
7778
</ClCompile>
7879
<Link>
7980
<SubSystem>Console</SubSystem>
8081
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
82+
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\SampleSharedLib\x64\Debug\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
8183
</Link>
8284
</ItemDefinitionGroup>
8385
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
@@ -104,7 +106,6 @@
104106
<ClInclude Include="pch.h" />
105107
</ItemGroup>
106108
<ItemGroup>
107-
<ClCompile Include="dllload.cpp" />
108109
<ClCompile Include="SampleHelper.cpp" />
109110
<ClCompile Include="main.cpp" />
110111
<ClCompile Include="pch.cpp">

Samples/BatchSupport/BatchSupport/BatchSupport.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
<ClCompile Include="SampleHelper.cpp">
3333
<Filter>Source Files</Filter>
3434
</ClCompile>
35-
<ClCompile Include="dllload.cpp">
36-
<Filter>Source Files</Filter>
37-
</ClCompile>
3835
</ItemGroup>
3936
<ItemGroup>
4037
<None Include="packages.config" />

Samples/BatchSupport/BatchSupport/SampleHelper.cpp

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "pch.h"
22
#include "SampleHelper.h"
3-
43
#include "Windows.AI.MachineLearning.Native.h"
54
#include <MemoryBuffer.h>
65
#include <windows.h>
@@ -15,27 +14,9 @@ using namespace winrt::Windows::Graphics::Imaging;
1514
using namespace winrt::Windows::Storage::Streams;
1615
using namespace winrt::Windows::Storage;
1716

18-
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
19-
2017
#define BATCH_SIZE 3
2118

2219
namespace SampleHelper {
23-
std::wstring GetModulePath() {
24-
std::wstring val;
25-
wchar_t modulePath[MAX_PATH] = {0};
26-
GetModuleFileNameW((HINSTANCE)&__ImageBase, modulePath, _countof(modulePath));
27-
wchar_t drive[_MAX_DRIVE];
28-
wchar_t dir[_MAX_DIR];
29-
wchar_t filename[_MAX_FNAME];
30-
wchar_t ext[_MAX_EXT];
31-
_wsplitpath_s(modulePath, drive, _MAX_DRIVE, dir, _MAX_DIR, filename,
32-
_MAX_FNAME, ext, _MAX_EXT);
33-
34-
val = drive;
35-
val += dir;
36-
37-
return val;
38-
}
3920

4021
std::vector<float>
4122
SoftwareBitmapToFloatVector(SoftwareBitmap softwareBitmap) {
@@ -110,10 +91,10 @@ hstring GetModelPath(std::string modelType) {
11091
hstring modelPath;
11192
if (modelType == "fixedBatchSize") {
11293
modelPath =
113-
static_cast<hstring>(GetModulePath().c_str()) + L"SqueezeNet_batch3.onnx";
94+
static_cast<hstring>(FileHelper::GetModulePath().c_str()) + L"SqueezeNet_batch3.onnx";
11495
} else {
11596
modelPath =
116-
static_cast<hstring>(GetModulePath().c_str()) + L"SqueezeNet_free.onnx";
97+
static_cast<hstring>(FileHelper::GetModulePath().c_str()) + L"SqueezeNet_free.onnx";
11798
}
11899
return modelPath;
119100
}
@@ -122,7 +103,7 @@ TensorFloat CreateInputTensorFloat() {
122103
std::vector<hstring> imageNames = {L"fish.png", L"kitten_224.png", L"fish.png"};
123104
std::vector<float> inputVector = {};
124105
for (hstring imageName : imageNames) {
125-
auto imagePath = static_cast<hstring>(GetModulePath().c_str()) + imageName;
106+
auto imagePath = static_cast<hstring>(FileHelper::GetModulePath().c_str()) + imageName;
126107
auto imageFrame = LoadImageFile(imagePath);
127108
std::vector<float> imageVector =
128109
SoftwareBitmapToFloatVector(imageFrame.SoftwareBitmap());
@@ -142,7 +123,7 @@ IVector<VideoFrame> CreateVideoFrames() {
142123
std::vector<hstring> imageNames = { L"fish.png", L"kitten_224.png", L"fish.png" };
143124
std::vector<VideoFrame> inputFrames = {};
144125
for (hstring imageName : imageNames) {
145-
auto imagePath = static_cast<hstring>(GetModulePath().c_str()) + imageName;
126+
auto imagePath = static_cast<hstring>(FileHelper::GetModulePath().c_str()) + imageName;
146127
auto imageFrame = LoadImageFile(imagePath);
147128
inputFrames.emplace_back(imageFrame);
148129
}
@@ -177,7 +158,7 @@ std::vector<std::string> LoadLabels(std::string labelsFilePath) {
177158

178159
void PrintResults(IVectorView<float> results) {
179160
// load the labels
180-
auto modulePath = GetModulePath();
161+
auto modulePath = FileHelper::GetModulePath();
181162
std::string labelsFilePath =
182163
std::string(modulePath.begin(), modulePath.end()) + "Labels.txt";
183164
std::vector<std::string> labels = LoadLabels(labelsFilePath);

Samples/BatchSupport/BatchSupport/SampleHelper.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
#include <unknwn.h>
55
#include <winrt/Windows.Media.h>
66
#include <winrt/Windows.Graphics.Imaging.h>
7+
#include "FileHelper.h"
78

89
namespace SampleHelper
910
{
10-
// Return the path where BatchSupport.exe is located
11-
std::wstring GetModulePath();
12-
1311
// Convert SoftwareBitmap to std::vector<float>
1412
std::vector<float> SoftwareBitmapToFloatVector(
1513
winrt::Windows::Graphics::Imaging::SoftwareBitmap softwareBitmap);

Samples/BatchSupport/BatchSupport/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ string modelType = "freeBatchSize";
1616
string inputType = "TensorFloat";
1717

1818
hstring executionPath =
19-
static_cast<hstring>(SampleHelper::GetModulePath().c_str());
19+
static_cast<hstring>(FileHelper::GetModulePath().c_str());
2020

2121
bool ParseArgs(int argc, char *argv[]);
2222

Samples/BatchSupport/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ This sample tells how to bind and evaluate batches of input in WinML
3333
2. Change the current folder to the folder containing the built EXE (`cd <path-to-exe>`).
3434
3. Run the executable as shown below. Make sure to replace the install location with what matches yours:
3535
```
36-
SqueezeNetObjectDetection.exe [fixedBatchSize|freeBatchSize] [TensorFloat|VideoFrame]
36+
BatchSupport.exe [fixedBatchSize|freeBatchSize] [TensorFloat|VideoFrame]
3737
```
3838
4. You should get output similar to the following:
3939
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.1000
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SampleSharedLib", "SampleSharedLib\SampleSharedLib.vcxproj", "{12103A5B-677A-4286-83D2-54EAB9010C16}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{12103A5B-677A-4286-83D2-54EAB9010C16}.Debug|x64.ActiveCfg = Debug|x64
17+
{12103A5B-677A-4286-83D2-54EAB9010C16}.Debug|x64.Build.0 = Debug|x64
18+
{12103A5B-677A-4286-83D2-54EAB9010C16}.Debug|x86.ActiveCfg = Debug|Win32
19+
{12103A5B-677A-4286-83D2-54EAB9010C16}.Debug|x86.Build.0 = Debug|Win32
20+
{12103A5B-677A-4286-83D2-54EAB9010C16}.Release|x64.ActiveCfg = Release|x64
21+
{12103A5B-677A-4286-83D2-54EAB9010C16}.Release|x64.Build.0 = Release|x64
22+
{12103A5B-677A-4286-83D2-54EAB9010C16}.Release|x86.ActiveCfg = Release|Win32
23+
{12103A5B-677A-4286-83D2-54EAB9010C16}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {5825F592-3D51-4A66-B1E0-44599C7A5C40}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "pch.h"
2+
#include "FileHelper.h"
3+
4+
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
5+
6+
namespace FileHelper {
7+
std::wstring GetModulePath() {
8+
std::wstring val;
9+
wchar_t modulePath[MAX_PATH] = { 0 };
10+
GetModuleFileNameW((HINSTANCE)&__ImageBase, modulePath, _countof(modulePath));
11+
wchar_t drive[_MAX_DRIVE];
12+
wchar_t dir[_MAX_DIR];
13+
wchar_t filename[_MAX_FNAME];
14+
wchar_t ext[_MAX_EXT];
15+
_wsplitpath_s(modulePath, drive, _MAX_DRIVE, dir, _MAX_DIR, filename,
16+
_MAX_FNAME, ext, _MAX_EXT);
17+
18+
val = drive;
19+
val += dir;
20+
21+
return val;
22+
}
23+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
#include <string>
3+
#include <Windows.h>
4+
namespace FileHelper
5+
{
6+
std::wstring GetModulePath();
7+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" 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>15.0</VCProjectVersion>
23+
<ProjectGuid>{12103A5B-677A-4286-83D2-54EAB9010C16}</ProjectGuid>
24+
<Keyword>Win32Proj</Keyword>
25+
<RootNamespace>SampleSharedLib</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>StaticLibrary</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v141</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>StaticLibrary</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v141</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>StaticLibrary</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v141</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>StaticLibrary</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v141</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|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)'=='Debug|x64'">
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)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<LinkIncremental>true</LinkIncremental>
75+
</PropertyGroup>
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
77+
<LinkIncremental>true</LinkIncremental>
78+
</PropertyGroup>
79+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
80+
<LinkIncremental>false</LinkIncremental>
81+
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
83+
<LinkIncremental>false</LinkIncremental>
84+
</PropertyGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
86+
<ClCompile>
87+
<PrecompiledHeader>Use</PrecompiledHeader>
88+
<WarningLevel>Level3</WarningLevel>
89+
<Optimization>Disabled</Optimization>
90+
<SDLCheck>true</SDLCheck>
91+
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
92+
<ConformanceMode>true</ConformanceMode>
93+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
94+
</ClCompile>
95+
<Link>
96+
<SubSystem>Windows</SubSystem>
97+
<GenerateDebugInformation>true</GenerateDebugInformation>
98+
</Link>
99+
</ItemDefinitionGroup>
100+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
101+
<ClCompile>
102+
<PrecompiledHeader>Use</PrecompiledHeader>
103+
<WarningLevel>Level3</WarningLevel>
104+
<Optimization>Disabled</Optimization>
105+
<SDLCheck>true</SDLCheck>
106+
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
107+
<ConformanceMode>true</ConformanceMode>
108+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
109+
<LanguageStandard>stdcpp17</LanguageStandard>
110+
</ClCompile>
111+
<Link>
112+
<SubSystem>Windows</SubSystem>
113+
<GenerateDebugInformation>true</GenerateDebugInformation>
114+
</Link>
115+
</ItemDefinitionGroup>
116+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
117+
<ClCompile>
118+
<PrecompiledHeader>Use</PrecompiledHeader>
119+
<WarningLevel>Level3</WarningLevel>
120+
<Optimization>MaxSpeed</Optimization>
121+
<FunctionLevelLinking>true</FunctionLevelLinking>
122+
<IntrinsicFunctions>true</IntrinsicFunctions>
123+
<SDLCheck>true</SDLCheck>
124+
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
125+
<ConformanceMode>true</ConformanceMode>
126+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
127+
</ClCompile>
128+
<Link>
129+
<SubSystem>Windows</SubSystem>
130+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
131+
<OptimizeReferences>true</OptimizeReferences>
132+
<GenerateDebugInformation>true</GenerateDebugInformation>
133+
</Link>
134+
</ItemDefinitionGroup>
135+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
136+
<ClCompile>
137+
<PrecompiledHeader>Use</PrecompiledHeader>
138+
<WarningLevel>Level3</WarningLevel>
139+
<Optimization>MaxSpeed</Optimization>
140+
<FunctionLevelLinking>true</FunctionLevelLinking>
141+
<IntrinsicFunctions>true</IntrinsicFunctions>
142+
<SDLCheck>true</SDLCheck>
143+
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
144+
<ConformanceMode>true</ConformanceMode>
145+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
146+
</ClCompile>
147+
<Link>
148+
<SubSystem>Windows</SubSystem>
149+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
150+
<OptimizeReferences>true</OptimizeReferences>
151+
<GenerateDebugInformation>true</GenerateDebugInformation>
152+
</Link>
153+
</ItemDefinitionGroup>
154+
<ItemGroup>
155+
<ClInclude Include="FileHelper.h" />
156+
<ClInclude Include="pch.h" />
157+
</ItemGroup>
158+
<ItemGroup>
159+
<ClCompile Include="dllload.cpp" />
160+
<ClCompile Include="FileHelper.cpp" />
161+
<ClCompile Include="pch.cpp">
162+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
163+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
164+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
165+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
166+
</ClCompile>
167+
</ItemGroup>
168+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
169+
<ImportGroup Label="ExtensionTargets">
170+
</ImportGroup>
171+
</Project>

0 commit comments

Comments
 (0)