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

passing SAFEARRAY from COM to C#

Hi all,

I'm very new to C#, and I've tried to find an answer to my problems.
We've got a method in an existing COM object as follows:

BOOL CCacheCtrl::IdFromStringRep(LPCTSTR lpszIdStringRep, const
VARIANT FAR& vaResult)
{
ID id;

if ((vaResult.vt == (VT_VARIANT | VT_BYREF)) || (vaResult.vt ==
VT_EMPTY))
{
// reset the SAFEARRAY in vaResult.pvarVal based on
lpszIdStringRep
}

return TRUE;
}

It works with VB no problem. Now we want to try in C#, but we got no
luck. Our code is

===
Byte[] SecondID = new Byte[] {1, 2, 3, 4, 5, 6, 7, 8};
object oid = SecondID;
bool success = myCache.IdFromStringRep(strCompare, oid );
===

Nothing seems wrong, but oid is not changed based on the strCompare
value. So we thought we could add a new method as follows

BOOL CCacheCtrl::IdFromStringRep2(LPCTSTR lpszIdStringRep, VARIANT *
pResult)

In C# we do

===
bool success = myCache.IdFromStringRep2(strCompare, ref oid);
===

However, oid is still unchanged!! What did we do wrong?

Thank you for reading my long post!!
Jenny
Nov 16 '05 #1
1 4648
Hello? Does anyone know the answer?
Thanks,
Jenny
yi*******@hotmail.com (Jenny Tam) wrote in message news:<d6**************************@posting.google. com>...
Hi all,

I'm very new to C#, and I've tried to find an answer to my problems.
We've got a method in an existing COM object as follows:

BOOL CCacheCtrl::IdFromStringRep(LPCTSTR lpszIdStringRep, const
VARIANT FAR& vaResult)
{
ID id;

if ((vaResult.vt == (VT_VARIANT | VT_BYREF)) || (vaResult.vt ==
VT_EMPTY))
{
// reset the SAFEARRAY in vaResult.pvarVal based on
lpszIdStringRep
}

return TRUE;
}

It works with VB no problem. Now we want to try in C#, but we got no
luck. Our code is

===
Byte[] SecondID = new Byte[] {1, 2, 3, 4, 5, 6, 7, 8};
object oid = SecondID;
bool success = myCache.IdFromStringRep(strCompare, oid );
===

Nothing seems wrong, but oid is not changed based on the strCompare
value. So we thought we could add a new method as follows

BOOL CCacheCtrl::IdFromStringRep2(LPCTSTR lpszIdStringRep, VARIANT *
pResult)

In C# we do

===
bool success = myCache.IdFromStringRep2(strCompare, ref oid);
===

However, oid is still unchanged!! What did we do wrong?

Thank you for reading my long post!!
Jenny

Nov 16 '05 #2

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

Similar topics

2
by: Ken Layton | last post by:
Attempting to pass a VBScript Array of Bytes to a C# Managed COM object has resulted in some very undesirable and strange behavior. When definining a method in my C# COM class as "void Write(byte...
3
by: Sascha Herpers | last post by:
Hi, I wrote a c dll with a type library to use it in vb. No problem, everything works fine. Now I needed to pass an array of type double to the dll. I defined the function in the type...
4
by: Roland Moschel | last post by:
Hi there ! I have some Problems to get a SafeArray out of a COM Server written in (Unmanaged) C++. From (unmanaged) Visual Basic , everything is ok , but unfortunately in C# I get an...
7
by: Tim | last post by:
When there is a need to pass some dynamic information between 2 managed assemblies, the "Dictionary object" in Generic form can be used as a method parameter to pass the information. The...
0
by: mitch | last post by:
Hi, could anyone help me with the following problem? I have an ActiveX control developed using Visual Studio 6.0 and it has a method declared in the .odl file as follows: void...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
3
by: cskarp | last post by:
I have create a .Net component which exposes an interface with two methods. The first method takes an array of structs as a parameter the other method returns an array of (the same tyoes of) structs....
4
by: Steven Blair | last post by:
I have some C++ code which creates a SafeArray and passes it to my C# dll using COM: SAFEARRAY *psaOut = SafeArrayCreateVector(VT_BSTR, 0, 3); VARIANT pVarOut; VariantInit(&pVarOut);...
0
skeptics
by: skeptics | last post by:
Trying to pass a SafeArray that i get form Request.BinaryRead Method in classic asp to a c# com interop component. In this thread i found a solution to pass and cast a normal asp safearray in to a c#...
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?
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:
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.