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

ActiveX c# Array

Is this really as hard as it seems. I've been truly suprised by the
lack of any information/suggestions about this. It should be so simple.

In c# I have:

double [] data = {1.0,2.0,3.0,4.0};

I need to pas this array to an ActiveX control which I have written in
Visual Studio 6 using the ActiveX wizard.

So I have full control over both sets of source code. How can I Add a
method to the ActiveX control which I can call from the c# code to pass
the array.

I've done this countless times with MFC c++ using SAFEARRYs and
SAEFARRAYs in a VARIANT. But I cannot get this to work from c#. Has
anyone ever done it?

Any help greatly appreciated,
Mitch.

May 4 '06 #1
5 3762

<mi***@bmtmis.demon.co.uk> wrote in message
news:11*********************@j73g2000cwa.googlegro ups.com...
| Is this really as hard as it seems. I've been truly suprised by the
| lack of any information/suggestions about this. It should be so simple.
|
| In c# I have:
|
| double [] data = {1.0,2.0,3.0,4.0};
|
| I need to pas this array to an ActiveX control which I have written in
| Visual Studio 6 using the ActiveX wizard.
|
| So I have full control over both sets of source code. How can I Add a
| method to the ActiveX control which I can call from the c# code to pass
| the array.
|
| I've done this countless times with MFC c++ using SAFEARRYs and
| SAEFARRAYs in a VARIANT. But I cannot get this to work from c#. Has
| anyone ever done it?
|
| Any help greatly appreciated,
| Mitch.
|

Declare your method taking a SAFEARRAY of double in IDL.

HRESULT PassDoubleArray([in] SAFEARRAY(double) arr);

implement like:

STDMETHODIMP CTest::PassDoubleArray(SAFEARRAY * arr)
{
double* temp;
SafeArrayAccessData(arr, (void**)&temp);
long ubound;
SafeArrayGetUBound(arr, 1, &ubound);
for(int i = 0; i <= ubound; i++)
// use array data
..
SafeArrayUnaccessData(arr);
return S_OK;
}


and call it from C# like this:

double[] darr = new double[5] {1.1, 2.2, 3.3, 4.44, 5.2356};

obj.PassDoubleArray(darr);

Willy.

May 4 '06 #2
Hi, thanks for your reply. It doesn't work :(

In my ODL file I have:

[id(3)] void UseArray([in]SAFEARRAY(double) pArray);

In my ctl header I have:

afx_msg void UseArray(SAFEARRAY* pArray);

And in my ctl cpp file I have:

void CTestOCXCtrl::UseArray(SAFEARRAY* pArray)
{
AfxMessageBox("Use Array");
}

Finally in my DISPATCH_MAP of my ctl cpp I have:

DISP_FUNCTION(CTestOCXCtrl, "UseArray", UseArray, VT_EMPTY, VTS_R8)

I get a type mismatch error when running from c# using exactly the c#
call you suggested.

Is my DISPATCH_MAP declaration in error?

May 4 '06 #3

<mi***@bmtmis.demon.co.uk> wrote in message
news:11********************@i39g2000cwa.googlegrou ps.com...
| Hi, thanks for your reply. It doesn't work :(
|
| In my ODL file I have:
|
| [id(3)] void UseArray([in]SAFEARRAY(double) pArray);
|
| In my ctl header I have:
|
| afx_msg void UseArray(SAFEARRAY* pArray);
|
| And in my ctl cpp file I have:
| |
void CTestOCXCtrl::UseArray(SAFEARRAY* pArray)
| {
| AfxMessageBox("Use Array");
| }
|
| Finally in my DISPATCH_MAP of my ctl cpp I have:
|
| DISP_FUNCTION(CTestOCXCtrl, "UseArray", UseArray, VT_EMPTY, VTS_R8)
|
| I get a type mismatch error when running from c# using exactly the c#
| call you suggested.
|
| Is my DISPATCH_MAP declaration in error?
|

Oh, MFC and Dispatch interfaces, don't know anything about SAFEARRAY's, try
to pass the argument as VARIANT array of doubles, or a VARIANT array of
VARIANTs.

ODL..
([in] VARIANT arr)

