473,786 Members | 2,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object To Variant

I am interfacing to a non .NET app and one of the params is of type variant.
In C# it is asking for an object. I went down that path with no luck. I ran
across using "marshal as" to convert an object to a variant. I cannot see
how to do this? I have 10 params to send a method by reference as type
variant. Is there an easy way to do this? Any help is greatly apprecieated.

Thanks;
Bob;
Nov 13 '05 #1
6 26109
Not so sure about this...but have you tried:
bool retVal = MethodYoureCall ing([ MarshalAs( UnmanagedType.A sAny )]object
parameter1,[ MarshalAs( UnmanagedType.A sAny )]object parameter1);

"Bob Allen" <Bo*@324pm.co m> wrote in message
news:%2******** *********@TK2MS FTNGP10.phx.gbl ...
I am interfacing to a non .NET app and one of the params is of type variant. In C# it is asking for an object. I went down that path with no luck. I ran across using "marshal as" to convert an object to a variant. I cannot see
how to do this? I have 10 params to send a method by reference as type
variant. Is there an easy way to do this? Any help is greatly apprecieated.
Thanks;
Bob;

Nov 13 '05 #2
I have and with no luck. I am using the following method. Which is close to
the same....thanks for post.
[MarshalAs(Unman agedType.AsAny)]
private object primaryFieldRes ultDataSA;

private void MyMethod()

{

int i = callme(ref primaryFieldRes ultDataSA);

}

"Jenny K" <je*****@hotmai l.com> wrote in message
news:OI******** ******@TK2MSFTN GP10.phx.gbl...
Not so sure about this...but have you tried:
bool retVal = MethodYoureCall ing([ MarshalAs( UnmanagedType.A sAny )]object
parameter1,[ MarshalAs( UnmanagedType.A sAny )]object parameter1);

"Bob Allen" <Bo*@324pm.co m> wrote in message
news:%2******** *********@TK2MS FTNGP10.phx.gbl ...
I am interfacing to a non .NET app and one of the params is of type

variant.
In C# it is asking for an object. I went down that path with no luck. I

ran
across using "marshal as" to convert an object to a variant. I cannot see how to do this? I have 10 params to send a method by reference as type
variant. Is there an easy way to do this? Any help is greatly

apprecieated.

Thanks;
Bob;


Nov 13 '05 #3
Bob,
I am interfacing to a non .NET app and one of the params is of type variant.
In C# it is asking for an object. I went down that path with no luck.


So what happened? Did you get an error? What kind of Variant does the
app expect, and what do you pass to it?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 13 '05 #4
Do you know what language the thing that needs the variants is in?
Nov 13 '05 #5
I have tried this a couple different ways. Here are some of the ways is set
it up. And my example is not true to form. I will expain.
1st Way: [MarshalAs(Unman agedType.AsAny)] object fieldIdSA = new int [8];
2nd Way: object fieldIdSA = new int [8];

The method calls for a ref to the object. so my example should be
mymethod(ref fieldIdSA);

In the example project it works in VB6. If you use the type as Variant. But
if i try to do the same in .NET either C# or VB it does not work???? This
one is stumping me....

"Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
news:eS******** *****@TK2MSFTNG P11.phx.gbl...
Bob,
I am trying to write this in C# not VB but i tried it as a last resort to
see if i could at least get results.
This is an error generated by the control. I am getting a return code of
ERROR_WRONG_PA RAM_TYPE Type mismatch in parameter
this is obvious not much to go on.


When moving the code from VB6 to VB.NET or C#, did you remember to
change the array type from Long to Integer/int? I'd expect this to
work

object MFPrimaryFieldS cores = new int[8];
object MFPrimaryResult Data = new string[8];
int ret = mymethod(MFPrim aryFieldScores, MFPrimaryResult Data);

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 13 '05 #6
Bob,
1st Way: [MarshalAs(Unman agedType.AsAny)] object fieldIdSA = new int [8];
You can't attribute individual variable declarations so that shouldn't
even compile.

2nd Way: object fieldIdSA = new int [8];


That looks like it should work, it's the equivalent of the VB code you
posted before. It's hard to say why it doesn't without seeing more of
the code and having the COM object to play with.

Do you know if the COM object was implemented in MFC?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 13 '05 #7

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

Similar topics

2
4891
by: Raoul | last post by:
I wrote a COM server object in C++ a few months ago. I can use it from Visual Basic, Visual C++, S-Plus and a number of other scripting environments. What I can't do is use it with my FAVOURITE scripting language, Python. I have tried everything by I'm going crazy here. Here is what I have...
1
7268
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.
0
1572
by: Russ Gadagno | last post by:
Hi, I’m trying to use net remoteing with Com+. I created a wrapper for the com object. I can call the com object from my c# client and an able to get return type of strings and int’s. One of the methods returns a variant. I can get the object back from the com object but cannot convert it. I tried using adodb. examples I tried is. object dept = obj.tryme();--- this wraps the com call which returns a variant. ADODB._Recordset rs...
2
13438
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 bBytes)" or "void Write(byte bBytes, int nLen)" or "int Write(byte bBytes, int nLen)"VBScript returns a "Invalid procedure call or argument" exception. However when I define the method as "int Write(byte bBytes)" it works just fine. Unfortunately...
3
4660
by: tigrrgrr42 | last post by:
I am working(vb.net03and05) with word documents stored in a sql db and I am currently bringing them from a byte array into a temp file to pop into word and make word do its thing as a com object. Is it possible to go straight from a byte array to document in word instead of a temp file? Also is there a way to change the save behaviour to notify my app to pickup a binary copy of the file or stream to save back to the sql db. Thanks in...
19
4662
by: Alan Carpenter | last post by:
Access 8 on Win98 and WinXP I'm having trouble with wildcards in the .Filename property of the FileSearch Object giving different results on win98 and XP. I've been successfully using FileSearch in win98 to fill an array with filenames with no problems since about 1998. From the 97 Help: (The Filename Property of the FileSearch object) --------------------------
4
6001
by: buzzluck68 | last post by:
Hello, I am having trouble upgrading my VB apps to .net. When i started at my company there was a dll created here in vb6, and i need to use that dll for many functions that would take too much time to re-create for the limit that i am given. I have to create a new app in .net, per my instructions, but the dll uses variant arrays, and i keep getting an error whenever i pass an object array from my .net app to the vb6 dll which needs...
4
4679
by: =?Utf-8?B?cGJsYWNrYnVybg==?= | last post by:
Summary Getting the error message Run time error 424 Object Required when attempting to assign a value to a C# COM visible property of type object. I have created a COM visible class as below using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices;
0
2999
by: dileepsree | last post by:
My aim is :- Pass C# object as a parameter of unmanaged Dll(vc++ 6.0) method . with in the unmaaged dll methedod construct similar C++ class instance . vice versa from dll method argument VARIANT result has to be converted to C# object For this , I tried Marshal.GetNativeVariantForObject(s, p); or Marshal.StructureToPtr(segInfo, ptrValue, false);
0
9650
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
9497
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
10363
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...
0
6748
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
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
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
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.