从C ++本机类创建C ++ / CLI包装器,其中包含CStrings [英] Create a C++/CLI wrapper from a C++ native class with CStrings in them

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

问题描述

您好,



我有一个巨大的C ++本机类,其中包含很多CStrings。我正在尝试使用C ++ / CLI编写托管类,以便在我的C#界面中使用它。我收到很多这样的错误:



代码:

Hello,

I have a huge C++ native class with a lot of CStrings in them. I am trying to write a managed class using C++/CLI in order to use it in my C# interface. I am getting a lot of errors like these:

Code:

const CString TAG_DISPLAY_USER_ANONYMOUS = TEXT("");





错误:



Error:

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int




error C2146: syntax error : missing ';' before identifier 'TAG_DISPLAY_USER_ANONYMOUS'




error C4430: missing type specifier - int assumed. Note: C++ does not support default-int




error C3861: 'TEXT': identifier not found





这是我在网上查看的,因为C ++ / CLI不支持CStrings。最好的方法是什么?也有人可以给我一个正确的例子。我已经读过,我需要另外一个接口来管理CStrings。任何人都可以建议我最好的方法吗?真的坚持这个:(



谢谢。



This I checked online and is because C++/CLI doesnt support CStrings. What is the best way to go about it? Could someone please give me a proper example as well. I have read that I need another interface in between to manage the CStrings. Can anyone suggest me the best way out of this? Really stuck on this :(

Thanks.

推荐答案

在一个CString中使用CString没有任何问题C ++ / CLI程序集。



查看项目的DLL.h和/或StdAfx.h头文件。你可能错过了#include< afx.h>这样编译器就可以看到CString的定义。



编译完成后,你可能会遇到链接问题。确保项目的配置属性具有常规设置使用MFC设置为在共享DLL中使用MFC或在静态库中使用MFC。
There is nothing wrong with using CString in a C++/CLI assembly.

Look in your project's DLL.h and/or StdAfx.h header files. You are probably missing a #include <afx.h> so that the compiler sees the definition for CString.

Once it compiles, you may run into problems linking. Make sure the project's Configuration Properties has the General setting "Use of MFC" set to "Use MFC in a Shared DLL" or "Use MFC in a Static Library".


该消息是由于表单的函数定义而生成的:

That message is produced as a result of function definitions of the form:
extern foo(int i);



没有明确的退货类型。与 CString 无关。



注意:如果你真的向我们展示了这些线路,那将会非常有帮助生成错误消息的代码。


which have no explicit return type. Nothing to do with CString.

Note: it would really help if you actually showed us the line(s) of code that produces the error message.


这篇关于从C ++本机类创建C ++ / CLI包装器,其中包含CStrings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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