Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2005

Tip: Looking for answers? Try searching our database.

Converting pointer to safearray

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ruslan Popov - 14 Nov 2005 12:07 GMT
Hello,

I have a method in C# exposed to COM like this:

HRESULT SetArray2([in, out] VARIANT* ar)

When an array is passed to this method from VBA, it comes to C# as an
integer, like this: [System.Int32]: {-2146826273}. That's a pointer to a
safearray I guess. How can it be converted to an array of objects?

Signature

Best regards,
Ruslan Popov

"Peter Huang" [MSFT] - 15 Nov 2005 07:04 GMT
Hi

Thanks for your posting.
Can you post some VBA code and C# code to demo what you are doing to
interactive between C# and VBA?

Also here is google link may related with what do you want to do?
using VB6 Collections in c#
http://groups.google.com/group/microsoft.public.dotnet.framework.interop/bro
wse_thread/thread/c6be6cf7982d93c/20e796f44c6cdcb3?lnk=st&q=%22v-phuang%22+c
ollection+c%23&rnum=4&hl=zh-CN#20e796f44c6cdcb3

http://support.microsoft.com/?kbid=323737

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Ruslan Popov - 16 Nov 2005 08:25 GMT
Hi,

Nope, collections have nothing to do with my question - I'm talking about
variants.

This is C# code:

    ClassInterface(ClassInterfaceType.AutoDual)]
    public class TestObject
    {
        public void SetArray2(ref object ar)
        {
            // array comes here as int
            Debug.WriteLine(ar.GetType().Name);
        }
    }

This is VBA code:

Call a.SetArray2([1, 2, "str"])

Here's what's output by the C# method during debugging:

Int32

Here's the value of the argument (ar):

{-2146826273}
   [System.Int32]: {-2146826273}

Signature

Best regards,
Ruslan Popov

"Peter Huang" [MSFT] - 16 Nov 2005 11:30 GMT
Hi

I think you may to use the Array in VBA.
Sub Test()
Dim o As New ExposeSafeArray.TestClass
Dim r As Variant
r = Array(1, 2, "Test")
Call o.MyMethod(r)
End Sub

public void MyMethod(ref object param)
{
    try
    {
        object[] obs=(object[])param;
        for(int i=0;i<=obs.GetUpperBound(0);i++)
            Debug.WriteLine(obs[i].ToString());
    }
    catch(Exception ex)
    {
        Debug.WriteLine(ex.ToString());
    }
}

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Ruslan Popov - 16 Nov 2005 13:08 GMT
You are right, Peter. Thanks. :)

Signature

Best regards,
Ruslan Popov

"Peter Huang" [MSFT] - 17 Nov 2005 02:37 GMT
Hi

You are welcomed!

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.