错误C2679:VC ++中的二进制'=' [英] error C2679: binary '=' in VC++

查看:311
本文介绍了错误C2679:VC ++中的二进制'='的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

旧代码:

Hi friends,

Old Code:

extern "C" __declspec(dllexport) int ReturnSize()
{
    return KbReceived;
}



新代码:



New Code:

extern "C" __declspec(dllexport) int ReturnSize(char *PortName)
{
     PortName =Re;
     return KbReceived;
}


此处Re =接收的端口号Kb-文件大小

当我运行此新代码时,出现此错误:
错误C2679:二进制" =":没有定义运算符,该运算符使用类型为"CString类"(或没有可接受的转换)的右侧操作数MFCDLL.cpp"

我该如何解决?请帮帮我.
问候,
Lakshmi Narayanan.S


Here Re = Port No.KbReceived -- file Size

when i run this new code i got this error:
"error C2679: binary ''='' : no operator defined which takes a right-hand operand of type ''class CString'' (or there is no acceptable conversion) MFCDLL.cpp"

How can i Solve this? Please Help me.
Regards,
Lakshmi Narayanan.S

推荐答案

Re 类型为CString rt?U是否需要使用函数strcpy()复制字符串? > 就像
Re is of type CString rt?U need to copy the string using the function strcpy()
like
strcpy( PortName, Re );


还要确保在将PortName的Refrection传递给函数ReturnSize()之前,已为该PortName分配了纯净的内存.


Also ensure that you have allocated enogh memory for PortName before passing its refrence to the function ReturnSize().


正如Resmi Anna猜测的那样,我想Re是一个CString.

我很确定问题出在字符串编码中:您期望您的CString对象将字符串保存为char*数组,但是(在您的项目中)它是一个wchar*数组(每个字符2个字节). br/>
有2种解决方案可解决您的问题:

1-更改您的函数声明以使其接受宽字符:
As Resmi Anna guessed, I suppose Re is a CString.

I am pretty sure the problem comes from string encoding: your are expecting your CString object to hold a string as char* array, but it is (in your project) a wchar* array (2 bytes per character).

There are 2 solutions to fix your issue:

1- Change your function declaration to make it accept wide chars:
extern "C" __declspec(dllexport) int ReturnSize(TCHAR* PortName)
{
     PortName =Re;
     return KbReceived;
}


但是在使用dll的应用程序中使用宽字符串后要小心.

2-如果要强制CString保持char,请转到项目属性页面,在常规选项卡中,设置字符集设置为未设置(并针对发布 Debug 配置进行此操作).

现在我必须问你想用功能实现什么?
因为如果您想将字符串对象返回给调用者,则不能这样做:您设置的指针将不会返回给调用者.

如果要返回字符串,请执行以下操作:


But be carefull after to use wide character strings in the application that uses the dll.

2- If you want to force your CString to hold char, go to the Project Properties page, in the General tab, set Character set to Not set (and do it for both Release and Debug configurations).

I must now ask what you want to achieve with your function?
Because if you want to return a string object to the caller, you can''t do it this way: the pointer your are setting will not be returned to the caller.

If you want to return the string just do something like that:

extern "C" __declspec(dllexport) LPCTSTR GetString()
{
     return Re;
}


这篇关于错误C2679:VC ++中的二进制'='的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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