El día Friday, March 08, 2019 a las 09:00:27PM +0800, Liu Hao escribió:
> 在 2019/3/8 20:43, Matthias Apitz 写道:
> >
> > Hello,
> >
> > The next DLL I have to recompile for 64-bit was written on top of some
> > packages Microsoft ATL (Active Template Library), which includes the
> > header atlbase.h with VC++. Is there anything for this in MinGW?
> >
>
> No. But you may want to have a look at the one in ReactOS [1] which is
> supposed to compile with both MSVC and GCC.
>
> [1] https://github.com/reactos/reactos/blob/master/sdk/lib/atl/atlbase.h
Thanks for the pointer. All that DLL is only made from one small C++
file and when I do read it right it does not make use of ATL, but only
of a CString class provided there. Maybe we should rewrite it better
with std::string? It serves only for the Java app to write bytes to some
serial device.
matthias
Serout.cpp
#include
#include
#include "sisis_lib_serout_Serout.h"
bool WriteComPort(CString PortSpecifier, CString portInformation, jbyte* data,
jsize size);
void AdustDCB(CString portInformation, DCB* dcb);
JNIEXPORT jint JNICALL Java_sisis_lib_serout_Serout_SeroutC
(JNIEnv* env, jclass c, jstring jPort, jbyteArray array)
{
CString portSpecifier((char *) env->GetStringChars(jPort, 0));
CString portInformation = portSpecifier.Right(portSpecifier.GetLength()
- portSpecifier.Find(":", 0) - 1);
portSpecifier.Truncate(portSpecifier.Find(":", 0));
jbyte* data = env->GetByteArrayElements(array, NULL);
jsize size = env->GetArrayLength(array);
if (data != NULL && size > 0) {
bool res = WriteComPort(portSpecifier, portInformation, data,
size);
env->ReleaseByteArrayElements(array, data, JNI_ABORT);
}
return JNI_FALSE;
}
bool WriteComPort(CString PortSpecifier, CString portInformation, jbyte* data,
jsize size)
{
DCB dcb;
DWORD byteswritten;
HANDLE hPort = CreateFile(
PortSpecifier,
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL
);
if (!GetCommState(hPort, ))
return false;
AdustDCB(portInformation, );
if (!SetCommState(hPort, ))
return false;
bool retVal = WriteFile(hPort, data, size, , NULL);
CloseHandle(hPort); //close the handle
return retVal;
}
void AdustDCB(CString properties, DCB* dcb)
{
int curpos = 0;
CString token;
token = properties.Tokenize(",", curpos);
if (!token.IsEmpty()) {
dcb->BaudRate = _ttoi(token);
}
token = properties.Tokenize(",", curpos);
if (!token.IsEmpty()) {
// Parity(N = No, E = Even, O = Odd, M = Mark, S = Space
if (token.Compare("N") == NULL) {
dcb->Parity = NOPARITY;
}
else if (token == 'E') {
dcb->Parity = EVENPARITY;
}
else if (token == 'O') {
dcb->Parity = ODDPARITY;
}
else if (token == 'M') {
dcb->Parity = MARKPARITY;
}
else if (token == 'S') {
dcb->Parity = SPACEPARITY;
}
}
token = properties.Tokenize(",", curpos);
if (!token.IsEmpty()) {
// ByteSize
dcb->ByteSize = _ttoi(token);
}
token = properties.Tokenize(",", curpos);
if (!token.IsEmpty()) {
// StopBit
dcb->ByteSize = _ttoi(token);
}
}
--
Matthias Apitz, ✉ g...@unixarea.de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public