473,399 Members | 2,774 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,399 software developers and data experts.

Marshaling Variant object

Hi,
I'm writing a wrapper to a win32 dll in C#. I need to call
a method in DLL which has a Variant type reference
parameter.

How to marshal variant type from win32 (unmanaged code)
to C# (managed code)?

I tried using Marshal.GetObjectForNativeVariant(), but of
no use.

With regards,
-Sridhar
Jul 21 '05 #1
1 7223
Hi Sridhar,

Here is my understanding of your question. You have a dll function with a
reference VARIANT parameter, and now you hope to call it in C#.
Here is my sample code below.
Did I misunderstand your meaning?
I do not know why you need to call Marshal.GetObjectForNativeVariant() to
Marshal the Variant data type.
If you have further question, please post some code, such as the dll
function declaration and the DllImport declaration in C#.

[StdDLL.dll]
long __declspec (dllexport) __stdcall Func11(VARIANT& MyArray){
MyArray.vt = VT_BSTR;
char* lpszText = "Test";
BSTR bstrText = _com_util::ConvertStringToBSTR(lpszText);
MyArray.bstrVal =bstrText;
return 8;
}

[DllImport(@"c:\StdDLL.dll")]
public static extern int Func11(ref object var);
[STAThread]
static void Main(string[] args)
{
object s= new object();
int rt = Func11(ref s);
Console.WriteLine((string)s);
}

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Content-Class: urn:content-classes:message
From: "C. N. Sridhar" <sr********@geind.ge.com>
Sender: "C. N. Sridhar" <sr********@geind.ge.com>
Subject: Marshaling Variant object
Date: Wed, 10 Sep 2003 07:30:45 -0700
Lines: 13
Message-ID: <0e****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcN3qB8487/0YDhRRNePfI0ukOgeKQ==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:107952
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.public.dotnet.general

Hi,
I'm writing a wrapper to a win32 dll in C#. I need to call
a method in DLL which has a Variant type reference
parameter.

How to marshal variant type from win32 (unmanaged code)
to C# (managed code)?

I tried using Marshal.GetObjectForNativeVariant(), but of
no use.

With regards,
-Sridhar


Jul 21 '05 #2

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

Similar topics

0
by: Ash | last post by:
Hi, Has anyone ever tried using "COM marshaling" for cross- process communication? In particular, I am interested in cross-process marshaling between Managed Server and Unmanaged Client. ...
3
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example...
5
by: VM | last post by:
What's marshalling? I've had to use it extensively for a project but I don't know what it means. I tried to look for a definition in the Internet but I couldn't find anything that would explain...
0
by: Jemar | last post by:
I need to pass VARIANTs from unmanaged C++ to VB.NET. VARIANTS may contain arrays as well as simple types. Is there a standard Marshaling way of doing this or will I have to implement it myself?...
19
by: Jon Davis | last post by:
Hi guys! Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days. This is written in C#, but you can build a CLR/.NET class library assembly and reference...
1
by: C. N. Sridhar | last post by:
Hi, I'm writing a wrapper to a win32 dll in C#. I need to call a method in DLL which has a Variant type reference parameter. How to marshal variant type from win32 (unmanaged code) to C#...
2
by: Heike | last post by:
Hello everybody, I have a Problem with C Sharp. I have to use external functions in DLLs. This Functions are written in Visual C++ 6 like this: int (__stdcall *GetGlobalValue) (VARIANT Appl,...
0
by: KYAW KO KO | last post by:
Hi all, I am dot net new user.I am trying to use active x control from vc 6.0 in dot net.I have data marshaling problem in combination dot net and ocx from vc 6.0. The following...
0
by: jpogorman | last post by:
Hello, I am trying to get c# custom marshaling working in a particular scenario but it does not appear to be working or not jumping into my marshaling class when I try to debug it. I am try to...
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: 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: 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
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
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
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...
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.