Closed JiangHeWei closed 7 years ago
I'm quite surprised that you've got an error. CppSharp hasn't failed yet for me even for really big headers there weren't any dll import failures.
However, are you sure that the dll file is correct?
@JiangHeWei this can be fixed but requires a little setting up on your part. So in case you have control over the C++ you wrap, it would be easiest to you to instead just add an explicit empty constructor (and destructor) to Spi.
C++ dll is third part.so spi is not exported. maybe control don't "call __Internal.ctor_0((Instance + PointerAdjustment))"?
class Spi only exist virtual method for export C++ interface
if delete "__Internal.ctor_0((Instance + PointerAdjustment))". it is ok. dll sure ok.
@JiangHeWei if you delete that line, your object might not be properly constructed which in turn might lead to undefined behaviour. So try the following instead:
Let me know if this helps.
in C#: public SpiImp:Spi { public override Callback(){...} }
Api api = ApiInternal.CreateApi(); api.RegisterSPi(new SpiImp());
error: System.EntryPointNotFoundException "??0Spi@@QEAA@XZ"
because in auto genegrated code call "__Internal.ctor_0((Instance + PointerAdjustment))"-> SuppressUnmanagedCodeSecurity] [DllImport("Test", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, EntryPoint="??0Spi@@QEAA@XZ")] internal static extern global::System.IntPtr ctor_0(global::System.IntPtr instance);
I understand what your problem is and why you think deleting the line "fixes" it. What I am telling you is that this "fix" might cause you other problems. So please try my steps above instead.
this is callback class case. "Spi" only include virtual method. don't auto generate C# wrapper class into c++?
Spi is inherited by some real class, for example that SpiImpl. SpiImpl silently calls the base constructor, that is, the constructor of Spi. This is standard behaviour of C++ and all other object-oriented languages. So you'd be better off actually calling that constructor.
@ddobrev i will create new c++ project to solve this.thanks.
Brief Description
OS: Windows
Used headers
class Spi { public: virtual void Callback() = 0; };
class __declspec(dllimport) Api { public: static Spi CreateApi(); virtual void RegisterSpi(Spi pSpi) = 0; };
Used settings
options.GeneratorKind = GeneratorKind.CSharp;
Target: MSVC
Stack trace or incompilable generated code
Test.cs
SuppressUnmanagedCodeSecurity] [DllImport("Test", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, EntryPoint="??0Spi@@QEAA@XZ")] internal static extern global::System.IntPtr ctor_0(global::System.IntPtr instance);
protected Spi() { Instance = Marshal.AllocHGlobal(sizeof(global::Test.Spi.Internal)); ownsNativeInstance = true; NativeToManagedMap[Instance] = this;
}
System.EntryPointNotFoundException "??0Spi@@QEAA@XZ"