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

Interop with ASIO driver COM object

Ok I will be as clearer as I can (sorry for english/technical
mistakes)

I would like to write an audio application that supports ASIO drivers.
I downloaded the ASIO sdk from Stainberg and I read the docs and
viewed the code provided. The sdk retrieve the varius ASIO drivers
available from windows registry. The various drivers are COM objects
wich must be loaded dinamically after retrieving the CLSID from the
registry.
In C++ this is done by the following statement:

rc = CoCreateInstance(lpdrv->clsid,0,CLSCTX_INPROC_SERVER,lpdrv-
>clsid,asiodrv);
As you can notice the interface CLSID is the same as object's CLSID.
asiodrv type is IASIO:

interface IASIO : public IUnknown
{

virtual ASIOBool init(void *sysHandle) = 0;
virtual void getDriverName(char *name) = 0;
....
virtual ASIOError future(long selector,void *opt) = 0;
virtual ASIOError outputReady() = 0;
};

In C# i tried to do the following:

Type ASIODriverObjectType = Type.GetTypeFromCLSID(drvlist[dID].clsid,
true);
drvlist[dID].asiodrv =
(IASIO)Activator.CreateInstance(ASIODriverObjectTy pe);

where IASIO is the following:

[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("a91eaba1-cf4c-11d3-b96a-00a0c9c7b61a")]
public interface IASIO
{
[return: MarshalAs(UnmanagedType.Bool)]
bool init([In,Out] ref IntPtr sysHandle);

void getDriverName([Out, MarshalAs(UnmanagedType.LPStr)] out
string name);
....
}

1. Is there a way to specify the Guid attribute for the interface
during runtime (or not specify it at all)? Infact if I don't specify
the attribute, I get an E_NOINTERFACE error during conversion into
IASIO at the CreateInstence line.

2. When I call init function from the asiodrv object i created I get
an AccessViolationException can anybody tell me why this happens? Is
my way of doing things correct?

Thank you!

Apr 13 '07 #1
4 7333
The only way you will be able to use this in .NET would be to define the
interface over and over again, with a new name/namespace and the different
ids.

The reason for this is because the guys who wrote all of this completely
screwed it up when they declared the way to create the instances of this
interface.

COM declares that the GUID for the interface is immutable, and COM
interop relies on this when performing casts to COM interfaces. Because
they decided that you should re-declare the interface and give it a new IID
(which is the same as the CLSID, two horrible decisions on their part), the
COM interop layer is not going to know what to do.

My recommendation is to declare the interface once in unmanaged code,
and then implement it on a stub class. That class would have another
interface which declares a method instance telling it which CLSID it is
proxying. When you create the object, you would get this other interface,
and pass the CLSID to the method to tell it which class to create, then, you
would funnel the calls from your proxy object to the interface declaration
in your file (which will have the same vtable structure so it should work).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Technics" <ma***@giarresi.netwrote in message
news:11**********************@d57g2000hsg.googlegr oups.com...
Ok I will be as clearer as I can (sorry for english/technical
mistakes)

I would like to write an audio application that supports ASIO drivers.
I downloaded the ASIO sdk from Stainberg and I read the docs and
viewed the code provided. The sdk retrieve the varius ASIO drivers
available from windows registry. The various drivers are COM objects
wich must be loaded dinamically after retrieving the CLSID from the
registry.
In C++ this is done by the following statement:

rc = CoCreateInstance(lpdrv->clsid,0,CLSCTX_INPROC_SERVER,lpdrv-
>>clsid,asiodrv);

As you can notice the interface CLSID is the same as object's CLSID.
asiodrv type is IASIO:

interface IASIO : public IUnknown
{

virtual ASIOBool init(void *sysHandle) = 0;
virtual void getDriverName(char *name) = 0;
...
virtual ASIOError future(long selector,void *opt) = 0;
virtual ASIOError outputReady() = 0;
};

In C# i tried to do the following:

Type ASIODriverObjectType = Type.GetTypeFromCLSID(drvlist[dID].clsid,
true);
drvlist[dID].asiodrv =
(IASIO)Activator.CreateInstance(ASIODriverObjectTy pe);

where IASIO is the following:

[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("a91eaba1-cf4c-11d3-b96a-00a0c9c7b61a")]
public interface IASIO
{
[return: MarshalAs(UnmanagedType.Bool)]
bool init([In,Out] ref IntPtr sysHandle);

void getDriverName([Out, MarshalAs(UnmanagedType.LPStr)] out
string name);
...
}

1. Is there a way to specify the Guid attribute for the interface
during runtime (or not specify it at all)? Infact if I don't specify
the attribute, I get an E_NOINTERFACE error during conversion into
IASIO at the CreateInstence line.

2. When I call init function from the asiodrv object i created I get
an AccessViolationException can anybody tell me why this happens? Is
my way of doing things correct?

