473,807 Members | 2,766 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a COM Object with a VARIANT* param from C# just shows ref object varParam

I wish to call a COM Object which has a parameter of type VARIANT* on
a method call from C#

The COM Method :-
STDMETHODIMP CClassType::Get TypeIDs(VARIANT * TypeIDs)
{
AFX_MANAGE_STAT E(AfxGetStaticM oduleState())
if (DeviceTypeIDs->vt != (VT_I2|VT_ARRAY ))
return E_INVALIDARG ;
VARIANT* ptr ;
SafeArrayAccess Data (TypeIDs->parray, (void**) &ptr) ;
ptr[0].iVal = 1 ;
ptr[1].iVal = 2;
ptr[2].iVal = 3;
ptr[3].iVal = 4;
ptr[4].iVal = 5;
ptr[5].iVal = 6;
SafeArrayUnacce ssData (TypeIDs->parray) ;
return S_OK;
}

How do I create the parameter required within C# in order to call this
COM Method. I've read quite a few postings on marshalling and the
such, but is there anyone that can explain this in simple terms or
code samples would be good.

I think my main problem is C# knowledge, as I have only just started
using it

TIA for even the smallest hint on how to resolve this problem
Nov 15 '05 #1
2 3222
what about

Int16[] arrParam;
//initialize arrParam
comobject.metho d( arrParam );
/Morten

"Dave" <da*********@gr oup4technology. com> wrote in message
news:31******** *************** ***@posting.goo gle.com...
I wish to call a COM Object which has a parameter of type VARIANT* on
a method call from C#

The COM Method :-
STDMETHODIMP CClassType::Get TypeIDs(VARIANT * TypeIDs)
{
AFX_MANAGE_STAT E(AfxGetStaticM oduleState())
if (DeviceTypeIDs->vt != (VT_I2|VT_ARRAY ))
return E_INVALIDARG ;
VARIANT* ptr ;
SafeArrayAccess Data (TypeIDs->parray, (void**) &ptr) ;
ptr[0].iVal = 1 ;
ptr[1].iVal = 2;
ptr[2].iVal = 3;
ptr[3].iVal = 4;
ptr[4].iVal = 5;
ptr[5].iVal = 6;
SafeArrayUnacce ssData (TypeIDs->parray) ;
return S_OK;
}

How do I create the parameter required within C# in order to call this
COM Method. I've read quite a few postings on marshalling and the
such, but is there anyone that can explain this in simple terms or
code samples would be good.

I think my main problem is C# knowledge, as I have only just started
using it

TIA for even the smallest hint on how to resolve this problem

Nov 15 '05 #2
Thanks for this Morten,

Visual Studio automatically puts a wrapper around the COM Object for
me which is great and it specifies the parameter as a "ref Object var"
so when I call it I must specifiy it as follows

Int16[] list = new Int16[6];
//Initialise array

//Have to cast the array to an Object otherwise it will not compile
object test1 = list;

SampleVariant.C SampleClass sv = new CSampleClass();
sv.MySampleCall (ref list);

the Call on the COM method appears to work, as the first part which
checks the arg type works correctly, but when the COM method exits and
returns to the caller it throws an Unhandled Exception.

Any ideas?
Thanks
Dave
Nov 15 '05 #3

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

Similar topics

6
1690
by: Ivan Voras | last post by:
Can this be done: (this example doesn't work) ---- class A: def a_lengthy_method(self, params): # do some work depending only on data in self and params class B:
6
6905
by: dw | last post by:
Hello all, I'm having a dickens of a time calling a stored procedure on a connection. Every time I do, it generates an error "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another." I've run the same stored procedure with the same exact list of arguments in Query Analyser in SQL Server, and it works. The page has the adovbs constants. Note that uspGetProperties is a stored procedure in SQL...
4
5790
by: Bob Murdoch | last post by:
I have an ASP application that calls a COM function to create a custom report as an Excel file. This works in a synchronous fashion, as long as the report does not take too long to create. If that happens, the session times out and we run into other kinds of problems. I have, in other cases, executed a stored procedure asynchronously (thanks to a tip from this group) thru ADO. I'm wondering if ASP provides some way of executing a...
2
6930
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on a type mismatch. It is positively because of the boolean(java primitive)parameter. It goes fine if I change this parameter to int or String. This inteface has a lot more methods which works fine, it is just the
9
8609
by: Keith Rowe | last post by:
Hello, I am trying to reference a Shockwave Flash Object on a vb code behind page in an ASP.NET project and I receive the following error: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). On the aspx page I have the object tag as follows:
14
3015
by: ericellsworth | last post by:
Hi, I'm trying to use a class to pass variables back and forth from a form opened in dialog mode. I have created a class which invokes a form in its show method, like so: Public Sub Show() ' This method shows the form used to get the info If sWhereInt = "" Then DoCmd.OpenForm sFormNameInt, acNormal, , , acFormAdd, _
3
2677
by: RC | last post by:
Hi, I have a dll written by vb6. AFunction(ByRef o as Variant) I want to use it in csharp by System.Reflection. Assembly asm = Assembly.LoadFrom("Lib.dll"); Type t = asm.GetTypes("Lib.CLib"); object o = Activator.CreateInstance(t);
2
3553
by: avanhalen | last post by:
To embed flash objects in my pages, I read them from a database. A script file (Filedownload.aspx) reads it from the database, and streams it to the browser. Here are two example flash objects in a page. The first 1 (a simple link to an existing swf-file on the webserver) is showing in each browser (IE & FF), while the other one (using the filedownload page) is only being shown in FF. Does it have something to do with file-extension?
2
1682
by: ph33red | last post by:
Hi, I'm having a problem getting my code to pull the appropriate information when I call for it via URL. (example: http://..../.php?id=2). For some reason I can't get it to pull the information for ID #2 (or any ID over 1) and input that information into my dynamic page. No matter what ID i type, or even if I neglect to type in an ID to begin with, it displays the same information. What am I doing wrong? The entire code for my page is pasted...
0
9719
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...
1
10374
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,...
0
10111
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
7650
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
6877
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
5546
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
4330
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
3853
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
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.