|
Thanks for yor response .
How can i solve this in C#
can you give me a sugestion?
|
|
|
|
|
So you cant write
class A {
ref int m_retParam;
A(ref int param) {
m_retParam=param;
}
public void DoSomething(){
m_retParam = 5;
}
}
but you can write
class A {
public A() {}
public void DoSomething(ref int m_retParam) {
m_retParam = 5;
}
}
or
class A {
public int result;
public A() {}
public void DoSomething() {
result = 5;
}
}
the result now is available as A.result
or
class A {
private int result;
public int Result {get {return result;}}
public A() {}
public void DoSomething() {
result = 5;
}
}
the result now is available as A.Result
or, more in the way you would like it I guess, but with an extra class:
class B {
public int result;
public B() {}
}
class A {
private B m_retObject;
public A(B retObject) {
m_retObject=retObject;
}
public void DoSomething() {
m_retObject.result = 5;
}
}
the result now is available as B.result
(providing a B.Result property probably doesnt make much sense, since
it needs a getter for the caller, and a setter for class A, so it could as
well be public in the first place.
One of the above should suit almost every requirement.
Cheers.
Luc Pattyn
|
|
|
|
|
Thanks for your complete response
I think i will use the last example.
I Wonder why old simple things get so complicated in C# ...
|
|
|
|
|
It's all about safety.
Pointers are considered unsafe:
- if you can modify them (e.g. increment to scan an array), you may get outside
the valid range
- even if you cant, you might point to something that isnt alive anymore
(unless the CLR understands it really is a reference to an object, i.e. something
the CLR knows it is alive, and that is exactly what my class B is all about).
So C# offers you the following way to return results:
- through the return value of a method
- through an out or ref method parameter
- through an event (think of it as a callback function with input arguments)
each of these can be primitive values or aggregates (classes or structs).
Similar things hold true for delegates, which are basically function pointers
associated with a specific object.
Cheers,
Luc Pattyn
|
|
|
|
|
That code isn't possible in C#, you can't use a local field as a reference to an exisiting int, and then change it in some other method.
The ref parameter does allow you to modify the original calling instance, but not the way you want it.
|
|
|
|
|
Thanks for yor response .
How can i solve this in C#
can you give me a sugestion?
|
|
|
|
|
I have a form which contains a tab control, which contains two tab pages.
On each tab page, there is a DataGridView, bound to it's own DataTable.
In the RowsAdded event handler for both DGVs, when the first row is added, I resize the columns to fit the data. My handler looks something like this:
private void dgvAllEvents_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)<br />
{<br />
...<br />
dgvAllEvents.AutoResizeColumn(0, DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader);<br />
}<br />
<br />
This code works fine for the datagridview that is visible - that is, on the selected tab. However, the column does not get resized on whichever dgv is NOT visible - the tab page that is not selected.
The event is getting fired, I have confirmed that. But the column is not resized when the AutoResizeColumn method is called.
Is there an optimization here that prevents resize from being executed if the column is not visible?
Thanks for any insight you have here.
|
|
|
|
|
I have a bitmap file which I can load into a Bitmap object (or not if i don't have to), but I also have a number of smaller bitmap objects whose images should be sections of the larger image. The co-ordinates (top left, bottom right) of the sections I would like to take are known. I can do this by looping through every pixel needed, using the getPixel method on the larger bitmap, then the setPixel method on the smaller bitmap, however this seems a little bodged, and is probably a bit slow. Is there a better way to do this?
Thanks for any help.
|
|
|
|
|
Still a bit new to the programming, but it looks like the Bitmap.Clone Method is what you might be looking for?
<code>
Bitmap bmpOriginal, bmpSection;
bmpOriginal = new Bitmap("C:\\Test.bmp");
bmpSection = bmpOriginal.Clone(new Rectangle(0, 0, 100, 100), bmpOriginal.PixelFormat);
</code>
-- modified at 16:12 Saturday 6th January, 2007
|
|
|
|
|
you can do the following:
Bitmap newBitmap=new Bitmap(of the right size);
Graphics g=Graphics.FromImage(newBitmap);
and now you can draw anything you like into g, including (part of) an existing image.
Luc Pattyn
|
|
|
|
|
wondering if anyone has some C# code that can verify if SQL is ANSI complaint or not.
tj
|
|
|
|
|
Why does it need to be C# ?
What DB are you using ? Perhaps it has a full ANSI only mode ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
I have an unmanaged C++ class, and a managed c++ wrapper for the class. I then access the managed c++ from c# client. The whole thing compiles fine, but when I run the c# client, it crashes as soon as it hits the line where the managed c++ object is initialized. Here is the code that I am working with:
#include <windows.h>
#include <vcclr.h>
#using <System.dll>
using namespace System;
class UnManagedClass
{
public:
LPCWSTR GetPropertyA() { return 0; }
void MethodB ( LPCWSTR ) {}
};
public ref class AdapterNET
{
private:
UnManagedClass * m_unman;
public:
AdapterNET() : m_unman( new UnManagedClass ) {}
~AdapterNET() { delete m_unman; }
protected:
!AdapterNET() { delete m_unman; }
public:
property String ^ get_PropertyA
{
String ^ get()
{
return gcnew String( m_unman->GetPropertyA() );
}
}
void MethodB( String ^ aString )
{
pin_ptr<const WCHAR> str = PtrToStringChars( aString );
m_unman->MethodB( str );
}
};
using System;
using System.Collections.Generic;
using System.Text;
namespace TestingAdapterNET
{
class AdapterNETDriver
{
static void Main( string[] args )
{
AdapterNET _adapterNET = new AdapterNET();
string propA = _adapterNET.get_PropertyA;
_adapterNET.MethodB( propA );
}
}
}
Any ideas?
Thanks,
-----------------
Genaro
|
|
|
|
|
Hi
1) what is "crashes here", what are the symptoms ? any error message, message box, ... ?
2) try putting your managed code inside a try-catch construct, and when you catch
an exception entirely display it. (hint: the Exception.ToString() method gives it all).
3) BTW, how is your C# code to find adapterNET, arent you missing a using statement ?
Luc Pattyn
|
|
|
|
|
Hi and thanks for the response.
1) Crashes here means that I get the following:
No symbols are loaded for any call stack frame. The source code cannot be displayed.
with exception:
{"The specified module could not be found. (Exception from HRESULT: 0x8007007E)":null}
2) I added the try/catch, but it never hits it
3) I included a reference to the dll, and it seems to find the class (since intellisense is available). I have wrapped the c++ code with a namespace and am now '#using' it, just in case.
Any more ideas?
Thanks,
-----------------
Genaro
|
|
|
|
|
Hi,
HRESULT ending on 007E means good old ERROR_MOD_NOT_FOUND, so module not found,
meaning a needed dll file is not found at run-time
If I understand correctly you are using three modules:
1. your main program (C#), being an EXE file
2. your managed C++ adapter class in a DLL
3. your unmanaged C++ whatever, in another DLL
unfortunately it is not clear which module is not found.
I guess (and hope) you have 1. and 2. as two projects within a single solution
in Visual Studio, so it should be perfectly possible to single-step as long as
you do not access anything in 3.
to make sure the managed C++ works, add another class to it, something
that does not need 3. (e.g. a simple function that returns the sum of two integers)
and try using that first;
if that succeeds, continue with the adapter itself.
Luc Pattyn
|
|
|
|
|
I actually have 2 and 3 combined... both managed and unmanaged c++ in the same dll.
I added another managed class to the dll, which just returns the sum of two numbers and does not access any managed code, but I get the same error.
Thanks,
-----------------
Genaro
|
|
|
|
|
Gee, I was not even aware you could do that... But then, I dont use C++, I use
either C#, or C# + unmanaged C with PInvoke.
Maybe the presence of unmanaged code prevents you from calling the managed half of
that mixed dll ??
Luc Pattyn
|
|
|
|
|
Hi Picazo,
Actually, come to think of it; I can not believe you can do that at all.
Please feel free to e-mail me a zip with your solution and stuff, or at least
such combined dll. I would like to look inside it !
Regards
Luc Pattyn
|
|
|
|
|
Hey Luc,
http://sqlite.phxsoftware.com/[^]
These guys to the same, they have combined the original Sqlite3.dll (c only) with a managed C# wrapper.
Supports the Full and Compact .NET Framework as well as native C/C++
The library is 100% binary compatible with the original sqlite3.dll and has no linker dependencies on the .NET runtime for full unmanaged C/C++ development.
And you can get the source
|
|
|
|
|
Thanks a lot, Steve. I will look into that some day.
Seems like picazo should have a look too into that source code...
Luc Pattyn
|
|
|
|
|
Best guess - you have a problem loading the library, because of WinSxS issues. Do you have more than one PC ? My notebook died recently, to the point that a vanilla dll and vanilla C# app would blow up in this circumstance. My own code runs fine on my desktop still.
At the same time, are you sure that all the dlls your code relies on are in the directory of the exe ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi All
the problem is this that i m filling the treeview from the XML File when the form load event occurs the treeview starts making its nodes and child nodes . when I add a node to the XML file it is added but the tree doesnt show it again restarting the application displays the node newly added. I tried the refresh method but I think the problem is this that xmltextreader is forward reader of xml file when the new node is added the cursor is not there which avoids the treenode to make itself updated how to get rid of this problem
SAS
|
|
|
|
|
You have to refresh you TreeView manually by reloading the Xml file. One way to check if the Xml file has been modified is to get the hash code of file, last modified attribute, or store the size in bytes in a long. Then make a timer to check if the values has changed let's say every minute. If there are changes clear all the nodes and reload them again like you did in the load event.
Regards
|
|
|
|
|
Nader Elshehabi wrote: One way to check if the Xml file has been modified is to get the hash code of file, last modified attribute, or store the size in bytes in a long. Then make a timer to check if the values has changed let's say every minute.
Or simply use a FileSystemWatcher component and handle the Changed event
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|