S
SJR3t2
I am new to C#, and I have an issue that I can't find the answer thru
googling or checking msdn. I want to run some c++ code from a dll in
C#. Here are snipits of the C++ header file.
struct ChartInfo
{
char symbol[12]; // symbol
int period; // period (PERIOD_*)
time_t start; // start of chart block
time_t end; // end of chart block
time_t timesign; // timestamp of existing
chart base
int mode; // request mode
};
struct RateInfo
{
time_t ctm; // rate time
int open; // open price:
11987=119.87
short high,low,close; // high,low,close shift
from open
double vol; // volume
};
class CManagerInterface
{
public:
//---- connection
virtual int __stdcall Connect(LPCSTR server) =0;
virtual int __stdcall Login(const int login,LPCSTR password)=0;
//---- chart bases
virtual RateInfo* __stdcall ChartRequest(const ChartInfo
*chart,time_t *timesign,int *total) =0;
};
inline code to load funcitons from dll.
typedef int (*MtManVersion_t)(void);
typedef int (*MtManCreate_t)(int version,CManagerInterface **man);
m_pfnManVersion=reinterpret_cast<MtManVersion_t>
:GetProcAddress(m_lib,"MtManVersion"));
m_pfnManCreate
=reinterpret_cast<MtManCreate_t>
:GetProcAddress(m_lib,"MtManCreate"));
inline CManagerInterface* Create(const int version) const
{
CManagerInterface *man=NULL;
(*m_pfnManCreate)(version,&man);
return(man);
}
What I have writen in C#:
using System.Runtime.InteropServices;
namespace InterbankFX
{
public struct ChartInfo
{
char symbol[12]; // symbol
int period; // period (PERIOD_*)
time_t start; // start of chart block
time_t end; // end of chart block
time_t timesign; // timestamp of existing chart
base
int mode; // request mode
}
public struct RateInfo
{
time_t ctm; // rate time
int open; // open price: 11987=119.87
short high,low,close; // high,low,close shift
from open
double vol; // volume
}
public class Manager
{
public extern virtual int Connect(string server);
public extern virtual int Login(int login,string password);
public extern virtual RateInfo[] ChartRequest(ref ChartInfo chart,ref
time_t timesign,ref int total);
}//public class Manager
public class ManagerFactory
{
[DllImport("mtmanapi.dll",EntryPoint="MtManVersion")]
public static extern int Version();
[DllImport("mtmanapi.dll",EntryPoint="MtManCreate")]
public static extern int CreateInteface(int version,ref Manager
manager);
}//public class ManagerFactory
}//namespace InterbankFX
I am hoping someone can help me fill in the gaps.
Steven
googling or checking msdn. I want to run some c++ code from a dll in
C#. Here are snipits of the C++ header file.
struct ChartInfo
{
char symbol[12]; // symbol
int period; // period (PERIOD_*)
time_t start; // start of chart block
time_t end; // end of chart block
time_t timesign; // timestamp of existing
chart base
int mode; // request mode
};
struct RateInfo
{
time_t ctm; // rate time
int open; // open price:
11987=119.87
short high,low,close; // high,low,close shift
from open
double vol; // volume
};
class CManagerInterface
{
public:
//---- connection
virtual int __stdcall Connect(LPCSTR server) =0;
virtual int __stdcall Login(const int login,LPCSTR password)=0;
//---- chart bases
virtual RateInfo* __stdcall ChartRequest(const ChartInfo
*chart,time_t *timesign,int *total) =0;
};
inline code to load funcitons from dll.
typedef int (*MtManVersion_t)(void);
typedef int (*MtManCreate_t)(int version,CManagerInterface **man);
m_pfnManVersion=reinterpret_cast<MtManVersion_t>

m_pfnManCreate
=reinterpret_cast<MtManCreate_t>

inline CManagerInterface* Create(const int version) const
{
CManagerInterface *man=NULL;
(*m_pfnManCreate)(version,&man);
return(man);
}
What I have writen in C#:
using System.Runtime.InteropServices;
namespace InterbankFX
{
public struct ChartInfo
{
char symbol[12]; // symbol
int period; // period (PERIOD_*)
time_t start; // start of chart block
time_t end; // end of chart block
time_t timesign; // timestamp of existing chart
base
int mode; // request mode
}
public struct RateInfo
{
time_t ctm; // rate time
int open; // open price: 11987=119.87
short high,low,close; // high,low,close shift
from open
double vol; // volume
}
public class Manager
{
public extern virtual int Connect(string server);
public extern virtual int Login(int login,string password);
public extern virtual RateInfo[] ChartRequest(ref ChartInfo chart,ref
time_t timesign,ref int total);
}//public class Manager
public class ManagerFactory
{
[DllImport("mtmanapi.dll",EntryPoint="MtManVersion")]
public static extern int Version();
[DllImport("mtmanapi.dll",EntryPoint="MtManCreate")]
public static extern int CreateInteface(int version,ref Manager
manager);
}//public class ManagerFactory
}//namespace InterbankFX
I am hoping someone can help me fill in the gaps.
Steven