I am based on the example published in:
http://msdn.microsoft.com/library/de.../en-us/vcsampl
e/html/vcsammcppwrappersampledemonstrateswrappingcdllwith managedextensio
ns.asp
The original dll (LOOX Maker) is in Visual C++, so according with that
example i am making a dll in Visual C++ .net that use the original dll,
and it is the next code :
#include <graph.h>
#using <mscorlib.dll>
#include <line.h>
using namespace System;
public __gc class ScdGraph
{
protected:
LxGraph *lxGraph;
int a;
public :
char * StringToChar(String * s)
{
int length = s->Length;
char * in_string = new char[length+1];
for(unsigned short i = 0; i<length; i++)
{
in_string[i] = (char)s->Chars[i];
}
in_string[length] = '\0';
return in_string;
}
ScdGraph::ScdGraph(IntPtr w,int mode)
{
lxGraph= new LxGraph((Widget)w.ToPointer(),mode);
a=7;
}
//ScdGraph::ScdGraph(HWND__ *w,String * fileName,int mode)
ScdGraph::ScdGraph(IntPtr w,String * fileName,int mode)
{
char * name = this->StringToChar(fileName);
lxGraph = new LxGraph((Widget)w.ToPointer(),name,mode);
//lxGraph = new LxGraph((Widget)w,name,mode);
if(name!=NULL)
delete [] name;
a=9;
}
ScdGraph::~ScdGraph()
{
}
LxGraph *GetLxGraph()
{
return lxGraph;
}
int GetA()
{
return a;
}
};
//---------------------LINEA--------------------
public __gc class ScdLine
{
protected:
LxLine *l;
public:
ScdLine::ScdLine(String *s,ScdGraph *g,int x1,int y1,int x2,int y2)
{
char * name = g->StringToChar(s);
l = new LxLine(name,g->GetLxGraph(),x1,y1,x2,y2);
if(name!=NULL)
delete [] name;
}
};
graph.h and line.h they are files of which i want to reuse in c# .NET,
when i compile this code i generate my dll to use in c# .NET.
i made a project in c# .NET and there i use the dll and i call the
functions :
private void button1_Click(object sender, System.EventArgs e)
{
ScdGraph g = new ScdGraph(this.Handle,1);
//This code line must create an area to draw
ScdLine l = new ScdLine("Linea",g,10,10,200,400);
//This code line must draw a line into the drawing area
label1.Text=g.GetA().ToString();
//this code show the value of "a"
}
the problem is that this code dont make the drawing area neither draw
the line.
*** Sent via Developersdex
http://www.developersdex.com ***