Skip to content

Commit c563979

Browse files
Merge pull request #305 from microsoft/user/xianz/SharedLib
move dllload and Filherper to shared lib
2 parents 1e91969 + a0f0019 commit c563979

19 files changed

+301
-149
lines changed

Samples/BatchSupport/BatchSupport/BatchSupport.vcxproj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,37 +74,46 @@
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\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
8183
</Link>
8284
</ItemDefinitionGroup>
8385
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
8486
<ClCompile>
8587
<PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
88+
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
8689
</ClCompile>
90+
<Link>
91+
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\SampleSharedLib\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
92+
</Link>
8793
</ItemDefinitionGroup>
8894
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
8995
<ClCompile>
9096
<Optimization>MaxSpeed</Optimization>
9197
<FunctionLevelLinking>true</FunctionLevelLinking>
9298
<IntrinsicFunctions>true</IntrinsicFunctions>
9399
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
100+
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
101+
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
94102
</ClCompile>
95103
<Link>
96104
<SubSystem>Console</SubSystem>
97105
<EnableCOMDATFolding>true</EnableCOMDATFolding>
98106
<OptimizeReferences>true</OptimizeReferences>
99107
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
108+
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\SampleSharedLib\x64\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
109+
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\SampleSharedLib\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
100110
</Link>
101111
</ItemDefinitionGroup>
102112
<ItemGroup>
103113
<ClInclude Include="SampleHelper.h" />
104114
<ClInclude Include="pch.h" />
105115
</ItemGroup>
106116
<ItemGroup>
107-
<ClCompile Include="dllload.cpp" />
108117
<ClCompile Include="SampleHelper.cpp" />
109118
<ClCompile Include="main.cpp" />
110119
<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+
}

Samples/SqueezeNetObjectDetection/Desktop/cpp/Filehelper.h renamed to Samples/SampleSharedLib/SampleSharedLib/FileHelper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#include <Windows.h>
44
namespace FileHelper
55
{
6-
std::string GetModulePath();
7-
}
6+
std::wstring GetModulePath();
7+
}

0 commit comments

Comments
 (0)