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

activeX array transfer

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?
Nov 15 '05 #1
2 3200
This should be declared as:

void AppendData(double[] databuf);

The reason it should be declared like this is because if you declare it
as "ref double" then it will pass only the first item of the array.

If the method modifies the array in any way, then this won't work
either. Because this is a C-style array, it doesn't know what was modified
in the unmanaged realm (SAFEARRAYs don't have this problem) and can't just
marshal all of the memory in the array back.

If the contents are modified, then you will have to declare databuf as
an IntPtr and then allocate the memory yourself (using the static Alloc*
methods on the Marshal class). Then you write to the unmanaged memory block
and pass it to the method. On return from the method, you have to read the
unmanaged memory back from the unmanaged memory block (and free the memory
block as well).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Owen Woo" <wo*****@163.net> wrote in message
news:uQ**************@TK2MSFTNGP12.phx.gbl...
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?

Nov 15 '05 #2
I compiled the control in VC++ and import the OCX into C#, the method was
defined by the system as following:
void AppendData(ref double databuf)
How can I declare the method by myself in C#?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> дÈëÏûÏ¢
ÐÂÎÅ:eK**************@tk2msftngp13.phx.gbl...
This should be declared as:

void AppendData(double[] databuf);

The reason it should be declared like this is because if you declare it as "ref double" then it will pass only the first item of the array.

If the method modifies the array in any way, then this won't work
either. Because this is a C-style array, it doesn't know what was modified in the unmanaged realm (SAFEARRAYs don't have this problem) and can't just
marshal all of the memory in the array back.

If the contents are modified, then you will have to declare databuf as
an IntPtr and then allocate the memory yourself (using the static Alloc*
methods on the Marshal class). Then you write to the unmanaged memory block and pass it to the method. On return from the method, you have to read the unmanaged memory back from the unmanaged memory block (and free the memory
block as well).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Owen Woo" <wo*****@163.net> wrote in message
news:uQ**************@TK2MSFTNGP12.phx.gbl...
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?


Nov 15 '05 #3

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

Similar topics

3
by: adam | last post by:
hi is it possible to write activeX controls in C# and if so any suggestions of links to sample code would be appreciated? thanks Adam
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...
4
by: Brian | last post by:
Hi, I'm trying to make an online FTP utility in C# ASP.NET using MSINET.ocx (an active X control a.k.a. "Microsoft Internet Transfer Control") I've added the reference into my project and have...
3
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C...
5
by: mitch | last post by:
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...
2
by: Mehdi | last post by:
hi everybody I want to pass a bitmap file from activeX component that written in vc+ +6 to my project in c#.Net. how can transfer a bitmap file? is it possible that with return a pointer...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.