Hello,
VS 3.5
I have created a simple C++ DLL, and I want to use this in my C# program.
However, I am getting a Can't find PInvoke DLL 'TEST_SIP.dll
I have placed the DLL in my debug folder where my C# program is executed from. I am not sure if that is the correct place to put it.
Not sure where I am going wrong with this one.
many thanks for any suggestions,
Steve
Code in my C#
C++ header
C++ Functions
VS 3.5
I have created a simple C++ DLL, and I want to use this in my C# program.
However, I am getting a Can't find PInvoke DLL 'TEST_SIP.dll
I have placed the DLL in my debug folder where my C# program is executed from. I am not sure if that is the correct place to put it.
Not sure where I am going wrong with this one.
many thanks for any suggestions,
Steve
Code in my C#
Code:
[DllImport("TEST_SIP.dll")]
public static extern double Add(double a, double b);
private void btnLogin_Click_1(object sender, EventArgs e)
{
string msg = SendData("Hello how are you");//Can't find PInvoke DLL 'TEST_SIP.dll'.
MessageBox.Show(msg);
}
C++ header
Code:
//TEST_SIP.h
#include <iostream>
namespace TEST_SIP
{
class TEST_SIP_Phone
{
public:
static _declspec(dllexport) double Add(double a, double b);
static _declspec(dllexport) double Subtract(double a, double b);
static _declspec(dllexport) double Multiply(double a, double b);
static _declspec(dllexport) double Divide(double a, double b);
static _declspec(dllexport) std::string SendData(std::string data);
};
}
C++ Functions
Code:
//TEST_SIP.cpp
#include "TEST_SIP.h"
#include <stdexcept>
#include <cctype>
using namespace std;
namespace TEST_SIP
{
double TEST_SIP_Phone::Add(double a, double b)
{
return a + b;
}
double TEST_SIP_Phone::Subtract(double a, double b)
{
return a - b;
}
double TEST_SIP_Phone::Multiply(double a, double b)
{
return a * b;
}
double TEST_SIP_Phone::Divide(double a, double b)
{
if(b == 0)
{
throw new invalid_argument("b cannot be zero!");
}
return a / b;
}
std::string TEST_SIP_Phone::SendData(std::string data)
{
return data;
}
}