用C ++ / cli包装C ++ / MFC [英] Wrap C++/MFC in C++/cli

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

问题描述

我有一个API(包含DLL,lib和Headers)(在C ++ / MFC中)



我无法访问源代码。



我试图用C ++ / CLI包装这些头文件,以便稍后在C#中使用它们。





它告诉我DWORD / BYTE / BOOL ...未定义



它还向我显示此错误:IntelliSense:指令#error:WINDOWS.H已包含在内。 MFC应用程序不能#include windows.h



虽然当我在解决方案中查找#include windows.h时它没有显示结果



(我没有更改头文件中的任何内容,当我在C ++中使用它们时工作得很好)



我尝试过:



我在C ++ / CLI项目的共享DLL中使用MFC。



我尝试在c#中直接使用PInvoke,但似乎我不能编组整个类(我不能使用构造函数)

I have an API ( containing DLLs , libs, and Headers) ( in C++ /MFC)

I cannot access the source code.

I am trying to wrap those header files with C++/CLI to use them later in C#.


It tells me DWORD / BYTE /BOOL … not defined

It also shows me this error : IntelliSense : directive #error : WINDOWS.H already included. MFC apps must not #include windows.h

Although when I look for #include windows.h in the solution it shows no result

( I did not change anything in the header files , and when i use them in C++ they work just fine)

What I have tried:

I am using MFC in a shared DLL in my C++/CLI project .

I tryed using PInvoke directly in c# but it seems that i cannot marshal the whole class ( i cannot use the constructor)

推荐答案

windows。 h错误是典型和正确的(在更大的抽象意义上),所以你不应该或不能使用这个标题。你需要以其他方式包含所需的头文件,或者自己定义一些值。



我的建议:在其接口中创建一个没有任何外部MFC类的包装器dll静态链接。使用本机接口作为char *或int进行数据交换。有点烦人,但它确实有效。



我写了 Windows Phone 文章,所以代码应该给你一些见解。
The windows.h error is typical and correct (in bigger abstract sense), so you shouldnt or cant use this header. You need to include the needed headers in an other manner, or define some values yourself.

My advice: Make a wrapper dll without ANY external MFC class in its interfaces and link statically. Use native interfaces as char* or int for data exchange. A bit annoying, but it works.

I wrote an article for Windows Phone on roughly this topic, so the codeshould give you some insights.


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

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