Re: How to Calling PE Dlls on linux??

2007-08-22 Thread trulyliu
 Hi, Damjan Jovanovic

Thank you tired of the answer to my questions.

I carefully read the wine part of the code and development document,
searched in mail lists, these days.
And I got some inspiration from wine plugin API wiki page and wine loader's
code.

I am considering of an approach.

Link preloader and related resource(libwine) with my Linux native App.
Do some modify with wine_init function, and call it before main().
This can be implemented by a global C++ objects's constructor.
Upper two steps can deal with TEP and FS register.

But I there may be another problem.
If there was aready an static global C++ object in my App,
How can I makde it initiatited after wine_init from in object.

Do you have some other expostulate of this idea?


BTW, I skim over mplayer and xine's parts of code.
They don't dealwith TEB and FS register.
They only do sth on LDT and allocat PE header before LoadeLibaray.
Why they can run correctly???



2007/8/22, Damjan Jovanovic [EMAIL PROTECTED]:

 On 8/21/07, trulyliu [EMAIL PROTECTED] wrote:
 
 
 
  2007/8/21, Damjan Jovanovic [EMAIL PROTECTED]:
   On 8/21/07, trulyliu [EMAIL PROTECTED] wrote:
   
   
2007/8/21, Damjan Jovanovic [EMAIL PROTECTED]:
 On 8/21/07, trulyliu [EMAIL PROTECTED] wrote:
  Can I made Arithmetic.dll.so ? And link it against my linux App?

 A library function runs in the context of the process that invokes
 it.
 A library doesn't have its own TEB/memory layout/exception
 handling
 that works independently of the process that calls it, no matter
 how
 it is compiled. If the wine plugin API is ever made, it will
 modify
 the process so it has what the library expects when the library
 functions are called.

 Does your Arithmetic.dll.so call any Windows functions? If so, you
 need wine and you will always need wine, plugin API or no plugin
 API,
 whether you compile it into a DLL or .dll.so. But if you only use
 ANCI
 C stuff you can compile it into a .so and use it without wine.

 If you want something that runs seamlessly on every operating
 system
 today, IMHO you should consider Java.


   
   
Yes, Java may be a good choice for crossing platform.
   
As you said, my Arithmetic.dll does not call any windows function.
It's pure ANSI C library. What's the step of make .dll.so ??
   
Use winegcc or gcc ??
  
   Use gcc and make a .so like this:
   gcc -c arithmetic.c -fPIC
   gcc arithmetic.o -shared -o arithmetic.so
  
   Then put it in /usr/lib and link to it like so:
   gcc -c application.c
   gcc application.o -o application -larithmetic
  
  --
  [EMAIL PROTECTED]
 Damjan
--
[EMAIL PROTECTED]
   
  
   Damjan
 
  gcc -c arithmetic.c -fPIC  ???
  I am sorry. I don't have Arithmetic.dll's source code.
  Can I use LoadLibaray() and GetProcAddress
  to get the function which Arithmetic.dll exports.

 No, for the reasons I talked about before. Eg. GetProcAddress() does
 look  up the current directory, which resides in the TEB, which AFAIK
 resides in the FS CPU register on Windows. On Linux the FS register
 contains something else, leading to a crash.

 At the moment, you can only use Windows DLLs from Windows applications
 or from winelibs, which are Windows applications compiled to be able
 to use Linux libraries as well.

  --
  [EMAIL PROTECTED]
 

 Damjan




-- 
[EMAIL PROTECTED]



Re: How to Calling PE Dlls on linux??

2007-08-22 Thread trulyliu
The issue of the order of global  C++ object's constrution has been metioned

in wine development guid section 8.3.3.Starting a Winelib process

For the first scheme,
how can we made win_init as the entry of .init section.
Implement like .strat() in preloader.c 



