关于C#动态库函数重写的一个问题急!!!望高手指点

我真的是琦琦 2012-10-25 03:47:22
遇到一个问题,开发winform的时候调用动态库代码:
[DllImport("Mwic_32.dll", EntryPoint="ic_init", SetLastError=true,
CharSet=CharSet.Auto , ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明:初始化通讯接口
public static extern int ic_init(Int16 port, int baud);
这个是成功的。没有什么问题。
现在要开发一个 win store App应用,同样要调用这个第三方动态库,可是win store App应用程序开发时CharSet枚举没有Auto 值,所以导致调用该函数永远是失败的问题。现在想是否可以这此动态库之上再封装一个动态库来实现对之前动态库函数的重写,这个要怎么实现,求教~~~或者哪位高人有好的办法能解决此问题,谢谢~~~~望高人指点,最好有代码,谢谢!!!!!
...全文
205 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jshi123 2012-10-26
  • 打赏
  • 举报
回复
metro style app只能使用Win32 API的一个子集,用DllImport调用的动态连接库也要满足这个要求,可以用的API列表如下:
Win32 and COM for Windows Store apps
这个和desktop app下的api差异还是很大的,通常老的win32 dll都得要用Metro SDK重新编译并且要能够通过 Windows App Certification,这个不是通过封装就能变成winrt下可用的,明华的dll里用了很多desktop的api(用DependencyWalker就能看到),所以除非他们提供winrt版本,否则h还是放弃吧。
oh51888 2012-10-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

我感觉不是 charset 的问题。
先看看你的 函数是否可以在 Windows Runtime 下运行。
很多函数使用了 Windows Runtime 不支持的函数。
[/Quote]
+1
charset就是小问题


[Quote=引用 1 楼 的回复:]
把CharSet=CharSet.Auto 改成 CharSet=CharSet.Ansi 或 CharSet=CharSet.Unicode试下
[/Quote]
这位兄弟的方法就能解决的。

Saleayas 2012-10-25
  • 打赏
  • 举报
回复
我感觉不是 charset 的问题。
先看看你的 函数是否可以在 Windows Runtime 下运行。
很多函数使用了 Windows Runtime 不支持的函数。
我真的是琦琦 2012-10-25
  • 打赏
  • 举报
回复
刚网上查了一下win store App开发调用win32.dll时会有问题,不知道怎么把win32.dll封装成winrt.dll请教~~
XBodhi. 2012-10-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
给个列子: API FindWindow
---
/// Return Type: HWND->HWND__*
///lpClassName: LPCSTR->CHAR*
///lpWindowName: LPCSTR->CHAR*
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPo……
[/Quote]
showjancn 2012-10-25
  • 打赏
  • 举报
回复
给个列子: API FindWindow
---
/// Return Type: HWND->HWND__*
///lpClassName: LPCSTR->CHAR*
///lpWindowName: LPCSTR->CHAR*
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint="FindWindowA")]
public static extern System.IntPtr FindWindowA([System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string lpClassName, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string lpWindowName) ;



/// Return Type: HWND->HWND__*
///lpClassName: LPCWSTR->WCHAR*
///lpWindowName: LPCWSTR->WCHAR*
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint="FindWindowW")]
public static extern System.IntPtr FindWindowW([System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)] string lpClassName, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)] string lpWindowName) ;
bdmh 2012-10-25
  • 打赏
  • 举报
回复
应该是有一个基类或接口,声明dll的函数,后面派生出类,根据你的平台不同,做不同设置的引入dll
qygcom 2012-10-25
  • 打赏
  • 举报
回复
把CharSet=CharSet.Auto 改成 CharSet=CharSet.Ansi 或 CharSet=CharSet.Unicode试下

110,500

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