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

how to pass interface pointer to a method in a DLL

hello there!

I've been trying to translate some code in C++ into C#.

I've an object in a DLL wich has a Method that recieves an Interface pointer
as parameter.
something like this:

HRESULT _stdcall MyMethod([out] unsigned long* nElem, [out] IMyData**
aData);

In C++ I simply do this:

....
ULONG nElem;
MyLib::IMyData* aData = null;
myobj->MyMethod( &nElem, &aData);
....

but when I add the same object in the references in a C# project the method
becomes something like this:

void MyMethod(out uint nElem, System.IntPtr aData);

The method is not accepting my 'MyLib.IMyData aData' as a parameter and the
value IntPtr cannot be null.
I realy don't know how to parse MyLib.IMyData interface into a IntPtr Type.
Can you give me a clue?
Nov 15 '05 #1
3 2727
Rui,
but when I add the same object in the references in a C# project the method
becomes something like this:

void MyMethod(out uint nElem, System.IntPtr aData);


That's strange. If the method signature is really what you say it is
in the typelib, Tlbimp shouldn't produce such a signature. Are you
sure the last parameter isn't really a void**?

Anyway, you can hopefully edit the interop assembly and change the
signature to take an out IMyData parameter instead. See instructions
at

http://msdn.microsoft.com/library/en...opassembly.asp

Mattias

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

first of all thanks 'coz the link you sent helped me a lot but I still have
a problem.
the value returned is an array of IMyData and the
Marshal.PtrToStructure(...) method only gets the first item.

I'm getting disapointed with C# 'coz I've to write more code than only 3
lines in C++.

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:uA**************@TK2MSFTNGP11.phx.gbl...
Rui,
but when I add the same object in the references in a C# project the methodbecomes something like this:

void MyMethod(out uint nElem, System.IntPtr aData);
That's strange. If the method signature is really what you say it is
in the typelib, Tlbimp shouldn't produce such a signature. Are you
sure the last parameter isn't really a void**?

Anyway, you can hopefully edit the interop assembly and change the
signature to take an out IMyData parameter instead. See instructions
at

http://msdn.microsoft.com/library/en...opassembly.asp
Mattias

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

Nov 15 '05 #3
the value returned is an array of IMyData


Oh, OK. Then you should probably change the parameter type to IntPtr[]
and then call Marshal.GetObjectFromIUnknown for each of the returned
pointers.

Mattias

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

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

Similar topics

110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
8
by: Blue Ocean | last post by:
I know this is somewhat dependent on the circumstances, but let me ask anyway. Suppose I have a 100 byte struct or array or something like that. Which would be more efficient? void...
0
by: Owen Corpening | last post by:
I have this c# interface: int EditActuateConfigFile( string s); and I call it from C++ with a char * - it compiles, at runtime there is no complaint, but I put logging in the method and it isn't...
8
by: TJ | last post by:
I need to be able to pass a pointer to a (managed code) Stream object to a COM method so it can serialize its data into the stream. I have a C# application that makes uses of Randolf Duke's...
5
by: apm | last post by:
Any and all: Is there an efficient way to pass a large array from .NET to COM? Can references (or pointer) be passed from COM to NET and NET to COM without the object it refers to being copied?...
10
by: Just D | last post by:
All, What are advantages and disadvantages of these two different approaches? 1 . I create a base class with a few virtual methods, then I derive my classes from this class, override these...
6
by: Minfu Lu | last post by:
I have a problem dealing with passing a function address to a COM callback. I use this COM function for communicating to a hardware. My original project was written in VB. I have converted it to...
8
by: Lamefif | last post by:
// C3DRect supports IDraw and IShapeEdit. class C3DRect : public IDraw, public IShapeEdit { public: C3DRect(); virtual ~C3DRect(); // IDraw virtual void Draw(); // IShapeEdit virtual void...
9
by: =?Utf-8?B?RWR3YXJkUw==?= | last post by:
I would greatly appreciate some help on passing managed object into unmanaged code. I need to pass a reference (address of) of a managed class into unmanaged code (written by a thrid party). The...
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
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: 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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.