473,883 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Difference between [In, Out] and ref parameter usage....


Hello NewsGroup,

More out of curiosity, now I'd love to know which is a better way, if one
can think in such terms in this context. If I implement the ChooseColor API
function, the documentation states (briefly);

BOOL ChooseColor(LPC HOOSECOLOR lpcc);

lpcc is defined as "...[in, out] Pointer to a CHOOSECOLOR structure that..."
and you know or know where to read the rest of it.

I can interpret hence implement this in two ways (I know this may sound
trivial, I just want to know);

1) CHOOSECOLOR as a class;

private class CCHOOSECOLOR
{
internal Int32 lStructSize = 0;
... //And the rest of it
}

Hence the API call as;
[DllImport("Comd lg32.dll", EntryPoint = "ChooseColo r")]
private static extern bool ChooseColor([In, Out] CCHOOSECOLOR lpcc);
internal static bool ChooseColorApi([In, Out] CCHOOSECOLOR lpcc)
{
return ChooseColor(lpc c);
}
---------------------------------------------------------------------------------
2) CHOOSECOLOR as a structure;

private struct CHOOSECOLOR
{
internal Int32 lStructSize;
... //And the rest of it
}

Hence the API call as;
[DllImport("Comd lg32.dll", EntryPoint = "ChooseColo r")]
private static extern bool ChooseColor(ref CCHOOSECOLOR lpcc);
internal static bool ChooseColorApi( ref CCHOOSECOLOR lpcc)
{
return ChooseColor(ref lpcc);
}

Both work real well so to get pedantic on you all (sorry about that) would
there be any advantage or disadvantage on one way over the other? Hence
would the be a preferable way? The reason I ask the difference between [In,
Out] and ref is because if I use [In, Out] in the struct version nothing
works and I get errors vice versa as well. Also nothing (obviously) works if
[In, Out] or ref are left out.

Thanks NewGroup, this is no show stopper for me and I only ask out of
curiosity.

Regards,
SpotNet
Feb 5 '06 #1
2 2326
If it is a color options then I'd personally prefer to use a property.
It looks like it is taking a pointer to a color object so you should
probably work around the object/class concept. Perhaps adding 1 more
level of indirection would solve your task.
Curtis
http://www.ghostclip.com
The Premier Help System For Developers

Feb 5 '06 #2
"SpotNet" <Sp*****@msnews .grp> wrote in message news:eL******** ******@TK2MSFTN GP11.phx.gbl...

Hello NewsGroup,

More out of curiosity, now I'd love to know which is a better way, if one
can think in such terms in this context. If I implement the ChooseColor API
function, the documentation states (briefly);

<snip the actual interop>

Hi,

The guts of the call to the API should be totally hidden from the End user.
You can implement the icky part however you wish.
The methods exposed to Dotnet, however, should no nothing about the internal stuff.
Implement a ColorChooser class Wrapper (probably a static class).
Implement a Method like this

/* NOT TESTED */
public static Color PickColor() /// assumes using System.Drawing.
{
Color color = Color.Empty
..
//Your interop API stuff goes here
if (OK) // user pressed OK
color = ColorTranslator .FromWin32(cc.r gbResult); // cc is the CHOOSECOLOR struct
return (color);
}
The user simply needs to check if (color == Color.Empty) to see if a color was selected

Make it look like it was Part of Dotnet
Hope this helps
Bill


Feb 5 '06 #3

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

Similar topics

8
378
by: Chris Mayers | last post by:
'out' and 'ref' parameters in C#... Both these can be used to pass parameter values BACK from a Method, but obviously they are different techniques. As I understand it, 'ref' parameter passes the object into the Method by Reference, ie passes the memory location of the original object in the parameter list. The Method may change the value of the object and by doing so, will be changing the
4
2739
by: wkaras | last post by:
I would like to propose the following changes to the C++ Standard, the goal of which are to provide an improved ability to specify the constraints on type parameters to templates. Let me say from the start that my knowledge of compiler implementation is very limited. Therefore, my suggestions may have to be rejected because they are difficult or impossible to implement. The proposal is based on the concept of "type similarity". Type...
10
5151
by: David | last post by:
what's the differences between: int main(int argc,char* argv){ ... } and: int main(int argc,char** argv){ ...
33
2627
by: C# Learner | last post by:
Note ---- Please use a fixed-width font to view this, such as Courier New. Problem
10
18149
by: Jon Davis | last post by:
I've been using the ref keyword as a way of passing strings to methods as references so that in the method I don't have to manually return the modified "version" of what was passed into the method, I just have to assign a new value to the ref'd argument. However, I've learned that the 'out' keyword seems to do something just like this. I'm kind of confused; what's the practical difference between 'ref' and 'out' for my intents? Thanks,
1
2287
by: Alex Chan | last post by:
Hi Group, I have written a window service wtih SAP.NET Connector which is to fulfil request from SAP client. SAP client will call a function exposed by my window service that has a big "out" parameter. That "out" parameter is of class SAPTable, you can regard that as DataTable. As everytime SAP client issue request to my window service, it will connect to oracle and do some searching and return the result in a SAPTable. I did a volume...
9
22031
by: aczapran | last post by:
Everything I read on DB2 indicates that the bufferpool is a pool of database pages used to speed up database access. It is controlled by us, when we specify how many pages we would like to have allocated. My question is: 1. Under what circumstances can the buffer pool run out? Its my understanding that we would go into synchronous read/write mode if all pages were dirty and we needed to read in a new page. In this case, why would it...
10
16684
by: ravi | last post by:
Hi, i am a c++ programmer, now i want to learn programming in c also. so can anybody explain me the difference b/w call by reference and call by pointer (with example if possible).
7
2153
by: coolsti | last post by:
I have just noticed a very large difference in memory usage for the PHP applications that I have developed for my company between my developmental machine and the "production" machine: Development PC: PHP version 4.3.9 on a 32 bit using Linux Centos 4.5 as operating system. Production machine: PHP version 5.1.2 on a 64 bit machine with Linux Novell Suse 10.1 as operating system. I noticed this because I started to get memory limit...
0
9944
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
9796
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,...
1
10860
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
10420
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
9583
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
7975
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
7134
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();...
1
4620
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
4225
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.