473,772 Members | 2,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning good old string parameters with Type.InvokeMemb er

Hi
I need to be able to return a string from a VB6 method:

Public Sub GetMessageAsPar ameter(ByRef message As String)
message = "GetMessageAsPa rameter worked!"
End Sub

which is implemented inside an ActiveX DLL. I need to do this using late
binding so I am trying to do it with code like this:

object[] parameters = new object[1];
ParameterModifi er parameterModifi ers = new ParameterModifi er(1);

// Allocate some space for the parameter
parameters[0] = new string(' ', 100);

parameterModifi ers[0] = true;
ParameterModifi er[] parameterModifi er = { parameterModifi ers };

comType.InvokeM ember("GetMessa geAsParameter",
BindingFlags.In vokeMethod, null, comObject, parameters, parameterModifi er,
null, null);

Console.WriteLi ne(String.Forma t("\nGetMessage AsParameter:
Message={0}", parameters[0].ToString()));

The problem is that I never get anything coming back. I don't get any
TargetInvocatio nExceptions either. I've tried all the different options of
ByVal and ByRef without success.

Please could anyone advise.

Thanks

Marek
Oct 31 '06 #1
2 2174
Hi
I've worked it out:

parameters[0] = new StringBuilder(1 00).ToString();

Thanks.

Marek

"Marek" wrote:
Hi
I need to be able to return a string from a VB6 method:

Public Sub GetMessageAsPar ameter(ByRef message As String)
message = "GetMessageAsPa rameter worked!"
End Sub

which is implemented inside an ActiveX DLL. I need to do this using late
binding so I am trying to do it with code like this:

object[] parameters = new object[1];
ParameterModifi er parameterModifi ers = new ParameterModifi er(1);

// Allocate some space for the parameter
parameters[0] = new string(' ', 100);

parameterModifi ers[0] = true;
ParameterModifi er[] parameterModifi er = { parameterModifi ers };

comType.InvokeM ember("GetMessa geAsParameter",
BindingFlags.In vokeMethod, null, comObject, parameters, parameterModifi er,
null, null);

Console.WriteLi ne(String.Forma t("\nGetMessage AsParameter:
Message={0}", parameters[0].ToString()));

The problem is that I never get anything coming back. I don't get any
TargetInvocatio nExceptions either. I've tried all the different options of
ByVal and ByRef without success.

Please could anyone advise.

Thanks

Marek
Oct 31 '06 #2
Not sure what happened with the previous reply (appears blank), but the fix
for my problem was:

parameters[0] = new StringBuilder(1 00).ToString();

"Marek" wrote:
Hi
I need to be able to return a string from a VB6 method:

Public Sub GetMessageAsPar ameter(ByRef message As String)
message = "GetMessageAsPa rameter worked!"
End Sub

which is implemented inside an ActiveX DLL. I need to do this using late
binding so I am trying to do it with code like this:

object[] parameters = new object[1];
ParameterModifi er parameterModifi ers = new ParameterModifi er(1);

// Allocate some space for the parameter
parameters[0] = new string(' ', 100);

parameterModifi ers[0] = true;
ParameterModifi er[] parameterModifi er = { parameterModifi ers };

comType.InvokeM ember("GetMessa geAsParameter",
BindingFlags.In vokeMethod, null, comObject, parameters, parameterModifi er,
null, null);

Console.WriteLi ne(String.Forma t("\nGetMessage AsParameter:
Message={0}", parameters[0].ToString()));

The problem is that I never get anything coming back. I don't get any
TargetInvocatio nExceptions either. I've tried all the different options of
ByVal and ByRef without success.

Please could anyone advise.

Thanks

Marek
Oct 31 '06 #3

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

Similar topics

1
1612
by: mike | last post by:
hello, Using Type.InvokeMember to call a method of a class,Which method has byref parameter,It seems that there is no way to return the changed value of that byref parameter by the method of the class. Who can save me? Thanks a lot!
0
1134
by: David | last post by:
Hi, I have a program in which I used invokemember to late bind to a component. In my code I use: SetupInfo setup; Object objTem = callLateBinding ("BackOfficeServer.BackOffice", "getSetupByDescription", parameter); setup = (Transaction.SetupInfo)objTem;
8
2212
by: A.M | last post by:
Hi, Are string parameters in functions by refrence or by value ? Thanks, Ali
1
6138
by: Rein Petersen | last post by:
Hi All, I'm invoking Type.InvokeMember() on a COM class (via COMInterop) through a generalized interface. However, each specialized instance (of the COMInterop generic interface) requires slightly different arguments for which I dynamically create the object arguments and it all works nicely. Problem is, in some instances, I have methods which require certain arguments to be referenced (ref string x,...etc). I'm not sure how I can...
2
2101
by: Mike Moore | last post by:
does anyone have an example of how to get the connection string object converted to a string variable type in order for me to call a function?
11
1986
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have the method below that returns a bool, true or false depending on if the conversion to date tiem works. It takes a string input. I am only returning the bool but would also like to return the string message ex.message, just wondering how to do this since I think you can only return one thing with the function. Thanks. public bool checkdate(String s_date) { b_convert = true ; DateTime dt_temp1 =...
2
3225
by: adh | last post by:
In c# you can return a String() but in VB.NET2005 it does not work (the webservice test sends to the error page). See MS AJAX Controls Toolkit.Autocomplete which demands a String() reply. I prefer doing it in VB but how? Thanks, adh *** Sent via Developersdex http://www.developersdex.com ***
7
2874
by: Thomas Lenz | last post by:
Please consider the following code snippet: string myfunction() { ostringstream oss; oss << "junk"; // do something more with oss; I can't make it const... return oss.str(); } Is the returned string object still valid after myfunction() has returned? I
2
2760
by: GaryDean | last post by:
The following command... string DebugString = System.Web.HttpContext.Current.Server.MapPath("App_Themes"); is executed from my ThemeManager.cs class in my App_code directory It returns... "c:\\inetpub\\wwwroot\\TaxBusiness\\AnonymousAccess\\App_Themes" The folders in my website project are... Admin
1
2040
by: raghunadhs | last post by:
Hi All, i want to create a ATL com Object, and add this object as a reference to my VB application. my ATL com should contain 3 parametes. two are input parameters of type string, and an out put parameter of type long. when i try to pass strings as parameters, the .lib file is being crated and i am able to add it as a reference to my VB application also. but when i try to run the VB application, an error is coming like "Memory out of...
0
9620
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
9454
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
10261
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
10104
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
9912
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
8934
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
7460
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
6715
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
5354
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...

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.