Interop, PInvoke data coming from an umanaged source

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got the following umanaged code that I need to handle in C# code. The
data I read comes from an external device, by Read(ID, &data, REGLEN);


How should the code look for the structs in C# to handle "PULONG Value" in
the function call and the "PktArray[0].pbyBuf = (PUCHAR)&regAddr;"
"PktArray[1].pbyBuf = (PBYTE) pValue;" statement in C# so I get read data
from an external device?

*******Code******
typedef struct
{
PBYTE pbyBuf; // Message Buffer
WORD wlen; // Message Buffer Length
LPINT lpiresult; // Contains the result of the operation
} PACKET, *pPack;

typedef struct
{
PACKET *pPack;
Int32 Inumpackets;
} XFER

DLG::Read(USHORT regAddr, PULONG Value, UCHAR regLen)
{
ULONG data;
XFER xferBlock;
PACKET PktArray[2];
INT iResult;

PktArray[0].pbyBuf = (PUCHAR)&regAddr;
PktArray[0].wLen = sizeof(UCHAR); // let know how much to transmit

PktArray[0].byRW = RW_WRITE;
PktArray[0].byAddr = m_Base;
PktArray[0].lpiResult = &iResult; // if encounter an error,
// it will write to *iResult.

PktArray[1].pbyBuf = (PBYTE) pValue;
PktArray[1].wLen = regLen; // how much to receive

****App Code****

Read(ID, &data, REGLEN);
 
Tonofit said:
I've got the following umanaged code that I need to handle in C# code. The
data I read comes from an external device, by Read(ID, &data, REGLEN);


How should the code look for the structs in C# to handle "PULONG Value" in
the function call and the "PktArray[0].pbyBuf = (PUCHAR)&regAddr;"
"PktArray[1].pbyBuf = (PBYTE) pValue;" statement in C# so I get read data
from an external device?

*******Code******
typedef struct
{
PBYTE pbyBuf; // Message Buffer
WORD wlen; // Message Buffer Length
LPINT lpiresult; // Contains the result of the operation
} PACKET, *pPack;

typedef struct
{
PACKET *pPack;
Int32 Inumpackets;
} XFER

DLG::Read(USHORT regAddr, PULONG Value, UCHAR regLen)
{
ULONG data;
XFER xferBlock;
PACKET PktArray[2];
INT iResult;

PktArray[0].pbyBuf = (PUCHAR)&regAddr;
PktArray[0].wLen = sizeof(UCHAR); // let know how much to transmit

PktArray[0].byRW = RW_WRITE;
PktArray[0].byAddr = m_Base;
PktArray[0].lpiResult = &iResult; // if encounter an error,
// it will write to *iResult.

PktArray[1].pbyBuf = (PBYTE) pValue;
PktArray[1].wLen = regLen; // how much to receive

****App Code****

Read(ID, &data, REGLEN);

DeviceIoControl(m_h, // file handle to the driver
XX_IOCTL_TRANSFER, // I/O control code
(PBYTE) &Xfer, // in buffer
sizeof(XX_TRANSFER_BLOCK), // in buffer size
NULL, // out buffer
0, // out buffer size
NULL, // number of bytes returned
NULL);
 
Tonofit said:
I've got the following umanaged code that I need to handle in C# code. The
data I read comes from an external device, by Read(ID, &data, REGLEN);


How should the code look for the structs in C# to handle "PULONG Value" in
the function call and the "PktArray[0].pbyBuf = (PUCHAR)&regAddr;"
"PktArray[1].pbyBuf = (PBYTE) pValue;" statement in C# so I get read data
from an external device?

*******Code******
typedef struct
{
PBYTE pbyBuf; // Message Buffer
WORD wlen; // Message Buffer Length
LPINT lpiresult; // Contains the result of the operation
} PACKET, *pPack;

typedef struct
{
PACKET *pPack;
Int32 Inumpackets;
} XFER

DLG::Read(USHORT regAddr, PULONG Value, UCHAR regLen)
{
ULONG data;
XFER xferBlock;
PACKET PktArray[2];
INT iResult;

PktArray[0].pbyBuf = (PUCHAR)&regAddr;
PktArray[0].wLen = sizeof(UCHAR); // let know how much to transmit

PktArray[0].byRW = RW_WRITE;
PktArray[0].byAddr = m_Base;
PktArray[0].lpiResult = &iResult; // if encounter an error,
// it will write to *iResult.

PktArray[1].pbyBuf = (PBYTE) pValue;
PktArray[1].wLen = regLen; // how much to receive

****App Code****

Read(ID, &data, REGLEN);

DeviceIoControl(m_hXX, // file handle to the driver
XX_IOCTL_TRANSFER, // I/O control code
(PBYTE) &XFER, // in buffer
sizeof(XX_TRANSFER_BLOCK), // in buffer size
NULL, // out buffer
0, // out buffer size
NULL, // number of bytes returned
NULL);
 
Back
Top