Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

MIDL VARIANT-type to proper C# type

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bjoern - 24 Sep 2007 22:51 GMT
Hi

I have a COM object which fires an event where I have to pass an array
of SHORTs as a parameter to the listening object. The array of SHORTs
is encapsulated in a the CComSafeArray-class and passed as a VARIANT*
in MIDL (since MIDL doesn't support SAFEARRAYs in events).

In C# (.NET 1.0) the MIDL VARIANT* data-type is registered as "ref
object" in the event-handler (delegate). How do I convert this "ref
object" to a short array?

-- Bjoern
Mattias Sjögren - 25 Sep 2007 04:53 GMT
>How do I convert this "ref
>object" to a short array?

You probably only need a cast.

void YourEventHandler(ref object o)
{
    short[] arr = (short[])o;
    // Do stuff...
}

If that doesn't work please tell us what o.GetType().FullName returns.

Mattias

Signature

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

Bjoern - 26 Sep 2007 21:58 GMT
Hi

When I get the full path of the VARIANT* type it says
"System.Boolean".

Here's how my IDL event is declared:

HRESULT OnUserAudioData([in] LONG nUserID, [in] LONG nSampleRate, [in]
VARIANT* pRawAudio, [in] LONG nSamples);

Here's how I pass my data to the event:

//-- begin
Audio* aud = reinterpret_cast<Audio*> (lParam);
CComSafeArray<SHORT, VT_I2> safeArray;
if(aud->samples)
 safeArray.Add(aud->samples, aud->rawAudio, TRUE);
CComVariant vtVar(safeArray);
m_pListener->Fire_OnUserAudioData(aud->userid, aud->samplerate,
&vtVar, aud->samples);
//-- end

Any idea why C# thinks it's a boolean?

-- Bjoern

On Sep 25, 5:53 am, Mattias Sj?gren <mattias.dont.want.s...@mvps.org>
wrote:
> >How do I convert this "ref
> >object" to a short array?
[quoted text clipped - 15 lines]
> Mattias Sj?gren [C# MVP]  mattias @ mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
> Please reply only to the newsgroup.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.