R
rhythmchicago
I'm trying to write a dll in native c++, then wrap it in a c++ class
library.
I know I'm missing a few steps. Can someone please point me in the
right direction? I read that VS2008 had added some features to make
using native c++ dlls easier, but I haven't found much documentation
on this.
This is the native c++ dll:
#pragma once
typedef int (__stdcall *mbmTransmit)( const char *inMessage, const int
inLength );
class __declspec(dllexport) CModbusMaster
{
public:
CModbusMaster( bool inIsTcp );
~CModbusMaster(void);
char txMessage[255];
char rxMessage[255];
bool IsTcp;
// The Callback functions
mbmTransmit TransmitFunction;
// Enum some return values
enum
{
MB_SUCCESS = 0,
MB_BADFUNC = 0x01, // Illegal Function
MB_BADADDR = 0x02, // Illegal Data Address
MB_BADDATA = 0x03, // Illegal Data Value
MB_SLAVEFAILURE = 0x04, // Slave Device Failure
MB_BUSY = 0x06, // Target is busy with another request
MB_NORESP = 0x0B, // No response from target
MB_DEVNOTSET = 0x10, // device not properly set up
MBM_INVALID_PARAMETER = -1,
MBM_PACKET_ERROR = -2,
MBM_BAD_ADDRESS = -3,
MBM_BAD_BYTECOUNT = -4,
MB_CRC_ERROR = -5,
MBM_PFTRANSMIT_NULL = -10
};
/* FC 0x03 */
int ReadMulitpleRegisters( int inAddress,
int inStartRegister,
int inLength,
int *outValues );
/* FC 0x10 */
int WriteMultipleRegisters( int inAddress,
int inStartRegister,
int inLength,
int *inValues );
private:
char *ptxMessage;
void initMessage ( int inAddress, int inFunctionCode, int
inPDUByteCount );
void insertWord ( int Value );
void insertByte ( int Value );
int getMessageWord ( int Offset );
};
And this is c++ class library I'm trying to import into:
#pragma once
using namespace System;
#include "d:/srcroot/adcModbus/Master/v1/modbus_master/modbus_master/
ModbusMaster.h"
namespace adcModbusMasterTCP {
public ref class CModbusMasterTCP
{
public:
CModbusMasterTCP(void);
~CModbusMasterTCP(void);
int ReadMulitpleRegisters( int inAddress,
int inStartRegister,
int inLength,
int *outValues );
/* FC 0x10 */
int WriteMultipleRegisters( int inAddress,
int inStartRegister,
int inLength,
int *inValues );
private:
CModbusMaster *mbm;
};
}
In the constructor of the class library, I make a new ModbusMaster.
CModbusMasterTCP::CModbusMasterTCP(void)
{
mbm = new CModbusMaster(true);
}
Everything compiles fine, but it won't link.
Error 1 error LNK2020: unresolved token (06000002)
adcModbusMasterTCP.CModbusMasterTCP::~CModbusMasterTCP
adcModbusMasterTCP.obj adcModbusMasterTCP
Error 2 error LNK2020: unresolved token (06000003)
adcModbusMasterTCP.CModbusMasterTCP::ReadMulitpleRegisters
adcModbusMasterTCP.obj adcModbusMasterTCP
Error 3 error LNK2020: unresolved token (06000004)
adcModbusMasterTCP.CModbusMasterTCP::WriteMultipleRegisters
adcModbusMasterTCP.obj adcModbusMasterTCP
I'm obviously missing a step. Can anyone point me in the right
direction?
Thanks in advance!
library.
I know I'm missing a few steps. Can someone please point me in the
right direction? I read that VS2008 had added some features to make
using native c++ dlls easier, but I haven't found much documentation
on this.
This is the native c++ dll:
#pragma once
typedef int (__stdcall *mbmTransmit)( const char *inMessage, const int
inLength );
class __declspec(dllexport) CModbusMaster
{
public:
CModbusMaster( bool inIsTcp );
~CModbusMaster(void);
char txMessage[255];
char rxMessage[255];
bool IsTcp;
// The Callback functions
mbmTransmit TransmitFunction;
// Enum some return values
enum
{
MB_SUCCESS = 0,
MB_BADFUNC = 0x01, // Illegal Function
MB_BADADDR = 0x02, // Illegal Data Address
MB_BADDATA = 0x03, // Illegal Data Value
MB_SLAVEFAILURE = 0x04, // Slave Device Failure
MB_BUSY = 0x06, // Target is busy with another request
MB_NORESP = 0x0B, // No response from target
MB_DEVNOTSET = 0x10, // device not properly set up
MBM_INVALID_PARAMETER = -1,
MBM_PACKET_ERROR = -2,
MBM_BAD_ADDRESS = -3,
MBM_BAD_BYTECOUNT = -4,
MB_CRC_ERROR = -5,
MBM_PFTRANSMIT_NULL = -10
};
/* FC 0x03 */
int ReadMulitpleRegisters( int inAddress,
int inStartRegister,
int inLength,
int *outValues );
/* FC 0x10 */
int WriteMultipleRegisters( int inAddress,
int inStartRegister,
int inLength,
int *inValues );
private:
char *ptxMessage;
void initMessage ( int inAddress, int inFunctionCode, int
inPDUByteCount );
void insertWord ( int Value );
void insertByte ( int Value );
int getMessageWord ( int Offset );
};
And this is c++ class library I'm trying to import into:
#pragma once
using namespace System;
#include "d:/srcroot/adcModbus/Master/v1/modbus_master/modbus_master/
ModbusMaster.h"
namespace adcModbusMasterTCP {
public ref class CModbusMasterTCP
{
public:
CModbusMasterTCP(void);
~CModbusMasterTCP(void);
int ReadMulitpleRegisters( int inAddress,
int inStartRegister,
int inLength,
int *outValues );
/* FC 0x10 */
int WriteMultipleRegisters( int inAddress,
int inStartRegister,
int inLength,
int *inValues );
private:
CModbusMaster *mbm;
};
}
In the constructor of the class library, I make a new ModbusMaster.
CModbusMasterTCP::CModbusMasterTCP(void)
{
mbm = new CModbusMaster(true);
}
Everything compiles fine, but it won't link.
Error 1 error LNK2020: unresolved token (06000002)
adcModbusMasterTCP.CModbusMasterTCP::~CModbusMasterTCP
adcModbusMasterTCP.obj adcModbusMasterTCP
Error 2 error LNK2020: unresolved token (06000003)
adcModbusMasterTCP.CModbusMasterTCP::ReadMulitpleRegisters
adcModbusMasterTCP.obj adcModbusMasterTCP
Error 3 error LNK2020: unresolved token (06000004)
adcModbusMasterTCP.CModbusMasterTCP::WriteMultipleRegisters
adcModbusMasterTCP.obj adcModbusMasterTCP
I'm obviously missing a step. Can anyone point me in the right
direction?
Thanks in advance!