473,395 Members | 1,791 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.

MIDL VARIANT-type to proper C# type

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

Sep 24 '07 #1
2 2978
>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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 25 '07 #2
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_I2safeArray;
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?

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

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

Sep 26 '07 #3

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

Similar topics

3
by: Annie | last post by:
I am trying to call a COM object which expects a variant datatype to be passed in to the COM API object. However, I get "<COMObject <unknown>>" and the program fails. Below is my code in Python,...
8
by: MLH | last post by:
A97 HELP shows the proper syntax for using Nz as Nz(variant) I'm wondering what to expect from potential past misuse I've made. For example, consider the following... Private Sub...
16
by: Jon Davis | last post by:
Hi guys! Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days. // Here is an example of use: // start with a string of "1" Variant da = new...
0
by: Andrew S. Giles | last post by:
Helo all, I have a standalone unmanaged C++ application that makes a call on another standalone COM server, which raises an event that should be handled in C#. I am trying to send: unsigned...
0
by: .::alex::. | last post by:
Hello, Maybe you already guess the problem. I have a COM with a method in a Interface like that: HRESULT GetArray(VARIANT *pVal); so this method will return a VARIANT. This VARIANT contains...
2
by: Heike | last post by:
Hello everybody, I have a Problem with C Sharp. I have to use external functions in DLLs. This Functions are written in Visual C++ 6 like this: int (__stdcall *GetGlobalValue) (VARIANT Appl,...
11
by: MLH | last post by:
The following procedures found at http://ffdba.com/downloads/Send_Mail_With_Outlook_Express.htm are meant to work together in harmony to effect eMail sends via OE. The last procedure (FN SplitB)...
1
by: morten | last post by:
When i compile this code in VC71 or VC80 i get the following errors: The code is copy/paste from the boost.org tutorial. Please help! error C2039: 'begin' : is not a member of...
4
by: jainchar | last post by:
hello I am creating a VARIANT that stores a integer value of variable but variable is not initialize.In my code the variable are "r" and"c" where r and c are the value of row and column of a table.I...
8
by: bradyounie | last post by:
I have a C++ COM project that was created with Visual C++ 6. I have just converted the project to Visual Studio 2005 and have been trying to build it. I get the following compile errors: warning...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.