afx_msg void UseArray(VARIANT var);
Implemenattion ...
void CTestOCXCtrl::UseArray(VARIANT var)
{
HRESULT hr = S_OK;
long low, up, dim;
VARTYPE vt = V_VT(&arr);
if (vt & VT_ARRAY) {
LPSAFEARRAY psa = V_ARRAY(&arr);
dim = SafeArrayGetDim(psa);
SafeArrayGetLBound(psa, dim, &low);
SafeArrayGetUBound(psa, dim, &up);
switch(vt)
{
case (VT_ARRAY | VT_R8): // array of doubles
{
double* temp;
SafeArrayAccessData(psa, (void**)&temp);
for (int i = low; i <= up; i++)
{
// use array data
}
SafeArrayUnaccessData(psa);
break;
}
default:
hr = E_INVALIDARG;
}
}
else
hr = E_INVALIDARG;
return hr;
}

Usage:
xxx.UseArray((object)arrayOfDoubles); // need to cast to object (VARIANT ==
object)

Willy.
May 4 '06 #4
Sadly this dies not work either. I've pretty much exhausted every
possibility. Very sad state of affairs. I have:

In ODL file:

[id(3)] void UseArray([in] VARIANT arr);

In ctl header:

afx_msg void UseArray(VARIANT var);

In ctl cpp:

void CTestOCXCtrl::UseArray(VARIANT pArray)
{
AfxMessageBox("Use Array");
}

And from c# I have:

double[] darr = new double[5] {1.1, 2.2, 3.3, 4.44, 5.2356};

axTestOCX1.UseArray((object)darr);

Bizzarely, when I execute the above c# command I see the "Use Array"
text box come up TWICE! After which I get an exeption "Object Reference
Not Set To An Instance Of Object"

:(

This shouldn't be at all hard.

May 5 '06 #5

<mi***@bmtmis.demon.co.uk> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
| Sadly this dies not work either. I've pretty much exhausted every
| possibility. Very sad state of affairs. I have:
|
| In ODL file:
|
| [id(3)] void UseArray([in] VARIANT arr);
|
| In ctl header:
|
| afx_msg void UseArray(VARIANT var);
|
| In ctl cpp:
|
| void CTestOCXCtrl::UseArray(VARIANT pArray)
| {
| AfxMessageBox("Use Array");
| }
|
| And from c# I have:
|
| double[] darr = new double[5] {1.1, 2.2, 3.3, 4.44, 5.2356};
|
| axTestOCX1.UseArray((object)darr);
|
| Bizzarely, when I execute the above c# command I see the "Use Array"
| text box come up TWICE! After which I get an exeption "Object Reference
| Not Set To An Instance Of Object"
|
| :(
|
| This shouldn't be at all hard.
|
It's not possible to get the dialog twice without calling the method twice.
Don't know why you get the null ref. exception, without you posting the
whole code.
Why not run this in the debugger and see what happens.

Willy.

May 6 '06 #6

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

Similar topics

3
by: Tash Robinson | last post by:
Hi I am kind of new to active-x programming, and need a point in the right direction. I have an active-x control that I wrote in VB6. I wrote a testbed in VB and everything seems to work OK....
2
by: Owen Woo | last post by:
My activeX control developped in VC++ has following method: void AppendData(double* databuf) How can I call this method in C# and transfer the databuf parameter to it?
1
by: Craig | last post by:
I am having problems getting an ActiveX DLL written in VB6 to call a method in a C# class library component. My C# DLL is called CSharpProject.dll and contains a public class called CSharpClass....
20
by: Cybertof | last post by:
Hello, Is there a good way to call a big time-consumming function from an ActiveX DLL (interoped) through a thread without blocking the main UI ? Here are the details : I have a class...
0
by: Robert Jenkins | last post by:
I am trying to send a string of data to a remote Terminal Server session via the ActiveX client. I can start the session login or logout okay but I can't send data very well. I can send any data...
3
by: Weston Fryatt | last post by:
Simple question I hope.... How do I send data to and from an ASP.Net (server side) web page to a ActiveX Control (client side) embedded in a web browser??? What I need to do, is I have image...
23
by: Galen Somerville | last post by:
A VB6 ActiveX.exe raises an event which is seen by the VB6 App. Same setup in VB2005. The event to be raised is in form frmSweep. As in VB6, frmSweep is hidden when the events take place. I...
0
by: Gadjuka | last post by:
Hi! I'm using Type.InvokeMember() to call functions in an ActiveX Dll written in Vb6 from C#. The function I need to call have several String-arrays as arguments and these act as out-parameters. It...
2
by: deccio | last post by:
I have create an activex Control with Visual studio 2005 and framework 2.0 in c# to add drag & drop functionality to upload multi file. When I use it in a windows form it work fine. Infact if I...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...
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,...

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.