473,395 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Interop, PInvoke data coming from an umanaged source

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);

Jun 14 '07 #1
2 2697


"Tonofit" wrote:
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);
>
Jun 14 '07 #2


"Tonofit" wrote:
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);
>
Jun 14 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: L | last post by:
Hi, As C# doesn't support Adobe fonts, I am writing interop to provide support for AdobeFonts in my application. I have copied interop code for TextOut, SelectObject, DeleteObject from the...
17
by: Aaron | last post by:
I've got a doozie of a problem! I and others have been trying to figure this out for too long and I've come to the conclusion that I should probably look for some support.. Ok, I have a COM...
6
by: Nataraj1978 | last post by:
I have a requirement to use a dll written in Visual C++ 6.0 in my C# application. In order to establish the link between my application and the dll, I have written a ATL COM Component in Visual...
3
by: msnews.microsoft.com | last post by:
Hi i am using User32.dll in Visual stdio 2005. public static extern long SetActiveWindow(long hwnd); public static extern long keybd_event(byte bVk, byte bScan, long dwFlags,
2
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using a COM DLL in my C# application (a single process). This COM DLL generates a data array, and by using the interop DLL (generated by VS/TlbImp.exe), I'm getting this array to a safe Array...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
5
by: John | last post by:
I would like to ask a question that is obvious to all people porting applications from the "traditional" C\VB6 interop scheme choosing C# vs VB.NET. We have a math library in C which...
0
by: user2008 | last post by:
Hi everybody, I'm working on exposing a .Net (C#) COM Server. Manage Code is exposting an interface with two methods. These methods take an IN/OUT Struct as parameter. Requirement is that the...
5
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I've been tasked to translate a C# program to VB. (Dot Net 2.0.) I'm starting from scratch with no documentation and I'm trying to understand what the original programmer did. (The 'original...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.