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

For C# Interop, how to deal with pointer field in struct in IDL?

How to deal with pointer field in struct in idl So that C# can call C++ COM?

e.g.

in C++ COM Server IDL:
typedef struct
{
long *xPos;
long yPos;
} MYPOINT;
...
...
interface IIDraw : IUnknown
{
HRESULT DrawALine([in,out] MYPOINT* p1, [in,out] MYPOINT* p2);
};

in C# Client:
// We want to remove the * (pointer) of xPos.
// The class will become:
public class MYPOINT
{
public long xPos;
public long yPos;
};

// When calling the COM function:
MYPOINT pt1, pt2;
draw.DrawALine(ref pt1, ref pt2);
How to make this kind of implementation?
Is it required to modify the IL Assembler file for certain marshaling? If yes, how?
--------------------------------
From: Lawrence Li

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>zOQ+8DNeTEWO1dMmzgHuHA==</Id>
Nov 16 '05 #1
2 2784
Checkout IntPtr see the following link
http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfSystemIntPtrClassTopic.asp

-----Original Message-----
How to deal with pointer field in struct in idl So that C# can call C++ COM?
e.g.

in C++ COM Server IDL:
typedef struct
{
long *xPos;
long yPos;
} MYPOINT;
...
...
interface IIDraw : IUnknown
{
HRESULT DrawALine([in,out] MYPOINT* p1, [in,out] MYPOINT* p2); };

in C# Client:
// We want to remove the * (pointer) of xPos.
// The class will become:
public class MYPOINT
{
public long xPos;
public long yPos;
};

// When calling the COM function:
MYPOINT pt1, pt2;
draw.DrawALine(ref pt1, ref pt2);
How to make this kind of implementation?
Is it required to modify the IL Assembler file for certain marshaling? If yes, how?

--------------------------------
From: Lawrence Li

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>zOQ+8DNeTEWO1dMmzgHuHA==</Id>
.

Nov 16 '05 #2
We want to avoid IntPtr because it is dangerous to use pointer in C#.

"BuddyWork" <an*******@discussions.microsoft.com> wrote in message news:<1a*****************************@phx.gbl>...
Checkout IntPtr see the following link
http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfSystemIntPtrClassTopic.asp

-----Original Message-----
How to deal with pointer field in struct in idl So that

C# can call C++ COM?

e.g.

in C++ COM Server IDL:
typedef struct
{
long *xPos;
long yPos;
} MYPOINT;
...
...
interface IIDraw : IUnknown
{
HRESULT DrawALine([in,out] MYPOINT* p1,

[in,out] MYPOINT* p2);
};

in C# Client:
// We want to remove the * (pointer) of xPos.
// The class will become:
public class MYPOINT
{
public long xPos;
public long yPos;
};

// When calling the COM function:
MYPOINT pt1, pt2;
draw.DrawALine(ref pt1, ref pt2);
How to make this kind of implementation?
Is it required to modify the IL Assembler file for

certain marshaling? If yes, how?


--------------------------------
From: Lawrence Li

-----------------------
Posted by a user from .NET 247

(http://www.dotnet247.com/)

<Id>zOQ+8DNeTEWO1dMmzgHuHA==</Id>
.

Nov 16 '05 #3

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

Similar topics

0
by: lawrence | last post by:
How to deal with pointer field in struct in idl So that C# can call C++ COM? e.g. in C++ COM Server IDL: typedef struct { long *xPos; long yPos; } MYPOINT;
1
by: Chris B. | last post by:
If anyone can figure out how to implement the following C++ function in C# using interop, I'd be very appreciative. I have not been successful in getting it to work correctly using interop...
1
by: ivang | last post by:
Hello, All! Please help me to marshal following win32 structure: typedef struct _STARTUPINFOW { DWORD cb; LPWSTR lpReserved;
0
by: weixian_shen | last post by:
I'm trying to call my DLL written in C, and got the error: Cannot marshal field 'b' of type 'mystruct': There is no marshaling support for this type. The 2 functions in the DLL are: void...
17
by: Aaron | last post by:
I've got a doozie of a problem! I and others have been trying to figure this out for too long and I've come to the conclusion that I should probably look for some support.. Ok, I have a COM...
6
by: Nataraj1978 | last post by:
I have a requirement to use a dll written in Visual C++ 6.0 in my C# application. In order to establish the link between my application and the dll, I have written a ATL COM Component in Visual...
2
by: mark.e.nelson | last post by:
Hi, I am trying to pass a pointer to a struct to a function that uses the data in the struct, and also happens to use ncurses. I always get a segmentation violation when the program exits. I...
1
by: Don.Leri | last post by:
Hi, I have a logger.dll (unmanaged c++ dll compiled in vs2005). I have a C# interop to use that dll in managed code implemented in Interfaces.dll (used by other C# dlls). I also have a...
0
by: user2008 | last post by:
Hi everybody, I'm working on exposing a .Net (C#) COM Server. Manage Code is exposting an interface with two methods. These methods take an IN/OUT Struct as parameter. Requirement is that the...
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.