473,758 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetObje ctForNativeVari ant(), but of
no use.

With regards,
-Sridhar
Jul 21 '05 #1
1 7260
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.GetObje ctForNativeVari ant() 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::Conv ertStringToBSTR (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.WriteLi ne((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********@gei nd.ge.com>
Sender: "C. N. Sridhar" <sr********@gei nd.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/0YDhRRNePfI0ukO geKQ==
Newsgroups: microsoft.publi c.dotnet.genera l
Path: cpmsftngxa06.ph x.gbl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:107952
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.publi c.dotnet.genera l

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.GetObje ctForNativeVari ant(), 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
1888
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. There seems to be very little documentation/examples on this. I have a "Service" that needs to have a COM
3
1312
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 below... --
5
96494
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 what it is. Is converting a C-style struct to a C# class (or struct) marshalling? And what about the function exports? Are those Marshalling too? Thanks for your help and thanks for helping me with the Dll exports (the several messages I posted in...
0
964
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? Jemar
19
2095
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 it to your liking. ' Here is an example of use: ' start with a string of "1" Dim da As Variant = new Variant("1") ' add an integer of 2, becomes 3
1
372
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# (managed code)? I tried using Marshal.GetObjectForNativeVariant(), but of no use.
2
4194
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, VARIANT &vRetVal); Now for the first time I want to use C Sharp and I find some examples to use Functions in extarnal DLLs, but I don't know how to cast the Variant-Paramters in C Sharp.
0
1083
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 is the function in vc 6.0 ocx.Function name is myRetrieve Image. BOOL CICACtrl::RetrieveImage(long iEventID, long iImageID, const VARIANT FAR& Image, short FAR* iWidth, short FAR* iHeight, short FAR* iDepth) { if(switchFlag == 0)
0
1876
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 implement a performance improvement in the transfer of thousands of objects (ClientInfoDescriptor) over a remote call. The objects all have a model object (IDataDrivenModel) to describe them but there may only two or three model objects in total. These...
0
9492
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9299
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9908
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9740
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5332
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3832
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3402
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2702
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.