473,792 Members | 3,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2995
>How do I convert this "ref
object" to a short array?
You probably only need a cast.

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

If that doesn't work please tell us what o.GetType().Ful lName 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_cas t<Audio*(lParam );
CComSafeArray<S HORT, VT_I2safeArray;
if(aud->samples)
safeArray.Add(a ud->samples, aud->rawAudio, TRUE);
CComVariant vtVar(safeArray );
m_pListener->Fire_OnUserAud ioData(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.w ant.s...@mvps.o rg>
wrote:
How do I convert this "ref
object" to a short array?

You probably only need a cast.

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

}

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

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.ne t/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
3007
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, and the same code in VB which is working fine... I guess this is a variant problem with python? How can I make this work? Would appreciate if someone can guide me as I am a python newbie... :-)
8
2183
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 Command0_Click() Dim a As Long, b As String b = Nz(a, "") MsgBox b End Sub
16
1492
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 Variant("1"); // add an integer of 2, becomes 3 da += 2; // add a float of 1.3, becomes 4.3
0
1912
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 long, double, BSTR, and VARIANT. The unsigned long, double, and BSTR (marshalled to System.String) work just fine and dandy.
0
1501
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 a SafeArray - 1 dimension.
2
4194
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, VARIANT &vRetVal); Now for the first time I want to use C Sharp and I find some examples to use Functions in extarnal DLLs, but I don't know how to cast the Variant-Paramters in C Sharp.
11
1962
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) fails on its last line which is meant to assign the value of SplitB (a variant) the value of aSplit (an array dim'd as variant). That fails due to Type Mismatch. Anyone know how to get around this? Private Type MapiRecip Reserved As Long
1
4581
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 'boost::variant<T0_,T1>' with Test2.cpp(47): error C2039: 'end' : is not a member of 'boost::variant<T0_,T1>' with
4
5975
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 am using it in a split function of Cell class of my project.The code for which i create for VARIANT is as follows and syntax of Split function are as follows.Please help me how i use this variant in my code. The code for variant is VARIANT v;...
8
7810
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 C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow) error C2143: syntax error : missing ';' before '__uuidof' error C2059: syntax error : '__uuidof' error C2143: syntax error : missing ';' before...
0
9670
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
10430
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10211
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10159
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7538
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
6776
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
5436
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...
1
4111
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
3
2917
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.