473,386 Members | 1,860 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,386 software developers and data experts.

Marshalling for C struct with arrays

Could someone give me an hint?

I have trouble with mashaling of a struct. I can set values in struct
(byVAL) but cant read from the struct. Its an long pointer struct in a
c dll.

thats my struct where is correct i guess

'-----------------------------------
' structure declarations
' xl event
<StructLayout(LayoutKind.Sequential, Pack:=1)> Structure s_xlEvent
Public tag As Byte
Public chanIndex As Byte
Public transID As Short
Public porthandle As Short
Public reserved As Short
Public timestamp As UInt64
<FieldOffset(0)> Public tagdata_can_msg As s_xl_can_msg
<FieldOffset(0)> Public tagdata_chipstate As s_xl_chipstate
<FieldOffset(0)> Public tagdata_lin_msg As s_xl_lin_msg_api
<FieldOffset(0)> Public tagdata_sync_pulse As s_xl_sync_pulse
<FieldOffset(0)> Public tagdata_daio_data As s_xl_daio_data
<FieldOffset(0)> Public tagdata_transceiver As
s_xl_transceiver
End Structure
Structure s_xl_can_msg
Public id As UInt32
Public flags As Short
Public dlc As Short
Public res1 As UInt64
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> Public
data As Byte()
Public res2 As UInt64
End Structure
' function to fill/set struct with array - this is successful

Public Declare Function xlCanTransmit Lib "vxlapi.dll" (ByVal
PortHandle As UInt32, ByVal accessmask As UInt64, ByRef messageCount
As UInt16, <MarshalAs(UnmanagedType.LPArray)> ByVal pMessages As
s_xlEvent()) As Byte

' function to read frome struct with array - this is the problem

Public Declare Function xlReceive Lib "vxlapi.dll" (ByVal PortHandle
As UInt32, ByRef pEventCount As UInt16,
<MarshalAs(UnmanagedType.LPArray)> ByRef pMessages As s_xlEvent()) As
Byte

Problem SizeParamIndex is not allowed to with byref parameter :(
Any suggestions?
Nov 20 '05 #1
3 2301
Markus,

What does the original native function signature look like? Are you
sure that pMessages should be ByRef in the xlReceive function?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #2
the original function is that. The driver dll I ask is an c dll and
will give me a pointer back to this structure. I saw that the call is
successful and values are returned in the debug messages of dll.

#ifdef DYNAMIC_XLDRIVER_DLL
typedef XLstatus (_EXPORT_API *XLRECEIVE) (
XLportHandle portHandle,
unsigned int *pEventCount,
XLevent *pEvents);
#else
XLstatus _EXPORT_DECL xlReceive(
XLportHandle portHandle,
unsigned int *pEventCount,
XLevent *pEvents);
#endif

Markus

Mattias Sjögren <ma********************@mvps.org> wrote in message news:<eA**************@TK2MSFTNGP09.phx.gbl>...
Markus,

What does the original native function signature look like? Are you
sure that pMessages should be ByRef in the xlReceive function?

Mattias

Nov 20 '05 #3
Markus,

Looks like the array should be passed ByVal after all. Try this

Public Declare Function xlReceive Lib "vxlapi.dll" (ByVal PortHandle
As UInt32, ByRef pEventCount As UInt16, <Out> ByVal pMessages As
s_xlEvent()) As Byte

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #4

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

Similar topics

4
by: Animesh | last post by:
Hi All, I don't know whethher this is possible or not. This is the result of a bad design problem. Here I go; I have a structure like this: typedef struct _s_index_entry { char *doc_id;...
2
by: RJ Lohan | last post by:
Howdy, I have a legacy DLL for which I have a problem marshalling a parameter type of char**. The function header (C++) is as so; extern "C" __declspec(dllexport) int __stdcall...
1
by: jsshah | last post by:
Hi I want to marshal following Win32 struct into .NEt class or struct as I want to call a native dll function from a Csharp code. The win32 struct ----------------------- typedef struct...
1
by: peary | last post by:
Hi, everyone, I'm writing a program to discover wireless network using Windows Native Wifi API & VB.net. I have to declare the windows API in my VB.net program. The original windows...
1
by: Beorne | last post by:
I have a cpp application with this structure: //////////////C++/////////////// typedef struct StatusStructure { char FixedLenString; long LongVariable; double DoubleVariable; BOOL...
2
by: calenlas | last post by:
Hi all, I'm taking my first steps into C# <--C++ DLL Interop and unfortunately I've run into (what seems to be) a very complicated case as my first task. Perhaps someone here can help me. I...
2
by: d-42 | last post by:
Hi, I'm pretty sure I've just got a Marshalling problem, but I'm completely stumped. If there is a better newsgroup to post this in, please point me towards it. First I'm trying to use...
3
by: Saad | last post by:
Hi, I have a struct as follows: public __gc struct STTemp { public: int someint; System::Collections::ArrayList* arrTemp;
1
by: roche72 | last post by:
I am having some trouble marshalling data between c++/C# Here is the C++ code: --------------------------------------------------------------------------------- typedef struct { ...... ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.