Thank you!

Apr 13 '07 #2
Thank you a lot for help!

However a little code example would clarify.

1. What happens when I cast the object into the interface ? When the
runtime system watches for Guid attribute of the instance to determine
how to query COM for the right interface?

2. I viewed at the Disassembly window to see why I get the exception
and I see that the exception comes when the program get to "call"
instruction. Is maybe a matter of how the interface is declared ? And
is there a way to create the exact interface layout in memory without
using unmanaged code?

Apr 14 '07 #3
Technics,

This is what you need to do. What you are going to see is pseudo-code
which you will have to replicate in C++.

First, you have to define an interface that will have a constant IID.
This interface will be the IASIO interface. However, you are going to
export it from your COM library:

// Define an IID for this interface which will be exported from your proxy
and be constant.
// This is what is going to be used in .NET.
interface IConstantAsio : public IUnknown
{

virtual ASIOBool init(void *sysHandle) = 0;
virtual void getDriverName(char *name) = 0;
....
};

Define another COM interface which will go on the proxy object as well:

interface IInitializeAsioProxy
{
virtual void Initialize(CLSID ProxyClsid) = 0;
}

Then you define your COM class (I don't recommend using the "C" in the
AsioProxy program id), like so:

class CAsioProxy : IConstantAsio, IInitializeAsioProxy
{
private:
IConstantAsio *m_proxy;

// IInitializeAsioProxy implementation.
HRESULT IInitializeAsioProxy::Initialize(CLSID ProxyClsid)
{
// Call CoCreateInstance here for the proxy.
return CoCreateInstance(ProxyClsid, 0, CLSCTX_INPROC_SERVER,
ProxyClsid, &m_proxy);
}

// IConstantAsio implementation.
void IConstantAsio::getDriverName(char *name)
{
// Call the proxy.
m_proxy->getDriverName(name);
}

}

Then, you use this in C#, and make sure you cast to the
InitializeAsioProxy first to pass the appropriate CLSID.

It occurs to me that this STILL might not work, because the IASIO
interface is not a valid COM interface. ALL methods on a COM interface must
return HRESULT, and it seems that none of them do, so you might have to do
additional work there in defining another PROPER COM interface and using
that internally on the proxy, and creating a different interface that the
proxy exports.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Technics" <ma***@giarresi.netwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
Thank you a lot for help!

However a little code example would clarify.

1. What happens when I cast the object into the interface ? When the
runtime system watches for Guid attribute of the instance to determine
how to query COM for the right interface?

2. I viewed at the Disassembly window to see why I get the exception
and I see that the exception comes when the program get to "call"
instruction. Is maybe a matter of how the interface is declared ? And
is there a way to create the exact interface layout in memory without
using unmanaged code?

Apr 14 '07 #4
Don't mess around with COM. I wrote a managed wrapper for the given code in C++/Cli, which does the job. Th app I did in C#. There were minor flaws to solve, but up to now it works.

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Apr 18 '07 #5

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

Similar topics

6
by: Binesh | last post by:
Hi I used Interop assemblies to read Excel data into DataSet. I am able to run it successfully on my workstation(windows XP and VS .Net 7 and MS Office XP) but when I port my code to...
0
by: Biot! | last post by:
Hi, I wanted to know if anybody has seen any translation of ASIO (Audio Streaming Input Output) for .NET framework Regards, Biot!
1
by: Nadav | last post by:
Hi, Introduction *************** I have a system build of a collection of 'Native COM objects' and '.NET COM interop' objects, all of the COM objects are managed through a 'Native COM' layer,...
2
by: Brendan | last post by:
I have a legacy COM/ActiveX component (an OCX) that I need to interface with from C# and the .NET framework. Ordinarily, I would just add a reference to the OCX or add it to the Toolbox (both of...
1
by: 张沈鹏 | last post by:
How to compile the HelloWorld of boost.asio? Maybe this is a stupid problem , but I really don't konw how to find the right way. My compile environment is WinXP, Msys , MinGw , G++ 3.4.2,...
2
by: Derek Hart | last post by:
I am using late bound Microsoft Word integration with a vb.net winforms application. If I run code such as the following: Dim objWord As Object Dim objWrdDoc As Object Dim count As Integer...
1
by: bje990 | last post by:
Here is the situation.... I have a device i connect to where i read a byte stream until some delimiter is found. boost::asio::streambuf response; size_t length =...
0
by: iwr | last post by:
Hello, I'm moving parts of some windows socket-based code to boost.asio. My async socket is connected to a server, and I noticed, that when the server goes down in a "non-graceful" way (eg.,...
1
by: wo3kie | last post by:
I had not any issues with Windows, but with Linux I failed It is going about an example from boost::asio library tutorial # Daytime.1 - A synchronous TCP daytime client # Daytime.2 - A...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...

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.