|
|
Hi all
How does one do this? My compiler just complains
[DllImport("any.dll")]
static extern void Function(ref int icanbenull, ref int icanbenull2);
void AnyOldFunction()
{
int output = 0;
Function( ref output, null);
return output;
}
UPDATE:
After lotsa searching the haystack, I found a way to quiet the compiler, but the questions is, will this work? Will my int get treated as by ref or by value?
[DllImport("any.dll")]
static extern void Function(
[ MarshalAs( UnmanagedType.AsAny ), Out]object icanbenull,
[ MarshalAs( UnmanagedType.AsAny ), Out]object icanbenull2);
int AnyOldFunction()
{
int output = 0;
Function( output, null);
return output;
}
Unfortunately, I cant test this at the moment
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Did you try:
IntPtr.Zero
inplace of null?
C# won't let you pass null directly in this situation.
|
|
|
|
|
doesnt work.
From MSDN for IntPtr.Zero:
Remarks
The value of this field is not equivalent to a null reference
BTW the in the dll API, specify that either parameter can be an ref int (a value to retrieve) or null (value should not be retrieved).
Anyways once i get the other parts done, i'll try to see what results i get.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Did you try overloading the declaration?
[DllImport("any.dll")]
static extern void Function(ref int icanbenull, ref int icanbenull2);
[DllImport("any.dll")]
static extern void Function(ref int icanbenull, object icanbenull2);
[DllImport("any.dll")]
static extern void Function(object icanbenull, ref int icanbenull2);
[DllImport("any.dll")]
static extern void Function(object icanbenull, object icanbenull2);
int AnyOldFunction()
{
int output = 0;
Function( ref output, null);
return output;
}
|
|
|
|
|
Thanx , i thought of this too, but imagine having 5 parameters , then you will need 25 overloads. too much work for me .
I simplified the dll function in the 1st post.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
all i hade to do is put both the extern and calling function in an unsafe context and use the */& notation, no ref or out needed. Maybe I'm just not reading the C++ to well
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Hi, all. I posted this earlier, but it was a bit off topic in that thread.
Can anyone help me?
The question i have is, how does the conversion between a signed and an unsigned integer take place when the value is "out of bounds" ?
Eg.:
byte b = 200;
sbyte sb = (sbyte) b;
Console.WriteLine(sb);
I remember something from java and some c++ books about the "remainder" gets added starting from the minvalue. The sample would print -55 . UPDATE: i verified this with someone who knows this stuff. So howcome did they change a general intrepetation in .Net? Guess it has all todo with managed code and being CLS Compliant.
Is that correct? I cant seem to find any mention to this in MSDN.
I did find something about an OverflowException, but in my case, i pass the variable to an extern method (which seems to work as the same as my logic as explained above), or sending it as a MSG param via SendMessage.
Cheers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
You might want to think about doing something like this:
Byte b = 200;
if(b < (int)SByte.MaxValue)
{
SByte sb = (SByte)b;
Console.WriteLine(sb);
}
else
{
Console.WriteLine("b is too large.");
}
Essentially you get caught in what I like to think of as a loop, but it isn't. When you go beyond the max (i.e. - MaxValue + 1; ) it will then wrap to the largest negative value. The -55 is correct, it is out of bounds and that's what it is trying to show you. I know you can do checked{...} and unchecked{...} blocks with certain data types which will allow you to control whether or not an exception is thrown, you may or may not be able to use this here.
HTH
Nick Parker
|
|
|
|
|
|
Section 6.2.1 of the C# spec covers this. Basically, the high bits are thrown away, and then the result is sign-extended to get the resultant value. I don't think you'd ever want to depend on this behavior, however.
You can trap such overflow by putting the code in a checked block:
checked
{
byte b = 200;
sbyte sb = (sbyte) b;
System.Console.WriteLine(sb);
}
|
|
|
|
|
|
Does anyone know where I can find a good, accurate algorithm for converting between the RGB and HLS colour models?
I'm writing in C#, but I could probably convert an algorithm from most languages.
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
Hi,
In the Color class it provides you with methods to convert RGB to HSB (does brightness = lumination ) .
GetHue(): Gets the hue-saturation-brightness (HSB) hue value, in degrees, for this Color structure.
GetSaturation(): Gets the hue-saturation-brightness (HSB) saturation value for this Color structure.
GetBrightness(): Gets the hue-saturation-brightness (HSB) brightness value for this Color structure.
The other way around, i cant help you with, well not yet
HTH
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
OK i found 2 variations:
From Anakrino:
public float GetBrightness() {
float local0;
float local1;
float local2;
float local3;
float local4;
local0 = (float) this.R / 255;
local1 = (float) this.G / 255;
local2 = (float) this.B / 255;
local3 = local0;
local4 = local0;
if (local1 > local3)
local3 = local1;
if (local2 > local3)
local3 = local2;
if (local1 < local4)
local4 = local1;
if (local2 < local4)
local4 = local2;
return local3 + local4 / 2;
}
public float GetHue() {
float local0;
float local1;
float local2;
float local3;
float local4;
float local5;
float local6;
if (this.R == this.G && this.G == this.B)
return 0;
local0 = (float) this.R / 255;
local1 = (float) this.G / 255;
local2 = (float) this.B / 255;
local6 = 0;
local3 = local0;
local4 = local0;
if (local1 > local3)
local3 = local1;
if (local2 > local3)
local3 = local2;
if (local1 < local4)
local4 = local1;
if (local2 < local4)
local4 = local2;
local5 = local3 - local4;
if (local0 == local3)
local6 = local1 - local2 / local5;
else {
if (local1 == local3)
local6 = 2 + local2 - local0 / local5;
else if (local2 == local3)
local6 = 4 + local0 - local1 / local5;
}
local6 = local6 * 60;
if (local6 < 0)
local6 += 360;
return local6;
}
public float GetSaturation() {
float local0;
float local1;
float local2;
float local3;
float local4;
float local5;
float local6;
local0 = (float) this.R / 255;
local1 = (float) this.G / 255;
local2 = (float) this.B / 255;
local6 = 0;
local3 = local0;
local4 = local0;
if (local1 > local3)
local3 = local1;
if (local2 > local3)
local3 = local2;
if (local1 < local4)
local4 = local1;
if (local2 < local4)
local4 = local2;
if (local3 != local4) {
local5 = local3 + local4 / 2;
if ((double) local5 <= 0.5)
local6 = local3 - local4 / local3 + local4;
else
local6 = local3 - local4 / 2 - local3 - local4;
}
return local6;
}
And from the MONO classes (very nice reference indeed ):
public float GetBrightness (){
return ((float)(r + g + b))/(255*3);
}
public float GetSaturation (){
return (255 - (((float)(r + g +b))/3)*Math.Min(r,Math.Min(g,b)))/255;
}
public float GetHue (){
float top = ((float)(2*r-g-b))/(2*255);
float bottom = (float)Math.Sqrt(((r-g)*(r-g) + (r-b)*(g-b))/255);
return (float)Math.Acos(top/bottom);
}
HTH
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Thanks for the info. I'll look into and see if it helps.
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
How do I create a C# control that can run in a web-browser on the client side.
I am working on a project where it has been specified that if it can be done in C# it must be.
I don't fancy having to implement all the interfaces myself - it'll be like going back to the old days of OLE - shudder. I am sure there must be a quicker way embedded in .NET - but I just can't find the wood for the trees.
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsIeSourcing.aspx
|
|
|
|
|
|
thanks - I knew I was missing something - so they altered the object tag to do something clever - do you know what versions of IE that works on?
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
Shaun Wilde wrote:
do you know what versions of IE that works on?
I *think* it is version 5.0 and up; of course the .NET runtime still needs to be installed on the client.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
I want to be able to create a range of objects using an Eval statement, but the name is not recognized.
I'm creating a C# program using the .NET framework, and the compilers doesn't know what eval means.
I'm trying to use a DataSet to create a bunch of objects using code similar to:
Eval("TreeNode node" + ds.Tables["tableName"].Rows[i]["field1"].ToString() + " = new TreeNode(\"" + ds.Tables["tableName"].Rows[i]["field2"].ToString() + "\")");
But that's not gonna pass it seems.
How can I achieve the desired affect using C# and the .NET Framework?
I'm currently researching the System.Reflection class to see what my options are there. Any help from the outside world would be a great thing =)
--chajadan
aka charlie
|
|
|
|
|
Type t = Type.GetType("System.Windows.Forms.TreeNode");
object[] param = new object[0];
ConstructorInfo[] ci = t.GetConstructors();
object o = ci[0].Invoke
(BindingFlags.CreateInstance,null,param,null);
Be sure to pass param with expected binding for one of the TreeNode constructor (in your case, that's a String object).
|
|
|
|
|
Somewhere in the back of my head I remember seeing a VB.Net to C# converter project, but I have looked everywhere and cant find it again.
Has anyone heard of this?
Any help will be great.
PS: If I am dreaming, writing something like that cant be too hard, I dont know VB/VB.Net but I find converting code manually between VB.Net and C# quite boring, basically C# in reverse and all those pesky Capped keywords.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
There is no VB to C# converter; the reverse exists but I don't have a current pointer.
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|