遇到一个问题,开发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 值,所以导致调用该函数永远是失败的问题。现在想是否可以这此动态库之上再封装一个动态库来实现对之前动态库函数的重写,这个要怎么实现,求教~~~或者哪位高人有好的办法能解决此问题,谢谢~~~~望高人指点,最好有代码,谢谢!!!!!
[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 值,所以导致调用该函数永远是失败的问题。现在想是否可以这此动态库之上再封装一个动态库来实现对之前动态库函数的重写,这个要怎么实现,求教~~~或者哪位高人有好的办法能解决此问题,谢谢~~~~望高人指点,最好有代码,谢谢!!!!!
---
/// 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) ;
先看看你的 函数是否可以在 Windows Runtime 下运行。
很多函数使用了 Windows Runtime 不支持的函数。
charset就是小问题用
这位兄弟的方法就能解决的。
Win32 and COM for Windows Store apps
这个和desktop app下的api差异还是很大的,通常老的win32 dll都得要用Metro SDK重新编译并且要能够通过 Windows App Certification,这个不是通过封装就能变成winrt下可用的,明华的dll里用了很多desktop的api(用DependencyWalker就能看到),所以除非他们提供winrt版本,否则h还是放弃吧。