2007/8/22, trulyliu [EMAIL PROTECTED]:

  Hi, Damjan Jovanovic

 Thank you tired of the answer to my questions.

 I carefully read the wine part of the code and development document,
 searched in mail lists, these days.
 And I got some inspiration from wine plugin API wiki page and wine
 loader's code.

 I am considering of an approach.

 Link preloader and related resource(libwine) with my Linux native App.
 Do some modify with wine_init function, and call it before main().
 This can be implemented by a global C++ objects's constructor.
 Upper two steps can deal with TEP and FS register.

 But I there may be another problem.
 If there was aready an static global C++ object in my App,
 How can I makde it initiatited after wine_init from in object.

 Do you have some other expostulate of this idea?


 BTW, I skim over mplayer and xine's parts of code.
 They don't dealwith TEB and FS register.
 They only do sth on LDT and allocat PE header before LoadeLibaray.
 Why they can run correctly???



 2007/8/22, Damjan Jovanovic [EMAIL PROTECTED]:
 
  On 8/21/07, trulyliu [EMAIL PROTECTED] wrote:
  
  
  
   2007/8/21, Damjan Jovanovic [EMAIL PROTECTED]:
On 8/21/07, trulyliu [EMAIL PROTECTED] wrote:


 2007/8/21, Damjan Jovanovic [EMAIL PROTECTED]:
  On 8/21/07, trulyliu  [EMAIL PROTECTED] wrote:
   Can I made Arithmetic.dll.so http://arithmetic.dll.so/ ? And
  link it against my linux App?
 
  A library function runs in the context of the process that
  invokes it.
  A library doesn't have its own TEB/memory layout/exception
  handling
  that works independently of the process that calls it, no matter
  how
  it is compiled. If the wine plugin API is ever made, it will
  modify
  the process so it has what the library expects when the library
  functions are called.
 
  Does your Arithmetic.dll.so http://arithmetic.dll.so/ call any
  Windows functions? If so, you
  need wine and you will always need wine, plugin API or no plugin
  API,
  whether you compile it into a DLL or .dll.so. But if you only
  use ANCI
  C stuff you can compile it into a .so and use it without wine.
 
  If you want something that runs seamlessly on every operating
  system
  today, IMHO you should consider Java.
 
 


 Yes, Java may be a good choice for crossing platform.

 As you said, my Arithmetic.dll does not call any windows function.
 It's pure ANSI C library. What's the step of make .dll.so ??

 Use winegcc or gcc ??
   
Use gcc and make a .so like this:
gcc -c arithmetic.c -fPIC
gcc arithmetic.o -shared -o arithmetic.so
   
Then put it in /usr/lib and link to it like so:
gcc -c application.c
gcc application.o -o application -larithmetic
   
   --
   [EMAIL PROTECTED]
  Damjan
 --
 [EMAIL PROTECTED]

   
Damjan
  
   gcc -c arithmetic.c -fPIC  ???
   I am sorry. I don't have Arithmetic.dll's source code.
   Can I use LoadLibaray() and GetProcAddress
   to get the function which Arithmetic.dll exports.
 
  No, for the reasons I talked about before. Eg. GetProcAddress() does
  look  up the current directory, which resides in the TEB, which AFAIK
  resides in the FS CPU register on Windows. On Linux the FS register
  contains something else, leading to a crash.
 
  At the moment, you can only use Windows DLLs from Windows applications
  or from winelibs, which are Windows applications compiled to be able
  to use Linux libraries as well.
 
   --
   [EMAIL PROTECTED]
  
 
  Damjan
 



 --
 [EMAIL PROTECTED]




-- 
[EMAIL PROTECTED]



Re: How to Calling PE Dlls on linux??

2007-08-21 Thread Damjan Jovanovic
On 8/21/07, trulyliu [EMAIL PROTECTED] wrote:

 I have tried these code, It works well. Thanks a lot.
 Could I use gcc/g++ instead of winegcc/wineg++ ???
 mplayer use gcc as it's complier? What's the mystery in it?


gcc/g++ would give you the wrong ABI (eg. 4 bytes per wide char
instead of 2 bytes), and the special code needed to set up the Windows
memory layout and the thread extension block and structured exception
handling wouldn't get executed, leading to segfaults when you call any
code that tries to access them. That's assuming you can even compile
and link.

That's why you need winegcc/wineg++.

 [EMAIL PROTECTED]

Damjan




Re: How to Calling PE Dlls on linux??

2007-08-21 Thread Damjan Jovanovic
On 8/21/07, trulyliu [EMAIL PROTECTED] wrote:
 Can I made Arithmetic.dll.so ? And link it against my linux App?

A library function runs in the context of the process that invokes it.
A library doesn't have its own TEB/memory layout/exception handling
that works independently of the process that calls it, no matter how
it is compiled. If the wine plugin API is ever made, it will modify
the process so it has what the library expects when the library
functions are called.

Does your Arithmetic.dll.so call any Windows functions? If so, you
need wine and you will always need wine, plugin API or no plugin API,
whether you compile it into a DLL or .dll.so. But if you only use ANCI
C stuff you can compile it into a .so and use it without wine.

If you want something that runs seamlessly on every operating system
today, IMHO you should consider Java.

 2007/8/21, Damjan Jovanovic [EMAIL PROTECTED] :
  On 8/21/07, trulyliu [EMAIL PROTECTED]  wrote:
 
   I have tried these code, It works well. Thanks a lot.
   Could I use gcc/g++ instead of winegcc/wineg++ ???
   mplayer use gcc as it's complier? What's the mystery in it?
  
 
  gcc/g++ would give you the wrong ABI (eg. 4 bytes per wide char
  instead of 2 bytes), and the special code needed to set up the Windows
  memory layout and the thread extension block and structured exception
  handling wouldn't get executed, leading to segfaults when you call any
  code that tries to access them. That's assuming you can even compile
  and link.
 
  That's why you need winegcc/wineg++.
 
   [EMAIL PROTECTED]
 
  Damjan
 
 
 



 --
 [EMAIL PROTECTED]


Damjan




Re: How to Calling PE Dlls on linux??

2007-08-21 Thread trulyliu
2007/8/21, Damjan Jovanovic [EMAIL PROTECTED]:

 On 8/21/07, trulyliu [EMAIL PROTECTED] wrote:
  Can I made Arithmetic.dll.so ? And link it against my linux App?

 A library function runs in the context of the process that invokes it.
 A library doesn't have its own TEB/memory layout/exception handling
 that works independently of the process that calls it, no matter how
 it is compiled. If the wine plugin API is ever made, it will modify
 the process so it has what the library expects when the library
 functions are called.

 Does your Arithmetic.dll.so call any Windows functions? If so, you
 need wine and you will always need wine, plugin API or no plugin API,
 whether you compile it into a DLL or .dll.so. But if you only use ANCI
 C stuff you can compile it into a .so and use it without wine.

 If you want something that runs seamlessly on every operating system
 today, IMHO you should consider Java.



Yes, Java may be a good choice for crossing platform.

As you said, my Arithmetic.dll does not call any windows function.
It's pure ANSI C library. What's the step of make .dll.so ??

Use winegcc or gcc ??




 
  
  
 
 
 
  --
  [EMAIL PROTECTED]
 

 Damjan





-- 
[EMAIL PROTECTED]



Re: How to Calling PE Dlls on linux??

2007-08-21 Thread Damjan Jovanovic
On 8/21/07, trulyliu [EMAIL PROTECTED] wrote:


 2007/8/21, Damjan Jovanovic [EMAIL PROTECTED]:
  On 8/21/07, trulyliu [EMAIL PROTECTED] wrote:
   Can I made Arithmetic.dll.so ? And link it against my linux App?
 
  A library function runs in the context of the process that invokes it.
  A library doesn't have its own TEB/memory layout/exception handling
  that works independently of the process that calls it, no matter how
  it is compiled. If the wine plugin API is ever made, it will modify
  the process so it has what the library expects when the library
  functions are called.
 
  Does your Arithmetic.dll.so call any Windows functions? If so, you
  need wine and you will always need wine, plugin API or no plugin API,
  whether you compile it into a DLL or .dll.so. But if you only use ANCI
  C stuff you can compile it into a .so and use it without wine.
 
  If you want something that runs seamlessly on every operating system
  today, IMHO you should consider Java.
 
 


 Yes, Java may be a good choice for crossing platform.

 As you said, my Arithmetic.dll does not call any windows function.
 It's pure ANSI C library. What's the step of make .dll.so ??

 Use winegcc or gcc ??

Use gcc and make a .so like this:
gcc -c arithmetic.c -fPIC
gcc arithmetic.o -shared -o arithmetic.so

Then put it in /usr/lib and link to it like so:
gcc -c application.c
gcc application.o -o application -larithmetic

   --
   [EMAIL PROTECTED]
  Damjan
 --
 [EMAIL PROTECTED]


Damjan




Re: How to Calling PE Dlls on linux??

2007-08-21 Thread Jakob Eriksson
trulyliu wrote:



 I have tried these code, It works well. Thanks a lot.
 Could I use gcc/g++ instead of winegcc/wineg++ ???
 mplayer use gcc as it's complier? What's the mystery in it?

AFAIK mplayer uses their own old version of wine they have adapted to
mplayer.



regards,
Jakob





How to Calling PE Dlls on linux??

2007-08-20 Thread trulyliu
hi:

I am sorry to disturb you with a question about calling PE Dll on linux.
This is really an old question.
I found the sameness issues in mail list.

http://www.winehq.org/pipermail/wine-devel/2003-December/thread.html
http://www.winehq.org/pipermail/wine-devel/2005-November/thread.html#41917
http://www.winehq.org/pipermail/wine-users/2004-August/014685.html
http://www.winehq.org/pipermail/wine-devel/2006-August/050619.html

I have tried the ways discussed in these threads。
But it's not clear enough how to do this.
So I send this mail to you for some help.

I have a PE Dll named Arithmetic.dll which exports a function,
it's prototype is:
void sort(unsigned int*, int num)

I want to call the function in my Linux App.

I used winedump to generate a spec file

winedump spec Arithmetic.dll

This comand generated three files: Arithmetic_dll.h Arithmetic_main.c and
Arithmeticspec.
What's the next exactly step I should do?
What's the usage of the three files?
And wow could I use them?


I made reference to mplayer's implementation,
It's code is a little clutter, and I don't have experience on MS D-Show.
Could you give me some simple sample codes ??

Best Regards.

-- 
[EMAIL PROTECTED]



Re: How to Calling PE Dlls on linux??

2007-08-20 Thread Roderick Colenbrander
 I have a PE Dll named Arithmetic.dll which exports a function,
 it's prototype is:
 void sort(unsigned int*, int num)


The easiest way would be to use LoadLibrary/GetProcAddress to load the 
function from the library. That way you avoid linking to it which makes 
things more complicated.

In order to be able to use wine functions you need to (re)compile parts of 
your program using Winelib (e.g. winegcc/wineg++). Your program will depend 
on Wine but you will be able to use the win32 dll.

Regards,
Roderick Colenbrander




Re: How to Calling PE Dlls on linux??

2007-08-20 Thread Damjan Jovanovic
On 8/20/07, trulyliu [EMAIL PROTECTED] wrote:
 hi:

 I am sorry to disturb you with a question about calling PE Dll on linux.
 This is really an old question.
 I found the sameness issues in mail list.

 http://www.winehq.org/pipermail/wine-devel/2003-December/thread.html
 http://www.winehq.org/pipermail/wine-devel/2005-November/thread.html#41917
 http://www.winehq.org/pipermail/wine-users/2004-August/014685.html
 http://www.winehq.org/pipermail/wine-devel/2006-August/050619.html

 I have tried the ways discussed in these threads。
 But it's not clear enough how to do this.
 So I send this mail to you for some help.

 I have a PE Dll named Arithmetic.dll which exports a function,
 it's prototype is:
 void sort(unsigned int*, int num)

 I want to call the function in my Linux App.

You can't, it's not supported (yet), but what you want is the Wine
plugin API (http://wiki.winehq.org/WinePluginApi).

At the moment you have 2 options:
* Make a Windows application instead of a Linux application.
* Make a winelib application which will require wine to run but can
access Linux libraries as well (with some restrictions, eg. you have
to use Windows synchronization primitives instead of the pthreads
ones).

 I used winedump to generate a spec file

 winedump spec Arithmetic.dll

 This comand generated three files: Arithmetic_dll.h Arithmetic_main.c and
 Arithmeticspec.
 What's the next exactly step I should do?
 What's the usage of the three files?
 And wow could I use them?

#include windows.h

int main(int argc, char **argv)
{
 HANDLE h;
 void (/*WINAPI?*/ *sort)(unsigned int,int);
 unsigned int *nums = malloc(sizeof(unsigned int) * 4);
 nums[0] = 3;
 nums[1] = 2;
 nums[2] = 1;
 nums[3] = 0;
 h = LoadLibrary(Arithmetic.dll);
 sort = GetProcAddress(h, sort);
 sort(nums, 4);
}

winegcc main.c -o main
./main


 I made reference to mplayer's implementation,
 It's code is a little clutter, and I don't have experience on MS D-Show.
 Could you give me some simple sample codes ??

MPlayer's code is GPL, so if you use it your code will be GPL too.

 Best Regards.

 --
 [EMAIL PROTECTED]

Good luck
Damjan




Re: How to Calling PE Dlls on linux??

2007-08-20 Thread trulyliu
2007/8/20, Damjan Jovanovic [EMAIL PROTECTED]:

 On 8/20/07, trulyliu [EMAIL PROTECTED] wrote:
  hi:
 
  I am sorry to disturb you with a question about calling PE Dll on linux.
  This is really an old question.
  I found the sameness issues in mail list.
 
  http://www.winehq.org/pipermail/wine-devel/2003-December/thread.html
 
 http://www.winehq.org/pipermail/wine-devel/2005-November/thread.html#41917
  http://www.winehq.org/pipermail/wine-users/2004-August/014685.html
  http://www.winehq.org/pipermail/wine-devel/2006-August/050619.html
 
  I have tried the ways discussed in these threads。
  But it's not clear enough how to do this.
  So I send this mail to you for some help.
 
  I have a PE Dll named Arithmetic.dll which exports a function,
  it's prototype is:
  void sort(unsigned int*, int num)
 
  I want to call the function in my Linux App.

 You can't, it's not supported (yet), but what you want is the Wine
 plugin API (http://wiki.winehq.org/WinePluginApi).

 At the moment you have 2 options:
 * Make a Windows application instead of a Linux application.
 * Make a winelib application which will require wine to run but can
 access Linux libraries as well (with some restrictions, eg. you have
 to use Windows synchronization primitives instead of the pthreads
 ones).

  I used winedump to generate a spec file
 
  winedump spec Arithmetic.dll
 
  This comand generated three files: Arithmetic_dll.h Arithmetic_main.c
 and
  Arithmeticspec.
  What's the next exactly step I should do?
  What's the usage of the three files?
  And wow could I use them?

 #include windows.h

 int main(int argc, char **argv)
 {
  HANDLE h;
  void (/*WINAPI?*/ *sort)(unsigned int,int);
  unsigned int *nums = malloc(sizeof(unsigned int) * 4);
  nums[0] = 3;
  nums[1] = 2;
  nums[2] = 1;
  nums[3] = 0;
  h = LoadLibrary(Arithmetic.dll);
  sort = GetProcAddress(h, sort);
  sort(nums, 4);
 }

 winegcc main.c -o main
 ./main



I have tried these code, It works well. Thanks a lot.
Could I use gcc/g++ instead of winegcc/wineg++ ???
mplayer use gcc as it's complier? What's the mystery in it?



  I made reference to mplayer's implementation,
  It's code is a little clutter, and I don't have experience on MS D-Show.
  Could you give me some simple sample codes ??

 MPlayer's code is GPL, so if you use it your code will be GPL too.

  Best Regards.
 
  --
  [EMAIL PROTECTED]

 Good luck
 Damjan





-- 
[EMAIL PROTECTED]