Results 1 to 6 of 6

Thread: Can't pass argument correctly from MSVC DLL to minGW App

  1. #1
    Join Date
    Mar 2010
    Location
    China
    Posts
    10
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Can't pass argument correctly from MSVC DLL to minGW App

    hi all,

    i get truble when passing argument in a Foo function from MSVC DLL to a minGW application....

    i tried the following code and get unexpected result:

    /// MSVC DLL code

    // XyzLibrary.h

    Qt Code:
    1. #ifdef XYZLIBRARY_EXPORTS
    2. #define XYZAPI __declspec(dllexport)
    3. #else
    4. #define XYZAPI __declspec(dllimport)
    5. #endif
    6.  
    7. #ifdef __cplusplus
    8. # define EXTERN_C extern "C"
    9. # define XYZHANDLE IXyz*
    10.  
    11. struct IXyz
    12. {
    13. virtual int Foo(int n) = 0;
    14. virtual void Release() = 0;
    15. };
    16.  
    17. #endif
    18.  
    19. EXTERN_C XYZAPI int hzf (int);
    20. EXTERN_C XYZAPI XYZHANDLE hzfXyz (VOID);
    To copy to clipboard, switch view to plain text mode 



    // XyzLibrary.cpp

    Qt Code:
    1. #include "stdafx.h"
    2. #include "stdio.h"
    3. #include "XyzLibrary.h"
    4.  
    5.  
    6. class XyzImpl : public IXyz
    7. {
    8. public:
    9. int Foo(int n);
    10. void Release();
    11. };
    12.  
    13. int XyzImpl::Foo(int n)
    14. {
    15. printf("Foo called....%d\n",n);
    16. return n * n;
    17. }
    18.  
    19. void XyzImpl::Release()
    20. {
    21. delete this;
    22. }
    23.  
    24.  
    25. XYZHANDLE hzfXyz()
    26. {
    27. printf("\n\nhzfXyz() called ....\n");
    28. return new XyzImpl;
    29. }
    30.  
    31. int hzf(int n)
    32. {
    33. printf("\n\nhzf(int) called ....\n");
    34. XyzImpl *xyz = new XyzImpl;
    35. return xyz->Foo(n);
    36. }
    To copy to clipboard, switch view to plain text mode 

    I compiled the code and get a XyzLibrary.dll



    /// minGW code.....

    Qt Code:
    1. #include <stdio.h>
    2. #include "XyzLibrary.h"
    3.  
    4.  
    5. int main(int ,char** )
    6. {
    7. IXyz *xxx = hzfXyz();
    8. printf(" hzfXyz call: %d\n" , xxx->Foo(5));
    9.  
    10. printf(" hzf call: %d\n" , hzf(8));
    11.  
    12. return 0;
    13. }
    To copy to clipboard, switch view to plain text mode 

    i compiled the code above with minGW in Qt creator2, got main.exe and then run it....


    the consloe outputs the following result:

    hzfXyz() called ....
    Foo called....169091488 /// here the number should be 5 , but i got 169091488
    hzfXyz call: -982866944 ///here the number should be 25, buit i got 169091488 * 169091488 ,flow over....

    hzf(int)
    Foo called....8
    hzf call: 64 //// here hzf(int) called ,and everything goes well




    i have attached the disassembler window, ss.jpg

    could somebody tell me why can't transfer correct value when i call xxx->Foo(5) from minGW App to MSVC DLL ??

    I really hope this two compilers cooperate with each other little well.....








    hzf(int)
    Foo called....8
    hzf call: 64

  2. #2
    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: Can't pass argument correctly from MSVC DLL to minGW App

    The two compilers have completely different name mangliing schemes. It is possible to use a library compiled with one for the other but it requires some other tool that will translate the imports to the dialect understood by the other compiler.

    Can't you use the same compiler for both the library and the application?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2010
    Location
    China
    Posts
    10
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Can't pass argument correctly from MSVC DLL to minGW App

    Quote Originally Posted by wysota View Post
    The two compilers have completely different name mangliing schemes. It is possible to use a library compiled with one for the other but it requires some other tool that will translate the imports to the dialect understood by the other compiler.

    Can't you use the same compiler for both the library and the application?
    thanks a lot for your reply, wysota, you are one of the best man here....
    Sorry , because i need to include ws2bth.h header file and call bluetooth functions in ws2_32.lib,
    i can't find this two file in mingw's include/lib folder, so i include them from window's SDK,
    it only get compiled with MSVC, i tried to use minGW do the same thing , i got so many errors.....
    i have no idea, although, i want to use minGW do all the things.....
    could you please tell me some alternative ways to call bluetooth functions on windows with minGW??

    Thank you very much.....

  4. #4
    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: Can't pass argument correctly from MSVC DLL to minGW App

    So why don't you compile your whole app with MSVC?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    radory (20th September 2010)

  6. #5
    Join Date
    Mar 2010
    Location
    China
    Posts
    10
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Can't pass argument correctly from MSVC DLL to minGW App

    yes ,this is a good option....i will consider it....
    i just prefer Qt creator much then ms visual studio, i have the set up qt develop environment with minGW, and
    don't want to set up msvc-qt again, msvc is a big thing , i don't like it, and don't like msvc's code style, it uses
    lot of #define/typedef directives , it is hard to understand.....although there are plenty of people use msvc in
    China....of course, most of them , are copies....
    thanks you again, Mr wysota....

  7. #6
    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: Can't pass argument correctly from MSVC DLL to minGW App

    Quote Originally Posted by radory View Post
    i just prefer Qt creator much then ms visual studio,
    You can use Qt Creator with MSVC. It's the compiler that you are going to change, not the IDE.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. how to set QT Creator to use MSVC++ compiler instead of mingw
    By hcetiner in forum Installation and Deployment
    Replies: 5
    Last Post: 28th March 2010, 20:55
  2. Replies: 3
    Last Post: 28th February 2010, 09:10
  3. Mingw vs MSVC?
    By vbman213 in forum Newbie
    Replies: 3
    Last Post: 18th February 2010, 08:51
  4. Open source dev on windows: MinGW vs MSVC
    By magland in forum Installation and Deployment
    Replies: 4
    Last Post: 29th December 2007, 09:20
  5. qmake for both msvc/mingw ?
    By gfunk in forum Qt Programming
    Replies: 2
    Last Post: 24th November 2007, 13:06

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.