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

need help with non-standard retvals in COM interop

i'm attempting to interop from C# to a COM DLL, and have found some trouble
with a non-standard interface (at bottom of post - followed by my C# version).

typically COM methods return an HRESULT or just void. for some reason, this
one is returning a string (char *) or in other interfaces is returning a
struct.

i'm pretty familiar with interop for normal params and using IntPtr
marshalling to structures, but i'm not sure how this works in this case.

when calling GetName or GetType in this interface (via C#), i'm just getting
'null' or '0' for each call.

thanks for any help!
Kirk

-------------
interface IAudioComponent : public IUnknown
{
virtual const char *
GetName() PURE;

// Application should first call this method to determine the type
// of the component and after that query the appropriate interface.
virtual EAudioComponentType
GetType() PURE;

// This method is called after all the components are enumerated.
// It should perform the actual initialization and store pMgr for
// later use to access functionality provided by other plugins.
// If the component initialization fails, it should return false
// and the plugin manager will remove it from components list so
// it will not be available.
virtual bool
Init(IAudioPluginMgr *pMgr, IStatus **ppStatus = NULL) PURE;

virtual bool
Done() PURE;
};
[ComImport]
[Guid("0D7EA5C4-DAF9-4738-BB57-EEFDE39CFF8C")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IAudioComponent
{
StringBuilder GetName();

EAudioComponentType GetType();

bool Init(
[In, MarshalAs(UnmanagedType.Interface)] IAudioPluginMgr pMgr,
[Out, MarshalAs(UnmanagedType.Interface)] out IStatus ppStatus);

bool Done();
}
Nov 17 '05 #1
2 1464
Kirk,

Try this:

[ComImport]
[Guid("0D7EA5C4-DAF9-4738-BB57-EEFDE39CFF8C")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IAudioComponent
{
[PreserveSig]
IntPtr GetName();

[PreserveSig]
EAudioComponentType GetType();

[PreserveSig]
[return: MarshalAs(UnmanagedType.U1)]
bool Init(IAudioPluginMgr Mgr, out IStatus ppStatus);

[PreserveSig]
[return: MarshalAs(UnmanagedType.U1)]
bool Done();
}

Mattias

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

I'm almost there... seems that GetCount works correctly and returns 2.

But when i call GetComponent to return the interface, i get an
AccessViolationException.

Any thoughts?

[ComImport]
[Guid("FC2E77B1-6278-452b-9756-7AC24E807778")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IComponentEnum
{
[PreserveSig]
[return: MarshalAs(UnmanagedType.I4)]
int GetCount();

[PreserveSig]
[return: MarshalAs(UnmanagedType.U1)]
bool GetComponent(int iNum, [Out,
MarshalAs(UnmanagedType.Interface)] out IAudioComponent ppComp);
}

here's the C# code that's calling these interop interfaces... it gets
through the first GetType() call and the GetCount() call, but fails on
GetComponent.

(the code here is directly translated from a C++ version.)

if (inputIA.GetType() !=
EAudioComponentType.ACT_ComponentEnumerator)
throw new InvalidOperationException("Primary audio object
does not support ACT_ComponentEnumerator.");

IComponentEnum inputICU = (IComponentEnum)inputIA;

if (inputICU.GetCount() == 0)
throw new InvalidOperationException("Component enumerator
contains no audio components.");

IAudioComponent inputIAC = null;
inputICU.GetComponent(0, out inputIAC);

thanks for your help!
Kirk
Nov 17 '05 #3

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

Similar topics

10
by: Beach Potato | last post by:
Dear Y'all: I'm about to start porting a big old project written in anscient version of Delphi to something more stable, robust, supportable and maybe even portable. Since I haven't seriously...
3
by: Jack A | last post by:
OK Guys. I'm fed up of the query below taking too much time. I CANT change the query since it is generated by a 3rd party product. I can change indexes and add new indexes though. The schema of...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
3
by: Drewdog | last post by:
I am getting some error messages which I can't figure out their meaning. I have the code setup, I think it's correct but it doesn't work. My goal is to get this program to read from a data file and...
1
by: Peggy Go | last post by:
Hi! I've downloaded postgreqsql-base-7.2.4.tar.gz but it says in the readme file that "This distribution also contains several language bindings, including C, Perl, Python, and Tcl, as well as a...
7
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a...
18
by: anand | last post by:
*********************************************************************************************************** #include<stdio.h> #include<conio.h> #include<math.h> void main() { double...
3
by: Dean Craig | last post by:
I'm working with the new ASP.NET AJAX Control Toolkit. I have a map that has several key areas (hot spots) where when the user hovers over them, I want to pop up a small window with information in...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
2
by: Anders B | last post by:
I want to make a program that reads the content of a LUA array save file.. More precicely a save file from a World of Warcraft plugin called CharacterProfiler, which dumps alot of information about...
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
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
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,...
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
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.