473,804 Members | 3,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 EAudioComponent Type
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(IAudioPlug inMgr *pMgr, IStatus **ppStatus = NULL) PURE;

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

EAudioComponent Type GetType();

bool Init(
[In, MarshalAs(Unman agedType.Interf ace)] IAudioPluginMgr pMgr,
[Out, MarshalAs(Unman agedType.Interf ace)] out IStatus ppStatus);

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

Try this:

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

[PreserveSig]
EAudioComponent Type GetType();

[PreserveSig]
[return: MarshalAs(Unman agedType.U1)]
bool Init(IAudioPlug inMgr Mgr, out IStatus ppStatus);

[PreserveSig]
[return: MarshalAs(Unman agedType.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
AccessViolation Exception.

Any thoughts?

[ComImport]
[Guid("FC2E77B1-6278-452b-9756-7AC24E807778")]
[InterfaceType(C omInterfaceType .InterfaceIsIUn known)]
public interface IComponentEnum
{
[PreserveSig]
[return: MarshalAs(Unman agedType.I4)]
int GetCount();

[PreserveSig]
[return: MarshalAs(Unman agedType.U1)]
bool GetComponent(in t iNum, [Out,
MarshalAs(Unman agedType.Interf ace)] 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.GetTyp e() !=
EAudioComponent Type.ACT_Compon entEnumerator)
throw new InvalidOperatio nException("Pri mary audio object
does not support ACT_ComponentEn umerator.");

IComponentEnum inputICU = (IComponentEnum )inputIA;

if (inputICU.GetCo unt() == 0)
throw new InvalidOperatio nException("Com ponent enumerator
contains no audio components.");

IAudioComponent inputIAC = null;
inputICU.GetCom ponent(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
2656
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 touched C for large implementations, I'm seeking advice on what to use for development. My ultimate goal is to spend as less time on it as possible. I'll be writing it in Windows 32-bit environment, probably Win2000 or Win98. Planning to use a...
3
1803
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 the tables is given below. The most expensive operation is a bookmark lookup on VGNCCB_ROLE_JT. I created the speed_up_login index as a covering index to cover the query but that has not seemed to help. Any ideas, suggestions are most welcome...
9
2942
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 a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
3
2676
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 basically put it into an output file that I can access as a test file. Here is my header file: #include <iostream.h> #include <fstream.h> #include <iomanip.h>
1
2181
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 JDBC driver. The ODBC and C++ interfaces have been moved to the PostgreSQL Projects Web Site at http://gborg.postgresql.org for separate maintenance. "
7
2361
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 WinForms interface and then need to port that to a web app. I am kinda stuck on a design issue and need some suggestions / direction. Basically I have a business layer that I want to use to process any dataentry logic (row focus changes, data...
18
2077
by: anand | last post by:
*********************************************************************************************************** #include<stdio.h> #include<conio.h> #include<math.h> void main() { double a,b,c,fa,fb,fc,err; int count;
3
2646
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 it (text, graphics, whatever). I am using the asp:ImageMap control and I can use the asp:circlehotspot control, but that only allows me to have a single hotspot. What I want to do is create a new custom control that derives everything from...
0
3969
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 Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
2
1814
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 your characters into that save file. Anyhow, I want to extract a couple of lines of it and save it into a database and I need help on figuring out a good way of reading the file. The problem is that the file can look pretty different depending...
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7625
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.