Note that there are some explanatory texts on larger screens.

plurals
  1. POExported function in C++ COM DLL not found from C#
    primarykey
    data
    text
    <p>I have an existing COM DLL that is currently accessed (just one function) through a VB wrapper class and called from a C# class.</p> <p>I'm trying to add callbacks into my C# code (4 separate callbacks). My chosen approach is the only one that I've found but I'm having issues.</p> <p>It says "Unable to find an entry point named 'InitDotNet' in DLL 'xxxx'.</p> <h2>My DLL header file:</h2> <pre><code>extern "C" { #define DLL __declspec(dllexport) typedef void (__stdcall * CB_func1)(int); typedef void (__stdcall * CB_func2)(char *); DLL void InitDotNet(CB_func1 func1, CB_func2 func2); } ... class CComInterface : public CCmdTarget ... afx_msg void mainCall(short parm1, LPCTSTR parm2); ... </code></pre> <h2>My DLL C++ file:</h2> <pre><code>... CB_func1 func1Function; CB_func2 func2Function; ... IMPLEMENT_DYNCREATE(CComInterface, CCmdTarget) ... BEGIN_DISPATCH_MAP(CComInterface, CCmdTarget) DISP_FUNCTION(CComInterface, "mainCall", mainCall, VT_EMPTY, VTS_I2 VTS_BSTR) END_DISPATCH_MAP() ... IMPLEMENT_OLECREATE(CComInterface, "MyDll.Interface", ...) ... void CComInterface::mainCall(short parm1, LPCTSTR parm2) { ... // at various times call func1Functoin and func2Function ... } DLL void InitDotNet(CB_func1 func1, CB_func2 func2) { func1Function = func1; func2Function = func2; } </code></pre> <h2>My VB wrapper looks like this:</h2> <pre><code>Public Class MyWrapperClass Private Shared Protocol As Object = CreateObject("MyDll.Interface") Public Shared Sub mainCall(ByVal parm1 As Short, ByVal parm2 As String) Protocol.mainCall(parm1, parm2) End Sub End Class </code></pre> <h2>My C# code looks like this:</h2> <pre><code>... using System.Runtime.InteropServices namespace MyNamespace { public partial class MyForm : AnotherForm { ... [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate void func1Callback(int value); [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate void func2Callback(string value); [DllImport("mycppdll.dll")] public static extern void InitDotNet([MarshalAs(UnmanagedType.FunctionPtr)] func1Callback f1c, [MarshalAs(UnmanagedType.FunctionPtr)] func2Callback f2c); ... private void MyFunc() { func1Callback f1c = (value) =&gt; { // work here }; func2Callback f2c = (value) =&gt; { // work here }; InitDotNet(f1c, f2c); MyWrapperDll.MyWrapperClass.mainCall(1, "One"); } </code></pre> <p>Anybody have any thoughts on what I'm doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload