-
Dll returning a String
Is that normal that I got an error like that :
error C2679: binary '=' : no operator defined which takes a right-hand operand of type
'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > (__cdecl *)(void)'
(or there is no acceptable conversion)
The code look like :
std::string a;
a = (*returnMyString);
-
First answer: NO not normal
If it is an external (usually MS) dll - you are dealing with null-terminated char *.
If it's OLE , then you've likely got BSTR *.
Not <string> :D
as in std::string
-
If you're calling between C++ DLLs from the same compiler, you can return strings quite happily...the best thing if you're making a C DLL is to get them to supply a buffer and a length, then fill it up a la strncpy().
Watch for the buffer overruns, though!
-
Well you are both too good in C for me because I think you have answer my question with too much hard word because I do not understand what to change to have no error...
And can we put whole class in a DLL ?
-
I call the dll to the string like that :
Code:
std::string sPass;
sPass =(*PasswordMaker);
and I got :
Code:
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,st
ruct std::char_traits<char>,class std::allocator<char> > (__cdecl *)(void)' (or there is no acceptable conversion)
warning C4550: expression evaluates to a function which is missing an argument list
-
Maybe try this:
PHP Code:
std::string sPass;
sPass =(*PasswordMaker)();
-
1 Attachment(s)
THX but that produce that error now :
-
1 Attachment(s)
THX but that produce that error now :
-
1 Attachment(s)
THX but that produce that error now :
http://www.vbforums.com/attachment.p...postid=1101347
I have that when the exe close.
-
How is your DLL written? What's the code for PasswordMaker()?
-
Oh, are you freeing the DLL when you have used it? Use FreeLibrary() to unload the DLL before quitting the program.
PHP Code:
//Use the DLL
//...........
//Free the DLL
FreeLibrary(hDLL);
-
C++ doesn't have something like in vb unload() or a function who is exectuted when the program close ?
-
C++ doesn't have something like in vb unload() or a function who is exectuted when the program close ?
Here is in the dll the code of the password function, the freelibrary didn't solve the problem.
PHP Code:
std::string __declspec( dllexport )PasswordMaker()
{
char cChar; //Contain the character that the user have pressed
std::string sPass; //Contain all character
int iNombreChar = 0; //Number of character that the user have pressed
//Loop until the user press enter
while(true)
{
//Get character one by one
cChar = getch();
//Only if the number that the user put is bigger than 1 you can erase
if (iNombreChar > 0)
{
if( cChar == 8)
{
//Erase the character in the String
sPass = sPass.substr(0,sPass.length() -1);
//Erase the character at the screen
std::cout << (char)(8) << char(32) << char(8);
iNombreChar--;
}//End if
}//End if
//Put stars and not the character
if (cChar != 13 && cChar != 8)
{
sPass += cChar;
std::cout << "*";
iNombreChar ++;
}//End if
//If the user press ENTER than we have done with the password creation
else if (cChar == 13)
break;
}//End for while(true)
return sPass;
}//End PasswordMaker
-
C++ doesn't have something like in vb unload() or a function who is exectuted when the program close ?
Here is in the dll the code of the password function, the freelibrary didn't solve the problem.
PHP Code:
std::string __declspec( dllexport )PasswordMaker()
{
char cChar; //Contain the character that the user have pressed
std::string sPass; //Contain all character
int iNombreChar = 0; //Number of character that the user have pressed
//Loop until the user press enter
while(true)
{
//Get character one by one
cChar = getch();
//Only if the number that the user put is bigger than 1 you can erase
if (iNombreChar > 0)
{
if( cChar == 8)
{
//Erase the character in the String
sPass = sPass.substr(0,sPass.length() -1);
//Erase the character at the screen
std::cout << (char)(8) << char(32) << char(8);
iNombreChar--;
}//End if
}//End if
//Put stars and not the character
if (cChar != 13 && cChar != 8)
{
sPass += cChar;
std::cout << "*";
iNombreChar ++;
}//End if
//If the user press ENTER than we have done with the password creation
else if (cChar == 13)
break;
}//End for while(true)
return sPass;
}//End PasswordMaker