Using mingW compiled dll in VS2017


this topic certainly doesn't look 'new' but after reading a number of posts, blogs and comments, I'm still none the wiser, and can't get my test application working.

From an implementation point of view I must compile the dll with mingW (when other MSVC compilers are used, the error count is hefty). However this gives the error when invoking into c# VS2017:

System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'

Whereas the sample DLL works fine in Visual studio project when compiled with MSVC2107-64bit (but will produce 120+ errors if try to compile existing implementation with same compiler).

My sample code for DLL export is simple (in Qt):

#pragma once

extern "C"
    __declspec(dllexport) int __stdcall test();

#include "qtlib.h"

int __stdcall test()
        return 10;

When exporting this and viewing the function name with Dependency Walker, the function name is:

Dependency Walker view

Then trying to invoke the DLL in VS2017 (C#):

[DllImport("QtLib.dll", EntryPoint = "test@0", CallingConvention = CallingConvention.StdCall)]
        static extern int test();

public void testFunc()
    int val = test();
  • 'Allow unsafe code' is also ticked under project properties

And the type of errors I get when I compile the full implementation code in MSVC, not mingW (in Qt) is:

__attribute__: unknown override specifier

deprecated: undeclared identifier

DISTANCE_OVERFLOW: A data member cannot be initialized with a parenthesized initializer

DJI::OSDK::ErrorCode::MissionACK::WayPoint::DISTANCE_OVERFLOW: a static data member with an in-class initializer must have non-volative const integral type or be specified as inline

type is const uint8_t &

So I have no idea which is 'better'... to try and read mingW DLL in VS2017 (MSVC), or try and convert the implementation code to be able to compile the DLL in MSVC (very tedious)? Is there a 'quick fix'?... please?

asked on Stack Overflow Mar 1, 2019 by Paul • edited Mar 1, 2019 by MSalters

1 Answer


It appears that you're compiling DJI code, which uses a GCC-specific __attribute__ ((deprecated))

The correct solution is to use [[deprecated]]. This is portable. As a result, all the follow-on errors such as "DISTANCE_OVERFLOW: A data member cannot be initialized with a parenthesized initializer" will also disappear. This is because MSVC parses (deprecated) as a parenthesized initializer.

answered on Stack Overflow Mar 1, 2019 by MSalters

User contributions licensed under CC BY-SA 3.0