M
Markus
Hi!
I came across the following problem I have to solve. The operating
system is WinXP Pro.
There are two programs, a C++- and a Java-program. The two programs
have to exchange data. I was looking for an effective way to do that,
and finally I chose a file as "shared resource". Both, C++ and Java
must read/write into the shared resource. However, the file must not
be accessed simultaneously by both of them. Additionally there could
be several instances of the C++-progamm.
1. The C++-Side
I use the CFile-Class from MFC with Visual C++. The CFile-Class
enables to open a file in exclusive-mode as following:
CFile MyFile;
MyFile.Open("filename", CFile::modeWrite | CFile::shareExclusive);
Using Random File Access I read and write the following type of struct
in/from the file:
struct t_dataset {
int flag;
int ID;
char Telegramm[29];
};
Ok, up to now it works pretty well so far.
2. The Java-Side
Browsing and searching the Java-Docs I found out that there is a
"FileLock"-class which enables to lock a file in terms of the used
operating system. The mechanism is for instance described here:
http://developer.java.sun.com/developer/JDCTechTips/2002/tt0924.html
Here are my questions:
- Is there a much more effective way to exchange data between my C++-
and Java-programmes on a windows-platform? If so which one do you
suggest and why is it better than files?
- How can I implement the file-access in Java? Assumed I use the
"RandomAccessFile"-class, there are just methods like this:
+int read(byte[] b, int off, int len)
+void write(byte[] b, int off, int len)
So how can I handle the data defined in the C++-struct above? As far
as I know I would have to define a class like
class t_dataset {
int flag;
int ID;
...
}
But I think that's not a good solution.
Do I have to read a byte-stream and afterwards "extract" and cast the
data?
Thank you,
Markus
I came across the following problem I have to solve. The operating
system is WinXP Pro.
There are two programs, a C++- and a Java-program. The two programs
have to exchange data. I was looking for an effective way to do that,
and finally I chose a file as "shared resource". Both, C++ and Java
must read/write into the shared resource. However, the file must not
be accessed simultaneously by both of them. Additionally there could
be several instances of the C++-progamm.
1. The C++-Side
I use the CFile-Class from MFC with Visual C++. The CFile-Class
enables to open a file in exclusive-mode as following:
CFile MyFile;
MyFile.Open("filename", CFile::modeWrite | CFile::shareExclusive);
Using Random File Access I read and write the following type of struct
in/from the file:
struct t_dataset {
int flag;
int ID;
char Telegramm[29];
};
Ok, up to now it works pretty well so far.
2. The Java-Side
Browsing and searching the Java-Docs I found out that there is a
"FileLock"-class which enables to lock a file in terms of the used
operating system. The mechanism is for instance described here:
http://developer.java.sun.com/developer/JDCTechTips/2002/tt0924.html
Here are my questions:
- Is there a much more effective way to exchange data between my C++-
and Java-programmes on a windows-platform? If so which one do you
suggest and why is it better than files?
- How can I implement the file-access in Java? Assumed I use the
"RandomAccessFile"-class, there are just methods like this:
+int read(byte[] b, int off, int len)
+void write(byte[] b, int off, int len)
So how can I handle the data defined in the C++-struct above? As far
as I know I would have to define a class like
class t_dataset {
int flag;
int ID;
...
}
But I think that's not a good solution.
Do I have to read a byte-stream and afterwards "extract" and cast the
data?
Thank you,
Markus