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

COM and variable length array sctructure

Hi,

Please, does anybody know how can the code bellow to C# ?

C++ structure
typedef struct SMAP_INFO
{
WORD wPort;
DWORD dwSerialNumber;
WORD wHardComp;
BYTE bFirmwVersion[16];
DWORD dwFirmwDate;
BYTE bMonitorVersion[16];
DWORD dwMonitorDate;
BYTE bRunningProgramID;
} SMapInfo, * PSMAP_INFO;

COM method
virtual HRESULT STDMETHODCALLTYPE GetPortMap(
/* [in] */ WORD wMaxPorts,
/* [out] */ WORD __RPC_FAR *pNumberOfPorts,
/* [size_is][size_is][out] */ SMapInfo __RPC_FAR *__RPC_FAR *pPortMap,
/* [out] */ DWORD __RPC_FAR *pTransactionID) = 0;

How can I change this for C#? I tried the code bellow, but it does work for just 1 structure, however the pPortMap, can have more them only 1 structure, i.e., it is pointer to an array of "n" struture.

C#
[StructLayout(LayoutKind.Sequential, Pack = 2, CharSet = CharSet.Unicode)]
public class SMAP_INFO
{
public ushort wPort;
public uint dwSerialNumber;
public ushort wHardComp;

[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.LPArray, SizeConst = 16)]
public byte[] bFirmwVersion;

public uint dwFirmwDate;

[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.LPArray, SizeConst = 16)]
public byte[] bMonitorVersion;

public uint dwMonitorDate;
public byte bRunningProgramID;
};

[PreserveSig]
HRESULTS GetPortMap(
[In] ushort wMaxPorts,
[Out] out ushort pNumberOfPorts,
[Out] out SMAP_INFO pPortMap, /* ** The PROBLEM IS HERE */
[Out] out uint pTransactionID);

** How can I define pPortMap to get an array of structure ? Please, detailed code information will be welcome since I an not an expert in C#. Thanks.
Feb 27 '07 #1
3 936
RedSon
5,000 Expert 4TB
Well one of the great things about .net is that you can compile your .net c++ project into the MISL and then use that compiled bytecode in your c# project. Is this something that can be done or are you trying to use some native code in your managed project?
Feb 27 '07 #2
Well one of the great things about .net is that you can compile your .net c++ project into the MISL and then use that compiled bytecode in your c# project. Is this something that can be done or are you trying to use some native code in your managed project?
If I understood your question, I am not using any C++ code in my C# project. I am implementing a new OPC Client in C# to get information of the C++ OPC Server. The only thing that I have is the headers of the c++ methods. Do you understand?
Feb 27 '07 #3
This for all.. I found the solution in:
http://msdn2.microsoft.com/pt-br/learning/2k1k68kw(VS.80).aspx
Feb 27 '07 #4

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

Similar topics

6
by: BigDadyWeaver | last post by:
I am using the following code in asp to define a unique and unpredictable record ID in Access. <% 'GENERATE UNIQUE ID Function genguid() Dim Guid guid =...
13
by: HappyHippy | last post by:
Hi, I'm wondering what you think about this piece of code: #include<iostream> int main() { int size; std::cin >> size;
27
by: Mike P | last post by:
I will be passing my function a two dimensional array of varying length. Within that array is one data point, and the number of times it should loop through. So, for example, I might pass this...
5
by: dam_fool_2003 | last post by:
Hai, I studied that the array size is fixed. But I come across a word called "variable length array". Is it possible to change the array size? So I tried the following: #include<stdio.h>...
10
by: Adam Warner | last post by:
Hi all, With this structure that records the length of an array of pointers as its first member: struct array { ptrdiff_t length; void *ptr; };
2
by: Augusto Cesar | last post by:
Hello people. How can I Pass ASP Array variable to Javascript; I´m to trying this: <script language="JavaScript"> var x = new Array(10);
6
by: foreverbored75 | last post by:
Hello All! I am just learning c++ in school and I have the following question: Is there a way for the user to input the length of an array (console application) without using another variable?...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
7
by: Cromulent | last post by:
In section 6.7.5.2 it states the following: If the size is not present, the array type is an incomplete type. If the size is*instead of being an expression, the array type is a variable length...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.