1

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):

//qtLib.h
#pragma once

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

//qtLib.cpp
#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?

MSalters
  • 173,980
  • 10
  • 155
  • 350
Paul
  • 756
  • 1
  • 8
  • 22
  • You seem to have a major issue with terminology, which won't help you in finding the right search terms. MSVC is the common abbreviation of the Microsoft Visual C++ compiler. It's not C#. I've no idea what "read mingW DLL in VS2017" even means. And why are you throwing Qt in the mix? That makes it much worse. In general, you should not mix 2 technologies unless you are reasonably fluent in both. You're trying to mix 3 (C#, C++, Qt). – MSalters Mar 01 '19 at 11:36
  • hmm sorry, I don't think so... I'm doing the dll compiling in Qt (not via Qt VS tools in Visual studio), compiling the DLL with both mingW and MSVC compilers (creating DLLs from c++ code). And testing the dlls through a sample application written in C# in Visual studio. When the dll is compiled with MSVC it works in the C# application (for apparent reasons), but not when compiled with mingW compiler... – Paul Mar 01 '19 at 12:03
  • That clarifies a lot. And you have checked that the MingW DLL is x64 like the MSVC build? Because that is the most common cause of `0x8007000B`. As for the `DISTANCE_OVERFLOW` problem; we don't see code. I would recommend asking a new question _just_ about that part. – MSalters Mar 01 '19 at 15:36

1 Answers1

3

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.

MSalters
  • 173,980
  • 10
  • 155
  • 350