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:
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();
}
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 asinline
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?
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.
User contributions licensed under CC BY-SA 3.0