|
There is absolutely no need of unsafe code in C#. The only viable reason I've ever seen if for fast pixel-by-pixel changes of images, which is still possible - albeit slow - using purely managed code.
You also need to understand that every class (besides numerical types, structures, and enumerations) in .NET is a reference type, or basically a managed pointer. You do not need to use the dereference operator.
If a first-in, first-out (FIFO) buffer is what you need, use a Queue . Otherwise, search this site - or the Internet - for linked list[^] and you'll find lots of implementations.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Ok thanks, but to get the pointer of an object inside itself how can i do?
That is:
myPointer = this; //doesn't work
|
|
|
|
|
What is myPointer declare as? And why are you storing a reference to this in this itself? And when you say "doesn't work", please be explicit. Is an exception thrown? What exception? What message text? Does it not compile?
I - nor anyone else - can help you if you don't tell us the necessary details. We aren't familiar with your code so you need to tell us exactly what you're doing.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi All,
I'd like to put together a couple of forms in a C# class library, and use them from existing VB6 code. Anybody know of any samples to do this? Any tips? It's been my understanding that .NET classes are basically COM objects, is this correct?
Thanks in Advance for any help
|
|
|
|
|
|
Heath,
Thanks for the tip. This is the info I was looking for.
Aaron
|
|
|
|
|
If I have an app.config file in another project, is there a way to bring that over into another project?
Thanks a lot,
Jim
|
|
|
|
|
Copy and paste from the Solution Explorer or from Windows Explorer itself. There's no automated way to do this short of either writing your own add-in or finding someone else's, if even available.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello all,
I bind combo box with datasource and need to select the the text in the combobox prgramaticly. I tried
tiltle.SelectedText = mytitle;
but it dosnt work with me ... please help
Regards
Hay
|
|
|
|
|
Use ComboBox.SelectedIndex . If you need to find the right item, enumerate through ComboBox.Items .
ComboBox.SelectedText is - if you read the documentation - only the text that is selected in an editable ComboBox , or one with ComboBox.DropDownStyle set to ComboBoxStyle.DropDown or ComboBoxStyle.Simple .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks Heath so much...
I Found the soultion for this problem. if i need to select the text programaticly i did this code.
mycombobox.Selectedindex = mycompobox.FindStringExact(thetext)
becaue the FindStringExact return the string index in the combobox
cboGroup_Insurance.SelectedIndex = cboGroup_Insurance.FindStringExact(Group_Insurance_Plan);
Group_Insurance_Plan variabl contain the text i want to select
Thanks again
Hay
|
|
|
|
|
FindStringExact does the same thing I mentioned, only with a single call. It really just depends on how much control you want over the process of enumerating and getting the right index for an item.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I've created a managed DLL with C++ wrapping unmanaged code. This error gets a bit tricksy. Here we go.
Loading the dll (using a reference) and building causes no errors. Declaring an object from inside that dll causes no errors (such as MyClass mclass; ). DEFINING that variable (mclass = new mclass(); ) causes the program to exit before it has started. That is, I can't step through the program to an offending line, the program exits before any line is executed.
Anyone got any ideas?
DC
|
|
|
|
|
First, are you sure that mclass is actually managed using, currently, the __gc construct? If you're doing this in Whidbey beta, you should use the ref class construct for the class declaration.
Second, are you sure the constructor isn't causing a catasrophic failure? Can you step into the constructor? If the constructor is calling unmanaged code bad code or calls can make it fail as opposed to throwing an exception since the code is, well, unmanaged by the CLR (which is why it's called unmanaged).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Yes, the managed class is actually managed with the __gc construct. Also, the constructor makes no outside function calls, the entirety of it is variable definitions. No, I can't step into the constructor. Setting a breakpoint does absolutely nothing, which makes me think it's something happening before execution.
I'm on XPSP2.
DC
|
|
|
|
|
More details than just the instantiation are needed, then. Are there any static fields you're initializing (meaning that the static constructor is run before the class is instantiated)? What variables are being defined? Keep in mind, also, that if you instantiate any instance fields outside the constructor the compiler will bake those instantiations in the default constructor automatically, although MC++ shouldn't allow for that syntax anyway since C++ doesn't.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
There's nothing static in the class being wrapped. No methods, fields, nothing.
The fields being assigned are either being declared NULL, filled with boolean and integer values, or assigned some enumerated constant. The C# code goes as follows:
using System;
using System.Runtime.InteropServices;
using Class1DLL;
namespace TestingManaged
{
public class Class1
{
[STATHREAD]
static void Main()
{
Class1 newobject = new Class1();
}
}
}
DC
|
|
|
|
|
The code about would instantiate itself and exit immediately. If you built a release configuration break points will not be hit because there is no debugging information generated. The C# code also won't be the problem since I'm betting what you have above is nothing like you're actual code, especially since "STATHREAD" would not compile, since it's STAThread .
The CLR will not crash because of managed code. It's when you introduce unmanaged code there's a potential of crashes if not called right. Even unmanaged structured exceptions are caught, but bad calls (like passing out string instead of just string or [Out] string for an /* [out] */ LPTSTR parameter in unmanaged code) can do it. The Managed C++ code that calls unmanaged code is most likely the problem.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Yeah, the code instaniates itself and exits. With one change (that of a type), that code is verbatim (well, that and the spelling issue you mentioned). The program exits before I can step into anything. I've put random stuff before it (adding to integers, assigning ints to variables), and I can't step into that stuff before the instantiation. The program dies before ANYTHING happens.
It's not that the constructor is calling a bunch of unmanaged code. The constructor is only initializing some variables. There are NO function calls.
DC
|
|
|
|
|
Are you doing this from within a debug build, though? Breakpoints will not fire for release builds. And I hate to ask, but just to be sure, are you debugging the app from within VS.NET or just running the application without debugging, in which case VS.NET will never break.
For runtime breaks - though not recommended unless there's really no other way - use Debugger.Break .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
This is a Debug build running from inside Studio. I can try to debug through either the DLL's project or the executable I'm trying to build, and I get the same error both ways.
DC
|
|
|
|
|
Here's a little test to make sure debugging isn't the problem. Add Console.WriteLine("Before new Class1()"); before you instantiate Class1 , and Console.WriteLine("After new Class1()"); after then run the command from the command line in your project's root followed by bin\debug (be default, unless you changed it). Do you see both lines output to the console?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Neither line outputs to the console.
DC
|
|
|
|
|
Here's something else; if I run the program from the console, the last line of the log output reads:
LOG: Attempting download of new URL file:///C:/Documents and Settings/MyName/Visual Studio Projects/StubCalls/bin/Debug/SwathPrinter.DLL
The DLL is already in that folder.
DC
|
|
|
|
|
I think I've found the problem.
Dependency walker (http://www.dependencywalker.com) showed me four DLLs that were needed for loading. I don't know why the error message earlier couldn't just tell me what the dependencies were. So frustrating. Thanks for the help.
DC
|
|
|
|