OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
OrcaSlicer_app_msvc.cpp File Reference
#include <Windows.h>
#include <shellapi.h>
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <vector>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/constants.hpp>
Include dependency graph for OrcaSlicer_app_msvc.cpp:

Go to the source code of this file.

Macros

#define _WIN32_WINNT   0x0502
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX

Typedefs

typedef int(__stdcall * Slic3rMainFunc) (int argc, wchar_t **argv)

Functions

int wmain (int argc, wchar_t **argv)

Variables

Slic3rMainFunc orcaslicer_main = nullptr

Macro Definition Documentation

◆ _WIN32_WINNT

#define _WIN32_WINNT   0x0502

◆ NOMINMAX

#define NOMINMAX

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Typedef Documentation

◆ Slic3rMainFunc

typedef int(__stdcall * Slic3rMainFunc) (int argc, wchar_t **argv)

Function Documentation

◆ wmain()

int wmain ( int argc,
wchar_t ** argv )
221{
222#endif
223 // Allow the asserts to open message box, such message box allows to ignore the assert and continue with the application.
224 // Without this call, the seemingly same message box is being opened by the abort() function, but that is too late and
225 // the application will be killed even if "Ignore" button is pressed.
226 _set_error_mode(_OUT_TO_MSGBOX);
227
228 std::vector<wchar_t*> argv_extended;
229 argv_extended.emplace_back(argv[0]);
230
231#ifdef SLIC3R_WRAPPER_GCODEVIEWER
232 wchar_t gcodeviewer_param[] = L"--gcodeviewer";
233 argv_extended.emplace_back(gcodeviewer_param);
234#endif /* SLIC3R_WRAPPER_GCODEVIEWER */
235
236#ifdef SLIC3R_GUI
237 // Here one may push some additional parameters based on the wrapper type.
238 bool force_mesa = false;
239#endif /* SLIC3R_GUI */
240 for (int i = 1; i < argc; ++ i) {
241#ifdef SLIC3R_GUI
242 if (wcscmp(argv[i], L"--sw-renderer") == 0)
243 force_mesa = true;
244 else if (wcscmp(argv[i], L"--no-sw-renderer") == 0)
245 force_mesa = false;
246#endif /* SLIC3R_GUI */
247 argv_extended.emplace_back(argv[i]);
248 }
249 argv_extended.emplace_back(nullptr);
250
251#ifdef SLIC3R_GUI
252 OpenGLVersionCheck opengl_version_check;
253 bool load_mesa =
254 // Forced from the command line.
255 force_mesa ||
256 // Try to load the default OpenGL driver and test its context version.
257 ! opengl_version_check.load_opengl_dll() || ! opengl_version_check.is_version_greater_or_equal_to(2, 0);
258#endif /* SLIC3R_GUI */
259
260 wchar_t path_to_exe[MAX_PATH + 1] = { 0 };
261 ::GetModuleFileNameW(nullptr, path_to_exe, MAX_PATH);
262 wchar_t drive[_MAX_DRIVE];
263 wchar_t dir[_MAX_DIR];
264 wchar_t fname[_MAX_FNAME];
265 wchar_t ext[_MAX_EXT];
266 _wsplitpath(path_to_exe, drive, dir, fname, ext);
267 _wmakepath(path_to_exe, drive, dir, nullptr, nullptr);
268
269 wchar_t path_to_python[MAX_PATH + 1] = { 0 };
270 wcscpy(path_to_python, path_to_exe);
271 wcscat(path_to_python, L"python");
272 DWORD python_attrs = GetFileAttributesW(path_to_python);
273 if (python_attrs != INVALID_FILE_ATTRIBUTES && (python_attrs & FILE_ATTRIBUTE_DIRECTORY)) {
274 SetDllDirectoryW(path_to_python);
275 }
276
277#ifdef SLIC3R_GUI
278// https://wiki.qt.io/Cross_compiling_Mesa_for_Windows
279// http://download.qt.io/development_releases/prebuilt/llvmpipe/windows/
280 if (load_mesa) {
281 opengl_version_check.unload_opengl_dll();
282 wchar_t path_to_mesa[MAX_PATH + 1] = { 0 };
283 wcscpy(path_to_mesa, path_to_exe);
284 wcscat(path_to_mesa, L"mesa\\opengl32.dll");
285 printf("Loading MESA OpenGL library: %S\n", path_to_mesa);
286 HINSTANCE hInstance_OpenGL = LoadLibraryExW(path_to_mesa, nullptr, 0);
287 if (hInstance_OpenGL == nullptr) {
288 printf("MESA OpenGL library was not loaded\n");
289 } else
290 printf("MESA OpenGL library was loaded successfully\n");
291 }
292#endif /* SLIC3R_GUI */
293
294
295 wchar_t path_to_slic3r[MAX_PATH + 1] = { 0 };
296 wcscpy(path_to_slic3r, path_to_exe);
297 wcscat(path_to_slic3r, L"OrcaSlicer.dll");
298// printf("Loading Slic3r library: %S\n", path_to_slic3r);
299 HINSTANCE hInstance_Slic3r = LoadLibraryExW(path_to_slic3r, nullptr, 0);
300 if (hInstance_Slic3r == nullptr) {
301 printf("OrcaSlicer.dll was not loaded, error=%lu\n", GetLastError());
302 return -1;
303 }
304
305 // resolve function address here
306 orcaslicer_main = (Slic3rMainFunc)GetProcAddress(hInstance_Slic3r,
307#ifdef _WIN64
308 // there is just a single calling conversion, therefore no mangling of the function name.
309 "orcaslicer_main"
310#else // stdcall calling convention declaration
311 "_bambustu_main@8"
312#endif
313 );
314 if (orcaslicer_main == nullptr) {
315 printf("could not locate the function orcaslicer_main in OrcaSlicer.dll\n");
316 return -1;
317 }
318 // argc minus the trailing nullptr of the argv
319 return orcaslicer_main((int)argv_extended.size() - 1, argv_extended.data());
320}
#define L(s)
Definition ExtrusionEntity.cpp:25
int(__stdcall * Slic3rMainFunc)(int argc, wchar_t **argv)
Definition OrcaSlicer_app_msvc.cpp:209
Slic3rMainFunc orcaslicer_main
Definition OrcaSlicer_app_msvc.cpp:210

References L, and orcaslicer_main.

Variable Documentation

◆ orcaslicer_main

Slic3rMainFunc orcaslicer_main = nullptr

Referenced by wmain().