|
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
|
|
|
|
|
A .NET assembly on Windows is still a PE/COFF executable like all other executables, even from VB. The entry point in the PE/COFF .exe actually points to _CorExeMain in mscoree.dll, which does a number of things before executing your assembly's entry point in a managed AppDomain. This executable can still have Win32 dependencies that need to be loaded, as can its dependencies.
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]
|
|
|
|
|
That's fine. Fusion is just telling you that it's attempting to "download" (used loosely) the assembly using a list of paths to resolve the assembly according to How the Runtime Locates Assemblies[^].
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
Is it possible to write a program that allows us to cotrol users ability to run applications on the computer and determine which programs the user can run and prevent the user from being able to access the rest of te programs. If that's possible, what are the functions that I can use within C# that'll allow me do do this.
Your help is greatly appreciated.
|
|
|
|
|
That's an IT issue, not really a programming issue. IT Administrators need to use ACLs (Access Control Lists) in Windows NT (on which Win2K, XP, and 2K3 are based, including all newer Windows to be released like "Longhorn") to allow or disallow users or - better yet - groups to run certain applications by removing the Read and Execute permissions (more specifically the Execute permission). To do that is a programming topic that can be solved in numerous ways, from using Process.Start on the cacls.exe console application to using System.DirectoryServices classes with the "WinNT://" scheme, which you can read more about at http://msdn.microsoft.com/library/en-us/adsi/adsi/winnt_adspath.asp[^].
Short of that there's no easy - nor recommended way - of doing what you want.
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]
|
|
|
|
|
when i am connecting to this site,i get
An unhandled exception of type 'System.Net.WebException' occurred in system.dll
Additional information: The underlying connection was closed: The server committed an HTTP protocol violation.
how do i solve this issue
WebResponse objWebResponse =
WebRequest.Create("http://babelfish.altavista.com/tr").GetResponse();
BufferedStream objBufStream = new BufferedStream(objWebResponse.GetResponseStream());
FileStream objFileStream = new FileStream("c:\\webSample.html",FileMode.Create);
byte[] b = new byte[8192];
int iRead = 0;
do
{
iRead = objBufStream.Read(b,0,b.Length);
objFileStream.Write(b,0,b.Length);
}while( iRead > 0);
objBufStream.Close();
objFileStream.Close();
|
|
|
|
|
|
Ok, i did it like everyone does it and extended collection base...and have all the usual functions: add, remove, insert, etc. In all these i trip an action ...like OnItemsAdded, OnItemsRemoved, etc.
Now the problem i see occurs when the control collection is altered through a property grid (doesnt matter if its in vs.net or the property grid on my test form).
In this situation i get no notification through any of my other collection actions...for ex. when you add something with property grid...you would assume that it used your insert function...or indexer "this[ int index ]"...but placing a action tripwire in both locals did not generate any response...and i need these actions to go off so i can determine if my control should refresh when an item is added to the collection.
I did some googling that revealed the possibility of overriding some of collectionbase's actions:
i tried all of them, but OnInsertComplete was the only one that fired when items in the collection were altered or added through a property grid
problem with this approach is it fires to much! i can add an item to the collection, and it will fire for every item in the collection! this results in my control looking like trash everytime a item is changed or added with tons of extra refreshing occuring. A way i could stop this is only allowing it to set off a refresh while in designmode so i don't have to worry about extra refresh calls during the time when my collection is solely modified through actions i implemented...i.e.
<br />
public void Add(string text)<br />
{<br />
List.Add(new SimpleListItem(text));<br />
OnItemsAdded(this, new System.EventArgs(), List.Count - 1);<br />
}<br />
and the rest...but thats alot of performance lost with the OnInsert function calling my collection's action...which then notifies subscribers...and then in my control having to check if its in designmode and needs to be refreshed...everytime an item is added or changed, and for every single item in the collection over and over until this whole process occurs once for each item...thats just wrong!!!
Maybe i can get away with making my own collection that doesn't inherit collectionbase...this way i can control it way better...i wonder if anyones done this already?...that would help alot.
|
|
|
|
|
You're subject and message content have nothing to do with each other. Which is it that you want? Some collections - like the ArrayList - expose a Synchronized method that you can get a thread-safe IList or ICollection (which IList inherits).
For your problem you need to realize that many classes don't use your class but rather the underlying IList or ICollection interface, meaning that your typed methods like int Add(MyObject obj) will not be called. When your class is cast to an IList or any other interface the implementation of those interface methods or properties is used - not yours.
If you inherit from CollectionBase , all you need to do is override the OnEventName methods and do what you need to, like perhaps even firing events if that's what you need, or instrumenting your class. If you look at the implementing of CollectionBase using ildasm.exe from the .NET Framework SDK or .NET Reflector you can search for online, you will see that OnInsertComplete is all that is called for IList.Add and IList.Insert when you use the List property instead of the InnerList property. The documentation for these properties even states that. If you want to fire your own events than use the InnerList property. The List property IS the IList implementation of your CollectionBase derivative, which will invoke those On* methods.
The documentation is rather clear about this, IMO, but you can always use utilities like .NET Reflector to see how these classes work internally.
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]
|
|
|
|
|
Is this the way i'm supposed to handle this
public class Class4 : CollectionBase<br />
{<br />
public void Add(object value)<br />
{<br />
List.Add(value)<br />
}<br />
<br />
protected override void OnInsertComplete(int index, object value)<br />
{<br />
}<br />
}
p.s. renamed thread
|
|
|
|
|
Yes, except if your parameter is simply accepting an object , you might as well use the ArrayList . Of course, it doesn't have event or event handlers, so maybe that's a reason to inherit from CollectionBase , too.
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 need fix UserControl on a desktop window. How I can make it?
Exenten
|
|
|
|
|
You don't make any mention of what UserControl, what it does/doesn't do, what is broken/supposed to do, who wrote it (if not you), and what you mean by "on a desktop window". So all we can tell you is start VIsual Studio .NET and go from there.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|