473,769 Members | 7,315 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 7263
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
1891
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
96497
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
965
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
9589
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
9423
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
10219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9998
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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
8876
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.