Re: P/Invoke BYTE *



An array of structures could be represented as an array of bytes, just like
a single structure. There will be some alignment (dummy) bytes between
array entries, in most cases, but otherwise it's just the same the single
structure case.

Paul T.

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

I did download the source code for SDF 1.4. I did find passing arrays,
but did not find any reference for passing an array of structures. The
members of the structure that I need to pass contains the parameters to
drive PMW (sample, period,duration) and I need to pass a bunch of these
to turn on the buzzer. Thanks for your help.

Regards,

Mario

<ctacke/> wrote:
Take a look at the OpenNETCF.Net namespace in the SDF 1.4 source (still a
free download). It's got loads of examples of this.


--
Chris Tacke
OpenNETCF Consulting
www.opennetcf.com
--




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

Is there somewhere where I can find an example of what you are
suggesting? Thanks.

Cheers,

Mario


Paul G. Tobey [eMVP] wrote:
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: Re: how to read AIS data from encapsulated NMEA VDO sentence
    ... "Paul" wrote: ... Convert this byte array to a 6 bit bitstream. ... it all works until I get to character arrays ... Demodulated bitstream, eg. 168 bits for a message 1. ...
    (rec.boats.electronics)
  • 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: IOCTL_POWER_XXX method calls
    ... Paul, I understand how to implement your suggestions if the parameter ... // in the managed array of bytes. ... internal const int DeviceDxOffset = 0; ... BOOL PWM_IOControl (DWORD hOpenContext, DWORD pwCode, PBYTE pBufIn, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Design help with File I/O and searching?
    ... of String, String) in a Smart Device project in VS2005... ... Paul T. ... I just didn't quite know how to get the data into an array, ... I need to create an app that runs on a PDA type scanner running Win ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Help needed with arrays
    ... int main ... >> Really good idea to let Paul solve his problem himself. ... > The problem I have now is writing a loop statement to fill the array ...
    (microsoft.public.vc.language)

Loading