Page 1 of 2 12 LastLast
Results 1 to 20 of 121

Thread: dynamicCall and QByteArray - strange characters

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default dynamicCall and QByteArray - strange characters

    Hi to all,
    doing some test with a com object seems that a com routine that I call with dynamicCall returns a QByteArray or a QString.
    Looking at examples of call of such routine seems that it returns an array of bytes where every element is a pointer to a string

    I did some tests as this:

    QByteArray array = obj->dynamicCall("routine(QString)", "value").toByteArray();
    Debugging with visual studio and doing some cout ( qDebug() << array.data() ) I can see very strange characters like this "‰*" in both case, using QByteArray and QString.
    The routine called with dymanicCall comunicate with a chinese fingerprint reader. Maybe this is the reason I get such strange characters?

    Looking at doc and visual basic example the value returned should be an array of bytes -> returned_value[value1,value2,value3, value4..];

    and

    value1 = value2 = value3 = should points to a string.

    How can I get the value of every value without getting these strange characters?
    I hope to get help wysota where are you?

    Regards
    Last edited by franco.amato; 17th April 2010 at 18:03.
    Franco Amato

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

    Default Re: dynamicCall and QByteArray - strange characters

    Can you run the dumpcpp utility against the com object you are working with?
    Qt Code:
    1. cd somewheresafetowrite
    2. dumpcpp c:\windows\system32\comctl32.ocx
    To copy to clipboard, switch view to plain text mode 
    The resulting cpp and h file should allow you to more directly access the COM objects by simply instantiating them in the typical C++ fashion:
    Qt Code:
    1. ComctlLib::TreeView m_treeView;
    2. ...
    3. m_treeView.SetBorderStyle(ComctlLib::ccFixedSingle);
    To copy to clipboard, switch view to plain text mode 

    The process can be largely automated by:

    client.pro
    Qt Code:
    1. TEMPLATE = app
    2. CONFIG += qaxcontainer
    3. TARGET = client
    4. DEPENDPATH += .
    5. INCLUDEPATH += .
    6. RC_FILE = client.rc
    7. // {6B7E6392-850A-101B-AFC0-4210102A8DA7} is the TypeLib value from the class concerned.
    8. TYPELIBS = $$system( dumpcpp -getfile {6B7E6392-850A-101B-AFC0-4210102A8DA7} )
    9. isEmpty(TYPELIBS) {
    10. message("Tree control type library not found!")
    11. REQUIRES += COMCTL.TreeView
    12. }
    13. else: {# Input
    14. SOURCES += main.cpp
    15. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by ChrisW67 View Post
    Can you run the dumpcpp utility against the com object you are working with?
    Qt Code:
    1. cd somewheresafetowrite
    2. dumpcpp c:\windows\system32\comctl32.ocx
    To copy to clipboard, switch view to plain text mode 
    The resulting cpp and h file should allow you to more directly access the COM objects by simply instantiating them in the typical C++ fashion:
    Qt Code:
    1. ComctlLib::TreeView m_treeView;
    2. ...
    3. m_treeView.SetBorderStyle(ComctlLib::ccFixedSingle);
    To copy to clipboard, switch view to plain text mode 

    The process can be largely automated by:

    client.pro
    Qt Code:
    1. TEMPLATE = app
    2. CONFIG += qaxcontainer
    3. TARGET = client
    4. DEPENDPATH += .
    5. INCLUDEPATH += .
    6. RC_FILE = client.rc
    7. // {6B7E6392-850A-101B-AFC0-4210102A8DA7} is the TypeLib value from the class concerned.
    8. TYPELIBS = $$system( dumpcpp -getfile {6B7E6392-850A-101B-AFC0-4210102A8DA7} )
    9. isEmpty(TYPELIBS) {
    10. message("Tree control type library not found!")
    11. REQUIRES += COMCTL.TreeView
    12. }
    13. else: {# Input
    14. SOURCES += main.cpp
    15. }
    To copy to clipboard, switch view to plain text mode 
    Hi,
    I executed the dumpcpp on my dll ( the com object) but it doesn't generated any *.h or *.cpp
    What can I do?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: dynamicCall and QByteArray - strange characters

    Did you write the com object yousrself? Using QAxServer? If so you probably have a file ending .tlb as part of the build process, and you can put this file name directly in TYPELIBS.

  5. #5
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by ChrisW67 View Post
    Did you write the com object yousrself? Using QAxServer? If so you probably have a file ending .tlb as part of the build process, and you can put this file name directly in TYPELIBS.
    No I didn't write the com object. It com from a finger print sdk I have. I have it in a compiled dll.
    I'm not sure now if I have a tlb file as I'm out of office. If I have it what can I do? And if I don't have it?

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by franco.amato View Post
    No I didn't write the com object. It com from a finger print sdk I have. I have it in a compiled dll.
    I'm not sure now if I have a tlb file as I'm out of office. If I have it what can I do? And if I don't have it?
    You can try
    Qt Code:
    1. TYPELIBS += C:\path\to\your\fingerprint.dll
    To copy to clipboard, switch view to plain text mode 
    which seems to work OK for me for at least some COM objects.

  7. #7
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by ChrisW67 View Post
    You can try
    Qt Code:
    1. TYPELIBS += C:\path\to\your\fingerprint.dll
    To copy to clipboard, switch view to plain text mode 
    which seems to work OK for me for at least some COM objects.
    If I also have the *.tlb I have to do
    Qt Code:
    1. TYPELIBS += C:\path\to\your\fingerprint.dll
    To copy to clipboard, switch view to plain text mode 
    And
    Qt Code:
    1. TYPELIBS += C:\path\to\your\fingerprint.tlb?
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: dynamicCall and QByteArray - strange characters

    If you have the TLB file then list it otherwise try listing the DLL or OCX file itself. One or the other, not both.

  9. #9
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by ChrisW67 View Post
    The resulting cpp and h file should allow you to more directly access the COM objects by simply instantiating them in the typical C++ fashion:
    Qt Code:
    1. ComctlLib::TreeView m_treeView;
    2. ...
    3. m_treeView.SetBorderStyle(ComctlLib::ccFixedSingle);
    To copy to clipboard, switch view to plain text mode 
    Hi, I don't understand a thing:
    I don't have to use the new operator to instantiate the objects?

  10. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by franco.amato View Post
    Hi, I don't understand a thing: I don't have to use the new operator to instantiate the objects?
    That depends on the lifetime you expect the object (m_treeView in my example) to have. On the stack is fine for a short lifespan limited by scope, on the heap would be more typical. The code generated by dumpcpp connects to COM control at the time the wrapper object is constructed and doesn't care how the object came to be.

    You have had success with dumpcpp creating some wrappers. The generated classes should manage marshalling COM response into qt and/or C++ structures for you make for more direct access (adjust names as needed):
    Qt Code:
    1. #include "generated_header.h"
    2. ...
    3. terminalLib::oTerminal *comObject;
    4.  
    5. comObject = new terminalLib::oTerminal(this);
    6. QVariant result = oTerminal->GetUserData(QString("some card id thingy"));
    7. delete comObject;
    To copy to clipboard, switch view to plain text mode 
    If you dig around in the generated H and CPP file you might find a definition of "ArrayList" (or it may be intended to be an opaque blob although this seems unlikely). You may also find references to a Windows help file that matches the type library.

    Could you post (attach) the generated header file?

  11. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: dynamicCall and QByteArray - strange characters

    If the QVariant returned is of type QByteArray then the COM return was a SAFEARRAY(BYTE) according to the QAxBase documentation.
    You might find this useful:
    http://www.roblocher.com/whitepapers/oletypes.aspx
    http://msdn.microsoft.com/en-us/libr...ROT.13%29.aspx

  12. #12
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by ChrisW67 View Post
    That depends on the lifetime you expect the object (m_treeView in my example) to have. On the stack is fine for a short lifespan limited by scope, on the heap would be more typical. The code generated by dumpcpp connects to COM control at the time the wrapper object is constructed and doesn't care how the object came to be.

    You have had success with dumpcpp creating some wrappers. The generated classes should manage marshalling COM response into qt and/or C++ structures for you make for more direct access (adjust names as needed):
    Qt Code:
    1. #include "generated_header.h"
    2. ...
    3. terminalLib::oTerminal *comObject;
    4.  
    5. comObject = new terminalLib::oTerminal(this);
    6. QVariant result = oTerminal->GetUserData(QString("some card id thingy"));
    7. delete comObject;
    To copy to clipboard, switch view to plain text mode 
    If you dig around in the generated H and CPP file you might find a definition of "ArrayList" (or it may be intended to be an opaque blob although this seems unlikely). You may also find references to a Windows help file that matches the type library.

    Could you post (attach) the generated header file?
    Dear Chris,
    for sure. Tomorrow I'll post the .h file.

    Regards

  13. #13
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by ChrisW67 View Post
    Could you post (attach) the generated header file?
    I tried to send the files you asked for but the forum says they are bigger than the limit.
    If you have a mail address I can send them to you.

    Regards

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: dynamicCall and QByteArray - strange characters

    Compress them. Then you will be able to attach them to your post. And only send the relevant file (.h).

  15. #15
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by wysota View Post
    Compress them. Then you will be able to attach them to your post. And only send the relevant file (.h).
    Ok Wysota thank you.
    I compressed PallyCom.h in PallyCom.zip ( 8K )

    Regards
    Attached Files Attached Files

  16. #16
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by wysota View Post
    Compress them. Then you will be able to attach them to your post. And only send the relevant file (.h).
    Wysota I saw some data calling the routine in a C# console application and I had to do a conversion byte to ascii to see something.
    I think if for that that I can not see nothing in Qt. How can I convert the bytearray in ascii?
    I also saw that the stream of data contains lots of '\0' and for that maybe I can not see well all characters.

    Best
    Last edited by franco.amato; 21st April 2010 at 20:31.

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by franco.amato View Post
    How can I convert the bytearray in ascii?
    What did you already try to do it?

  18. #18
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by wysota View Post
    What did you already try to do it?
    Hi,
    first I have know how to access to every byte contained in the bytearray and discover how Qt manage the '\0' as in the
    returned stream I have lots of such character
    Franco Amato

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by franco.amato View Post
    Hi,
    first I have know how to access to every byte contained in the bytearray and discover how Qt manage the '\0' as in the
    returned stream I have lots of such character
    Then open the documentation of QByteArray and read it. I can tell you that Qt doesn't "manage" null bytes in any way. They are bytes like any other.

  20. #20
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by wysota View Post
    Then open the documentation of QByteArray and read it.
    This is was I already did many times

    I can tell you that Qt doesn't "manage" null bytes in any way. They are bytes like any other.
    This is the result of the routine call in a cmd line app written in C#:

    "I??\0\0xml;q=0.Franco\0\0\0\0\0\0\0\0\0Amato\0\0 \0\0\0\0\0\0\0\0\0\0\0\0AAAAAAAAAAAAAAA=0\0\n \n0987654321`E?\"UF ??\fCQ????O\"D ?\v2??(E??\n2F?D?\fH1\b\vH???\nIae?.???(?`>?/?p<?;M???????:????\"8??`:?!???PQ?\r??`'?`2 ??Q)\n??#3?????#34????\"34????\"34O???\"34O? ??\"#3D???#4D???#4D???#4D???34D???\"3DD? ??#DDE???4DTE???4UUEo??EUUUo???VffUo???ffff?? ?wwff????wwvg?\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0"
    You can see many '\0' but why debuggind with visual studio my Qt app I can not see the same string that's should contained in the QByteArray? And also I really don't understand which characteres are these:     ??

    I hope you can help me
    Franco Amato

Similar Threads

  1. Replies: 0
    Last Post: 16th April 2010, 23:21
  2. Regarding qbytearray
    By mohanakrishnan in forum Qt Programming
    Replies: 7
    Last Post: 19th November 2009, 13:38
  3. Replies: 9
    Last Post: 25th July 2009, 13:27
  4. Replies: 1
    Last Post: 28th May 2008, 16:52
  5. QByteArray in Qt3
    By joseph in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2007, 06:16

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.