高分求救 懂C# 调用C++Dll的请进,
void CCallDllDlg::Find()
{
int cx,cy;//找到图片的横坐标cx和纵坐标cy
CString temp_x,temp_y;//
CString msg="Pee_Shangx.bmp";//要查找的bmp文件(24位色位图)
HINSTANCE hDllInst = LoadLibrary("FindPic.dll");
if(hDllInst)
{
typedef void (*MYFUNC)(CString,int*,int*);
MYFUNC youFuntionNameAlias = NULL; // youFuntionNameAlias 函数别名
youFuntionNameAlias = (MYFUNC)GetProcAddress(hDllInst,"FindPic");
// youFuntionName 在DLL中声明的函数名
if(youFuntionNameAlias)
{
youFuntionNameAlias(msg,&cx,&cy);
temp_x.Format("%d",cx);
temp_y.Format("%d",cy);
AfxMessageBox("横坐标"+temp_x+" 纵坐标"+temp_y);
SetCursorPos(cx,cy);//移动鼠标到图片位置
}
FreeLibrary(hDllInst);
}
下面是C# 调用的代码
private int iHwnd = 0; //DLL句柄
private delegate void FindPictures(StringBuilder strFileName, ref int iX, ref int iY);
private FindPictures fp;
private const string DLLNAEM = "FindPic.dll";
[DllImport("kernel32.dll", EntryPoint = "LoadLibrary", SetLastError = true)]
public static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("kernel32.dll", EntryPoint = "GetProcAddress", SetLastError = true)]
public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProceName);
[DllImport("kernel32.dll", EntryPoint = "FreeLibrary", SetLastError = true)]
public static extern bool FreeLibrary(IntPtr hModule);
public static Delegate GetAddress(IntPtr dllModule, string functionname, Type t)
{
IntPtr addr = GetProcAddress(dllModule, functionname);
if (addr == IntPtr.Zero)
return null;
else
return Marshal.GetDelegateForFunctionPointer(addr, t);
}
public void FindPicFunction(StringBuilder strName, ref int iX, ref int iY)
{
try
{
ipt = LoadLibrary(DLLNAEM);
if (ipt == IntPtr.Zero)
return;
fp = (FindPictures)GetAddress(ipt, "FindPic", typeof(FindPictures));
fp(strName, ref iX, ref iY);//这里就提示出错.说类型错误.//------------------------------------
}
catch
{
//出错
}
finally
{
FreeLibrary(ipt);
}
}
到标记的地方出错.错误代码如下
对 PInvoke 函数“#!#.Control.FindPicClass+FindPictures::Invoke”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。
问题: 请问这个CString 到底应该和C# 的那种类型相对应.? (String是尝试过了.不行 StringBuilder也不行.
)
相关推荐
C++调用C#的DLL实例程序
C++调用C#的DLL实例程序,压缩包中包含部分程序说明,很小的几行代码,但是C++调用C#的DLL目的已经达到。
C++ OCR实战:从DLL封装到多语言集成的文字识别方案
本文详细介绍了使用C++实现OCR文字识别的全流程,包括DLL封装、多语言集成及性能优化技巧。通过OpenCV和Tesseract等工具链组合,开发者可以构建高效的OCR解决方案,并实现与Python、C#等语言的跨平台兼容。文章还分享了金融票据识别等实际应用案例,帮助读者快速掌握C++ OCR开发的核心技术。
北洋标签打印机二次开发实战:DLL调用、打印流程与踩坑记录
在工业自动化和物流仓储场景中,标签打印机的软件集成是常见需求。开发者通常通过DLL二次开发或指令直发方式控制打印机,其中DLL封装了底层通信、状态查询和字符编码等复杂逻辑,能显著降低开发门槛。本文以北洋标签打印机开发包为例,详细讲解其初始化连接、标签任务创建、文本条码二维码绘制、打印参数设置等核心API调用流程,并分享多机并发、错误码排查、中文乱码、网口连接等实战经验。通过合理配置标签尺寸与偏移量,可快速实现稳定的批量打印,提升仓储管理效率。无论是C#、C++还是Python开发者,掌握这些方法都能有效应对
C#使用CLR调用C++的DLL库
C#使用CLR调用C++的DLL库的windows完整解决方案 说明如下: 1、工程一:C++的DLL 2、工程二:C++的CLR的类库 3、工程三:C#的exe
C++调用C#的DLL实现方法
SwfDotNet是C#编写的,这是个特别好的读写Swf文件的库。本文讲述了在C++项目中,怎么让C++调用C#的DLL动态链接库文件。 具体的实现步骤如下: 一、创建C# DLL,需要指定应用类型为“类库”,代码: namespace CSLib { public class Class1 { private string name; public string Name { get { return name; } set { name = "Your Name:


