473,236 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 software developers and data experts.

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(LPCHOOSECOLOR 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("Comdlg32.dll", EntryPoint = "ChooseColor")]
private static extern bool ChooseColor([In, Out] CCHOOSECOLOR lpcc);
internal static bool ChooseColorApi([In, Out] CCHOOSECOLOR lpcc)
{
return ChooseColor(lpcc);
}
---------------------------------------------------------------------------------
2) CHOOSECOLOR as a structure;

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

Hence the API call as;
[DllImport("Comdlg32.dll", EntryPoint = "ChooseColor")]
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 2302
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**************@TK2MSFTNGP11.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.rgbResult); // 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
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...
4
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...
10
by: David | last post by:
what's the differences between: int main(int argc,char* argv){ ... } and: int main(int argc,char** argv){ ...
33
by: C# Learner | last post by:
Note ---- Please use a fixed-width font to view this, such as Courier New. Problem
10
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,...
1
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"...
9
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...
10
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
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.