Results 1 to 14 of 14

Thread: Dll returning a String

  1. #1
    DaoK
    Guest

    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);

  2. #2
    jim mcnamara
    Guest
    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>
    as in std::string

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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!
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    DaoK
    Guest
    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 ?

  5. #5
    DaoK
    Guest
    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

  6. #6
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Maybe try this:
    PHP Code:
    std::string sPass;
    sPass =(*PasswordMaker)(); 
    Baaaaaaaaah

  7. #7
    DaoK
    Guest
    THX but that produce that error now :
    Attached Images Attached Images  

  8. #8
    DaoK
    Guest
    THX but that produce that error now :
    Attached Images Attached Images  

  9. #9
    DaoK
    Guest
    THX but that produce that error now :


    I have that when the exe close.
    Attached Images Attached Images  

  10. #10
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    How is your DLL written? What's the code for PasswordMaker()?
    Baaaaaaaaah

  11. #11
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    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); 
    Baaaaaaaaah

  12. #12
    DaoK
    Guest
    C++ doesn't have something like in vb unload() or a function who is exectuted when the program close ?

  13. #13
    DaoK
    Guest
    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 __declspecdllexport )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 

  14. #14
    DaoK
    Guest
    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 __declspecdllexport )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 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width