Hi,
how can I call a class constructor (which is built form another class) in spec file? Can anyone provide me an example?
This is possible, although it is not immediately obvious. Here is the solution I use (I will document this one day but I'm very busy ATM):
Scenario 1: App uses C++ dll, dll does not use win32 calls
Solution: Compile as non wine dll (unix .so) and link.
Scenario 2: App uses C++ dll, dll uses win32 calls
Solution 1: Static link with the object files of the dll. Winebuild will resolve references to win32 calls.
Solution 2: Use native .exe and dlls
Solution 3: Compile as wine dll with one extern "C" dummy function that does nothing. Do _not_ attempt to export any C++ symbols. install the resulting .dll.so as: /usr/local/lib/wine/NAME.dll.so and place a soft link to it as /usr/local/lib/libNAME.dll.so
Don't forget to install the .def file as: /usr/local/lib/wine/libNAME.def
Link as a wine dll _and_ a unix .so. e.g:
wineg++ -mwindows -o app.exe.so <opts> -lNAME -lNAME.dll
In any dll or program that calls functions from the dll, place a call to your dummy function immediately after WinMain(). This will force winebuild to link to the dll and the loader to set up the Win32 function pointers in the dll. Due to dlopen magic the ctors/dtors for statics will only be called once.
Be carefull with the order of static object initialisation, you may need to use gcc's attribute init_priority to ensure correct ordering, or defer static initialisation until after loading
Hope this helps, Jon
===== "Don't wait for the seas to part, or messiahs to come; Don't you sit around and waste this chance..." - Live
jon_p_griffiths@yahoo.com
__________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail
Jon Griffiths wrote:
I have to write a spec file so that a winelib application can use a third party dll. The problem is that APIs in third party dll are written in C++. As c++ names and parameters are mangled, how can i call them in spec file? how can I call a class constructor (which is built form another class) in spec file? Can anyone provide me an example?
This is possible, although it is not immediately obvious.
I think the original poster wanted to use a closed-source third-party DLL written in C++ and compiled with MSVC. AFAIK none of your suggestions address that case. - Dan
Hi,
I think the original poster wanted to use a closed-source third-party DLL written in C++ and compiled with MSVC. AFAIK none of your suggestions address that case.
If source for the dll isn't available then the only option i can think of is as follows:
WARNING: Untested, but should work(tm). its a lot of effort however.
Take the header(s) for the dll and compile them into a winelib dll as per previous instructions, method 3. You will need to write dummy code for each object method. Add to the implementation of each class a pointer to the real class in the native dll. In each dummy method proxy the call to the real dll, using GetProcAddress and passing the real class pointer using the msvcrt convention (this = %ecx, ). If a class has public members, update them from the object pointer before returning.
See dlls/msvcrt/tests/cpp.c for an example of calling native C++ object methods from Wine and accessing object members.
Link with the modified dll as per method 3 and all calls should go to the native dll.
If you try this let me know how you get on. I've been mulling the possibility of automatically creating thunks like this for a couple of years now.
Hope this helps, Jon
===== "Don't wait for the seas to part, or messiahs to come; Don't you sit around and waste this chance..." - Live
jon_p_griffiths@yahoo.com
__________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail
Hello, Actually I have the source code for the dll. Because a lot of classes in that dll are implemented in inline assembly for VC compiler and inline assembly sytax difference between vc and gcc, i thought the simple way is to use wine (winelib) and just call class methods of the dll when they are needed in other part of code (which is built as linux native).
I don't know much about wine, so could you provide me more detailed description with an example on how this can be done? Thanks.
Wu
On Fri, 1 Oct 2004, Jon Griffiths wrote:
Hi,
I think the original poster wanted to use a closed-source third-party DLL written in C++ and compiled with MSVC. AFAIK none of your suggestions address that case.
If source for the dll isn't available then the only option i can think of is as follows:
WARNING: Untested, but should work(tm). its a lot of effort however.
Take the header(s) for the dll and compile them into a winelib dll as per previous instructions, method 3. You will need to write dummy code for each object method. Add to the implementation of each class a pointer to the real class in the native dll. In each dummy method proxy the call to the real dll, using GetProcAddress and passing the real class pointer using the msvcrt convention (this = %ecx, ). If a class has public members, update them from the object pointer before returning.
See dlls/msvcrt/tests/cpp.c for an example of calling native C++ object methods from Wine and accessing object members.
Link with the modified dll as per method 3 and all calls should go to the native dll.
If you try this let me know how you get on. I've been mulling the possibility of automatically creating thunks like this for a couple of years now.
Hope this helps, Jon
===== "Don't wait for the seas to part, or messiahs to come; Don't you sit around and waste this chance..." - Live
jon_p_griffiths@yahoo.com
Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail