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

  • Thread starter Lawrence Li via .NET 247
  • Start date
L

Lawrence Li via .NET 247

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?
 
B

BuddyWork

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?
 
L

lawrence

We want to avoid IntPtr because it is dangerous to use pointer in C#.

BuddyWork said:
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>
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top