Re: P/Invoke BYTE *



Since this is a special case, knowing what's to be passed to it, I'd be
inclined to use the scheme found in many of the OpenNETCF classes: you have
a managed class with the fields that you want exposed via get/set methods.
There is also a method to get the structure as a byte[]. Declare the
function to take a byte[], not an IntPtr. This provides the flexibility to
easily call the function with a variety of different structures, since they
just have to be convertable to byte[].

Paul T.

"Mario" <alphatommy@xxxxxxxxxxx> wrote in message
news:1154390414.492187.272730@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks for your replies. I think I got it semi working. I can write,
but can not get any return values. Again, I might be reading it wrong.
Another question that I have is that on another function it has a
parameter of type LPCVOID. According to some docs that I have found,
type LPCVOID should be translated into type IntPtr when calling from
C#. I also know that LPCVOID is pointed to a structure that has the
following members:

typedef struct {

UINT32 val1;
UINT32 val2;
UNIT32 val3;
} Sample_t, *pSample_t

What would I need to do to use this function from C#? Thanks for your
help.

Regards,

Mario



Paul G. Tobey [eMVP] wrote:
A call back or some data copied into the buffer passed as a parameter? A
callback is going to require a rather different scheme (look up delegates
in
the help or in the archives of this group). If you just want to copy
some
data into a pre-allocated managed array in your unmanaged code, go ahead.

Paul T.

"Mario" <alphatommy@xxxxxxxxxxx> wrote in message
news:1154041731.172840.235320@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi Paul,

Your suggestion worked great. Thanks.

I have another question. How would the declaration different if the
function needs a call back. I want the driver (dll function) to return
value to pDataBuffer. Thanks.


Paul G. Tobey [eMVP] wrote:
I think that you want that to be a byte array.

public static extern void myfunction(IntPtr myhandle, Byte byAddress,
byte[] pDataBuffer, int iSize);

Paul T.

"Mario" <alphatommy@xxxxxxxxxxx> wrote in message
news:1153946653.546113.166310@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,

I have this function in a dll

void myfunction (HANDLE myhandle, BYTE byAddress, BYTE* pDataBuffer,
int iSize)

Invoking using Platform invoke by using the following:

[DllImport("mydll.dll")]
public static extern void myfunction(IntPtr myhandle, Byte
byAddress,
ref Byte pDataBuffer, int iSize);

Somehow I don't seem to be getting data from pDataBuffer. What is
the
right declaration for BYTE * in platform invoke?

Thanks.





.



Relevant Pages

  • Re: P/Invoke BYTE *
    ... Paul G. Tobey wrote: ... value to pDataBuffer. ... bytepDataBuffer, int iSize); ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: P/Invoke BYTE *
    ... Paul G. Tobey wrote: ... value to pDataBuffer. ... bytepDataBuffer, int iSize); ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: P/Invoke BYTE *
    ... I did find passing arrays, ... but did not find any reference for passing an array of structures. ... Paul G. Tobey wrote: ... value to pDataBuffer. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: nearly taken out by driver using mobile - got a result !
    ... Paul - xxx wrote: ... Indeed, in the scheme of things, nothing at all ... actually happened other than you saw a danger and stopped before it ...
    (uk.rec.driving)
  • Re: P/Invoke BYTE *
    ... Paul G. Tobey [eMVP] wrote: ... value to pDataBuffer. ...
    (microsoft.public.dotnet.framework.compactframework)

Loading