Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
}

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
Posted
Updated 1-Aug-11 20:02pm
v3
Comments
tolw 2-Aug-11 2:04am    
Edited for readability

Re is of type CString rt?U need to copy the string using the function strcpy()
like
strcpy( PortName, Re );

Also ensure that you have allocated enogh memory for PortName before passing its refrence to the function ReturnSize().
 
Share this answer
 
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:
C++
extern "C" __declspec(dllexport) int ReturnSize(TCHAR* PortName)
{
     PortName =Re;
     return KbReceived;
}

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:
C++
extern "C" __declspec(dllexport) LPCTSTR GetString()
{
     return Re;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900