Skip to content

Commit 019983c

Browse files
Merge pull request #21 from Neko-Box-Coder/UpdatedExamples
Updated examples
2 parents 180c27c + 9843855 commit 019983c

File tree

8 files changed

+77
-11
lines changed

8 files changed

+77
-11
lines changed
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1+
#include <string>
12

2-
3-
4-
5-
6-
int TestFunc()
3+
std::string TestFunc()
74
{
8-
return 8;
5+
return "For GCC";
96
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
int TestFunc();
1+
#include <string>
2+
3+
std::string TestFunc();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <string>
2+
3+
std::string TestFunc()
4+
{
5+
return "For MSVC";
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <string>
2+
3+
std::string TestFunc();

Examples/test.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
# Target Profile
1111
"g++":
1212
- "./OtherSources/AnotherSourceFileGcc.cpp"
13-
Default:
14-
- "./AnotherSourceFile.cpp"
15-
- "./AnotherSourceFile2.cpp"
13+
"msvc":
14+
- "./OtherSources/AnotherSourceFileMSVC.cpp"
1615
1716
Defines:
1817
Default:
@@ -54,7 +53,13 @@
5453
#define ssLOG_DLL 1
5554
#include "ssLogger/ssLog.hpp"
5655

57-
#include "./OtherSources/AnotherSourceFileGcc.hpp"
56+
#if defined(__GNUC__)
57+
#include "./OtherSources/AnotherSourceFileGcc.hpp"
58+
#endif
59+
60+
#if defined(_MSC_VER)
61+
#include "./OtherSources/AnotherSourceFileMSVC.hpp"
62+
#endif
5863

5964
#include <iostream>
6065
#include <chrono>

Include/runcpp2/PlatformUtil.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ namespace runcpp2
2424
int& outReturnCode,
2525
std::string runDirectory = "");
2626

27+
#if defined(_WIN32)
28+
std::string GetWindowsError();
29+
#endif
2730

2831
template <typename T>
2932
inline bool HasValueFromPlatformMap(const std::unordered_map<PlatformName, T>& map)

Src/runcpp2/PlatformUtil.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,31 @@ bool runcpp2::RunCommandAndGetOutput( const std::string& command,
127127

128128
return true;
129129
}
130+
131+
132+
#if defined(_WIN32)
133+
//Credit: https://stackoverflow.com/a/17387176
134+
std::string runcpp2::GetWindowsError()
135+
{
136+
//Get the error message ID, if any.
137+
DWORD errorMessageID = ::GetLastError();
138+
if(errorMessageID == 0) {
139+
return std::string(); //No error message has been recorded
140+
}
141+
142+
LPSTR messageBuffer = nullptr;
143+
144+
//Ask Win32 to give us the string version of that message ID.
145+
//The parameters we pass in, tell Win32 to create the buffer that holds the message for us (because we don't yet know how long the message string will be).
146+
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
147+
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
148+
149+
//Copy the error message into a std::string.
150+
std::string message(messageBuffer, size);
151+
152+
//Free the Win32's string's buffer.
153+
LocalFree(messageBuffer);
154+
155+
return message;
156+
}
157+
#endif

Src/runcpp2/runcpp2.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
extern "C" const uint8_t DefaultScriptInfo[];
1919
extern "C" const size_t DefaultScriptInfo_size;
2020

21+
//Use for SetDllDirectory
22+
#if defined(_WIN32)
23+
#ifndef WIN32_LEAN_AND_MEAN
24+
#define WIN32_LEAN_AND_MEAN
25+
#endif
26+
#ifndef NOMINMAX
27+
#define NOMINMAX
28+
#endif
29+
#include <windows.h>
30+
#endif
31+
2132
namespace
2233
{
2334
bool CreateLocalBuildDirectory( const std::string& scriptPath,
@@ -131,6 +142,17 @@ namespace
131142

132143
try
133144
{
145+
//TODO: We might want to use unicode instead for the path
146+
#if defined(_WIN32)
147+
std::string sharedLibDir = compiledSharedLibPath.parent_path().string();
148+
if(SetDllDirectoryA(sharedLibDir.c_str()) == FALSE)
149+
{
150+
std::string lastError = runcpp2::GetWindowsError();
151+
ssLOG_ERROR("Failed to set DLL directory: " << lastError);
152+
return false;
153+
}
154+
#endif
155+
134156
sharedLib = std::unique_ptr<dylib>(new dylib( compiledSharedLibPath.string(),
135157
dylib::no_filename_decorations));
136158
}

0 commit comments

Comments
 (0)