我在试图在C#中写成法典,以便把图带给一个未管理的C++ DLL,并返回一个POINT结构。
我在互联网上做了大量研究,但没有发现“Gotcha”条款或法典的一部分帮助我解决我的问题。
迄今为止,我能够讨论的最佳途径是管理不畅的++ DLL,由我C#的表号所呼吁,用一个管理得起的++路程。 在测试时,我可以穿透简单的类型,如ger,并送回无问题的愤怒。 现在,就我所持有的问题而言,这份蓝图。
我曾尝试过通过《经济、社会、文化权利国际公约》(利用我方位标的格特·贝图(GetHBitmap)(c#)的功能),但在汇编“从系统看不到参数1:由于保护水平,“IntPtr”到《经济、社会、文化权利国际公约》”和“Class1.FindImage(撤销*,无效)”时,我发现错误。
我的一些法典是:
主要应用:
class Program
{
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
public static implicit operator System.Drawing.Point(POINT p)
{
return new System.Drawing.Point(p.X, p.Y);
}
public static implicit operator POINT(System.Drawing.Point p)
{
return new POINT(p.X, p.Y);
}
}
static void Main(string[] args)
{
Image src = Image.FromFile("Pin.png");
Image tgt = Image.FromFile("screen.png");
Bitmap bsrc = new Bitmap(src);
Bitmap btgt = new Bitmap(tgt);
IntPtr bs = bsrc.GetHbitmap();
IntPtr bt = btgt.GetHbitmap();
POINT p = Class1.FindImage(bs, bt);
}
}
ImportWrap.h:
namespace ImportWrap {
public ref class Class1
{
public:
static POINT FindImage(IntPtr source, IntPtr target);
};
}
ImportWrap.cpp:
static POINT FindImage(IntPtr source, IntPtr target)
{
return ImgFuncs::MyImgFuncs::FindImage(source, target);
}
ImgFuncs.h
typedef long LONG;
typedef void *PVOID;
typedef PVOID HANDLE;
typedef HANDLE HBITMAP;
typedef struct tagPOINT {
LONG x;
LONG y;
} POINT, *PPOINT;
namespace ImgFuncs
{
class MyImgFuncs
{
public:
static __declspec(dllexport) POINT FindImage(HBITMAP source, HBITMAP target);
};
}
ImgFuncs.cpp
namespace ImgFuncs
{
POINT MyImgFuncs::FindImage(HBITMAP source, HBITMAP target)
{
POINT p;
p.x = 1;
p.y = 2;
return p;
}
}
What am I doing wrong, or am I going completely off the map with my approach? I would GLADLY entertain any suggestions regarding the correct way to code what I am trying to do. I have some C++ code that is used to find an image within another image that works quite fast. Unfortunately, even using lockbits in c#, it s not fast enough. So I would like to make use of the c++ code for the image search.
我相信,我会走到更多的天头,但如果我能够接过这一 st脚石,我可以处理。 如你所知,我的C++知识有限。