как вызвать функцию экспорта DLL C ++ из C #

Я впервые пытаюсь смешать C # с неуправляемым C ++, так что это может быть очень простой вопрос, но я его не понимаю.

Мне нужно позвонить некоторым функции из библиотеки DLL C ++ в код C #. Вот код для проекта dll:

файл .h:

#pragma once 
#include <iostream>
#if defined FIRSTDLL_EXPORTS
    #define DECLDIR __declspec(dllexport)
#else
    #define DECLDIR __declspec(dllimport)
#endif

extern "C"
    {
      DECLDIR int Add( int a, int b );
      DECLDIR void Function( void );
    }

файл .cpp

#include "stdafx.h"
#include "myFct.h"
#include <iostream>

extern "C"
{
      DECLDIR int Add( int a, int b )
      {
          return( a + b );
}

      DECLDIR void Function( void )
      {
          std::cout << "DLL Called!" << std::endl;
      }
}

Я скомпилировал его как для отладки, так и для выпуска и скопировал в папку debug мой проект C #. Ни одна из версий не работала.

Вот код C #: Additional Information: A call to PInvoke function 'MyAddin!MyAddin.ThisAddIn::Add' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."

But as I see the signatures are the same. What am I missing??

Thanks!

5
задан ghet 20 March 2011 в 09:01
поделиться