Skip to content

Make fit for Visual Studio 2017#12

Open
hmb wants to merge 8 commits intofx5:masterfrom
hmb:visual_studio_project
Open

Make fit for Visual Studio 2017#12
hmb wants to merge 8 commits intofx5:masterfrom
hmb:visual_studio_project

Conversation

@hmb
Copy link
Copy Markdown

@hmb hmb commented Jan 14, 2018

Compiler macros and MSVC specific settings have been added to correctly compile under MSVC in VS 2017. The other pull requests should go together with this one, to compile without warnings.

Holger Böhnke added 7 commits January 14, 2018 13:25
The mechanisms to define the target windows version is to define the
appropriate macro before including SDKDDKVer.h. See targetver.h for more
details.
_WIN32 is defined by the compiler to tell the code that it is compiled under
a 32 bit version of Windows and later. Thus it is also defined under a 64
Bit version of Windows. It's also used by minGW. WIN32 (without underscore)
is *not* defined automatically neither by VC++ nor by minGW. Which is probably
the reason the code compiled in teh first place, because the __stdcall
had been misplaced.

See:
https://stackoverflow.com/questions/9025708/mingw-not-defining-win32-error-in-preprocessor-directives
When explicitly giving a calling convention it has to directly precede the
functions name like this:

void __stdcall foo();

The calling convention had been baked into the USB_DMX_DLL macro that
defines the dll import/export specifics resulting to:

__declspec(dllexport) __stdcall void foo();

which in turn leads to a compiler error. Apparently this did not show up
in minGW, because the WIN32 macro had been used to determine the windows
version, not the _WIN32 macro. The WIN32 macro however had not been
defined.

This has been corrected using two dedicated macros, one for the dll magic
and another one for the calling convention.

Additionally the dll magic has been improved to either turn to the
dllexport when compiling the implementation or to dllimport, when using the
header from a third party client. This is chosen by the
USB_DMX_IMPLEMENTATION macro that is defined in the implementation file
before including the usbdmx.h file

A similar error had been in the callback typedefs. Here the calling
convention has to go inside the brackets:

  typedef void (__stdcall foo)(); // correct

instead of

  typedef void __stdcall (foo)(); // compiler error
The project file can be used from any other solution to include the usbdmx
dll directly into the project. A single solution may be added later to
generate the dlls independently.
@fx5
Copy link
Copy Markdown
Owner

fx5 commented Jan 16, 2018

This breaks usbdmx_example:

$ make
g++ -L. -Wall -o usbdmx_example usbdmx_example.cpp -lusbdmx
usbdmx_example.cpp:9:23: error: expected initializer before ‘InterfaceChange’
 void USB_DMX_CALLBACK InterfaceChange(void) {

- rename USB_DMX_CALLBACK to USB_DMX_CALLBACK_CALLING_CONVENTION
- add a legacy define for USB_DMX_CALLBACK until it maybe becomes
  deprecated
@hmb
Copy link
Copy Markdown
Author

hmb commented Jan 16, 2018

My bad, I missed the example program. Changed the macro there and re-introduced the USB_DMX_CALLBACK macro in order to not break other existing project. If it's OK by you it could be marked deprecated in future releases. It's just a naming clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants