Free Downloads, Community Forum,
FAQs and Developer Resources


Make /Tools Your Home | Link to us

Today's posts | Posts since last visit | Most Active Topics

All Forums Register Login Search Subscriptions My Profile Inbox
Tool Warehouse FAQs Resources Help Member List Address Book Logout

accessing shared library

 
Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [SFU / Interix / SUA Technology] >> Interix Advanced Forum >> accessing shared library Page: [1]
Login
Message << Older Topic   Newer Topic >>
accessing shared library - Aug. 31, '05, 3:37:55 AM   
leokirch

 

Posts: 4
Joined: Aug. 30, '05,
Status: offline
hi,

i've got a .so shared library with the function "void CALLME (char* data)" that i want to access from within a native windows application. what i tried to far is to write a wrapper around that library running on interix that provides shared memory via mmap and to get access to to that memory via CreateFileMapping on the native side. i dont have to tell you that i wasnt successful at all :) i can shared data between two windows applications but cant get access to that interop data... are there any samples showing how to do it exactly (msdn isnt very useful that way)? or is there a even better way, possibly withouth creating a wrapper at interix and calling the file in a direct way?

thanks a lot
Post #: 1
RE: accessing shared library - Aug. 31, '05, 8:52:54 AM   
Rodney

 

Posts: 3142
Joined: Jul. 9, '02,
From: /Tools lab
Status: online
Two things:
1)
With Interix you do not make calls to Win32 API's & visa versa (to Interix 3.5).
The model used for shared memory access is different between Unix and Win32.
So you need to be vary carefully if you want to mix Win32 and Unix code. For
"good" code you should try and find a better design than mixing the pardigms.
That all said, starting with Interix 5.2 (SUA on W2K3/R2) you'll be able to make
these mixed calls. But because of the different paradigms you need to be careful
for what it means.

2) Shared memory (mmap()) does count as one of the methods that data can be shared
between an Interix/Unix application and a Win32 application. MSDN doesn't have an
example as far as I know either, but I have successfully done this. Create the mmap()
on the Interix side first (not required, but I found this the easiest way). Communicate
to the Win32 program the filename (by sockets or perhaps as an argument to the program).
Then on the Win32 side make the calls like it's a new mapping (for which there are several
examples on MSDN): Open(), CreateFileMapping(), MapViewOfFile(), UnmapViewOfFile(), CloseHandle().
Coordination is up to you. There is no "really nice" co-ordination API, such as semaphores or
signals, between the two subsystems.
Even though you "name" a file for the shared memory it's all done in memory. You don't need to
sync to the disk for the "other side" to see a change in the data in the shared memory.

(in reply to leokirch)
Post #: 2
RE: accessing shared library - Aug. 31, '05, 9:08:23 AM   
leokirch

 

Posts: 4
Joined: Aug. 30, '05,
Status: offline
aha! "Open()" does the trick... i used "Global\\anyvalue" as identifier.

CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(mydata), "Global\\lkdjf");


the coordination problem would be easier if i'd use a tcpstream. do you agree? or would you suggest using mmap? i need access within java: my first thought was to create a wrapper on interix, a jni wrapper on win and the appropriate java classes including calling the win jni. but i guess one step could be ommited if i'd use plain tcp messages... just worrying about performance

thanks again

< Message edited by leokirch -- Aug. 31, '05, 9:10:54 AM >

(in reply to Rodney)
Post #: 3
RE: accessing shared library - Aug. 31, '05, 12:41:01 PM   
Rodney

 

Posts: 3142
Joined: Jul. 9, '02,
From: /Tools lab
Status: online
> aha! "Open()" does the trick... i used "Global\\anyvalue" as identifier.

You should be choosing a fileystem path that can be accessed by both Interix and Win32.
You can then use unixpath2win() or winpath2unix() to do the conversion between syntax (see the man pages).

> the coordination problem would be easier if i'd use a tcpstream. do you agree?

Depends on how much co-ordination you need and the frequency.
A tcp socket stays within the stack (not pushed to the actual device) so that's usually
speedy (for lag time to delivery) for most applications). That also allows you to use
select() to test when data is ready thus reducing resource overhead/consumption. So
this is a reasonable way to do it for most applications. Otherwise you need to make your
own shared spin-lock which can consume a lot of resources.

(in reply to leokirch)
Post #: 4
Page:   [1]
All Forums >> [SFU / Interix / SUA Technology] >> Interix Advanced Forum >> accessing shared library Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Search All Forums -

Advanced search


SPONSORS



Forum Software © ASPPlayground.NET Advanced Edition 2.5 ANSI

0.047