为WPF创建C ++包装器 [英] Creating C++ wrapper for WPF

查看:76
本文介绍了为WPF创建C ++包装器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个dll Apms.dll,它不支持WPF(.net)。



所以我需要用C ++编写一个包装器并在其中使用它WPF appln。



我对包装器的创建很新。我有一些API调用Apms.dll。它们是



RETCOND API1090 ApmsApiSrvConnect

(LPTSTR szServerName,LPDWORD dwClientNbr,

LPDWORD dwReserved);



返回代码为



R_NORMAL



R_NOCONN



R_NOACTIVE ..



任何人都可以提供帮助我在C ++中为Api方法编写这个Wrapper并连接我的WPF应用程序?

解决方案

你需要研究P/Invoke [ ^ ]用于从.NET应用程序访问C风格的DLL函数。


< blockquote>使用混合模式C ++ / CLI DLL可能是一种简单的方法,可以为APms.dll中的代码提供.NET友好的接口。但是如果你只有一些函数可以调用,那么P / Invoke方法将是一个更好的选择。



通常,如果P / Invoke足够那么你应该跟着它。另一方面,如果DLL使用相对复杂,包装器也可能有助于简化其功能的使用。



我猜Apms.dll是外部的到你的公司,你只有DLL(及其链接库)。



因为,如果您有完整的源代码,您可能会考虑以混合模式编译DLL并将.NET包装器放在同一个DLL中,


i have one dll Apms.dll which is not supported to WPF (.net).

So i need to write a wrapper in C++ and use it in WPF appln.

iam new to wrapper creation . i have some API calls for Apms.dll .They are

RETCOND API1090 ApmsApiSrvConnect
( LPTSTR szServerName, LPDWORD dwClientNbr,
LPDWORD dwReserved );

Return code is of

R_NORMAL

R_NOCONN

R_NOACTIVE ..

can anybody help me in writing this Wrapper for the Api method in C++ and connect with my WPF application?

解决方案

You need to look into the use of P/Invoke[^] for accessing C style DLL functions from .NET applications.


Using a mixed mode C++/CLI DLL might be an easy way to provide a .NET friendlier interface for calling code in APms.dll. However if you only have a few functions to call, then the P/Invoke approach would be a better choice.

Typically, if P/Invoke is sufficient then you should go with it. On the other hand, if the DLL is relatively complex to use, wrapper might also help to simplify the use of its function.

I guess that Apms.dll is external to your company and that you only have the DLL (and its library for linking).

Because, if you have the full source code, you might consider compiling the DLL in mixed mode and have the .NET wrapper in the same DLL,


这篇关于为WPF创建C ++包装器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