Results 1 to 2 of 2

Thread: How to pass and get unicode strings from external dll

  1. #1
    Join Date
    Mar 2014
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default How to pass and get unicode strings from external dll

    I have a very old working dll.
    It has a function that takes in a unicode string.
    It does some processing.
    Prepares another string and returns the prepared unicode string.

    I have used this dll successfully in other projects. (Including in a firefox extension using js-ctype).

    Now I want to use the same dll in my current QT project. (I am new to QT)

    I have done some googling and have tried some ways; however could not successfully do what I wanted to do.

    Here is my function in the working dll
    ==========================

    DECLDIR TCHAR * process_string ( TCHAR * wList)
    {
    wstring outStr(L"{");
    ....
    ....
    //does some processing and prepares outStr
    outStr.append(L"}");
    .....
    ...... etc....

    TCHAR buff [10000] = L"";

    wcscpy ( buff, L"");
    wcscat ( buff, outStr.c_str());
    return buff;
    }

    ========================
    here is my header file
    ========================

    #if defined DLL_EXPORT
    #define DECLDIR __declspec(dllexport)
    #else
    #define DECLDIR __declspec(dllimport)
    #endif

    // Specify "C" linkage to get rid of C++ name mangeling
    extern "C"
    {
    DECLDIR TCHAR * process_string ( TCHAR * wlist);
    }

    =================

    I request you to guide me or give me some pointers so that I can use the above dll in my QT project

    Thanks in advance.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,626
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to pass and get unicode strings from external dll

    It strikes me that that function only works by accident rather than design. It is returning a pointer to a destroyed stack array.

    Anyway, QString has functions QString fromUtf16()/QString::utf16() and QString::fromWCharArray()/QString::toWCharArray() for dealing with these strings.

    Include your header (may require INCLUDEPATH variable), link your library into your project (LIBS variable) and use the QString functions.

Similar Threads

  1. Unicode strings int Qt 4.2.1
    By mkrentovskiy in forum Qt Programming
    Replies: 12
    Last Post: 29th December 2011, 09:02
  2. How do I pass a winId to an external application?
    By agerlach in forum Qt Programming
    Replies: 0
    Last Post: 18th October 2011, 22:30
  3. Extracting strings in files
    By ComaWhite in forum Qt Programming
    Replies: 2
    Last Post: 7th October 2008, 00:01
  4. Strings from LineEdit to Integers
    By Misko in forum Newbie
    Replies: 3
    Last Post: 12th August 2007, 11:11
  5. Adding strings in QTreeWidget ?
    By npc in forum Newbie
    Replies: 13
    Last Post: 30th January 2007, 09:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.