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.
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.
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.
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.