首页 新闻 会员 周边

C#调用C++扫描仪接口

0
悬赏园豆:15 [已关闭问题]

最近在做一个扫描仪接口,环境是VS2003 在c#里面调用c++写的扫描仪接口,总是提示找不到dll的依赖项。怀疑是传入的参数有问题,请问:
[DllImport("..\\Scan.dll")]
public static extern HINSTANCE InitTwainDLL(LPCTSTR szDLLName);
调用的时候LPCTSTR要用什么类型的参数?
最好能说下c++ 类型在c#都是用什么类型可以替换的?



小小蚂蚁的主页 小小蚂蚁 | 初学一级 | 园豆:180
提问于:2009-06-10 09:18
< >
分享
其他回答(2)
0
LPCTSTR 转换到C# 参考下面 API

HWND FindWindow(      

    LPCTSTR lpClassName,
    LPCTSTR lpWindowName
);
The corresponding  Prototype in C# will be
[DllImport("user32.dll",EntryPoint="FindWindow",CharSet=CharSet.UNICODE)]
Public static extern int MyFindWindow(string _WindowClassName, string _WindowName);

参考文章
http://weblogs.asp.net/rmahato/archive/2003/12/29/46335.aspx

eaglet | 园豆:17139 (专家六级) | 2009-06-10 09:40
0

借个地问下

PB声明
Function Integer DC_Mif_Read(Integer bAddr ,Ref String bData ) Library "Fox_DC.dll"

我在C#中调用
[DllImport("FOX_DC.dll", EntryPoint = "DC_Mif_Read")]
        public static extern int DC_Mif_Read(UInt16 bAddr,ref string bData);

string udd = "";
DC_Mif_Read(0, ref  udd);到这句就出错了
引发类型为“System.ExecutionEngineException”的异常。
高手帮忙

叶子绿了 | 园豆:50 (初学一级) | 2009-06-10 10:16
0

LPCTSTR 是字符串指针类型 需要用String,楼主的写法有问题;

[DllImport("..\\Scan.dll")]
public static extern HINSTANCE InitTwainDLL(ref String szDLLName);

或者

String   str   =   Marshal.PtrToStringAuto(指针地址);

winzheng | 园豆:8797 (大侠五级) | 2009-06-10 11:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册