|
Nick Parker wrote:
Chris Morrison wrote:
However, when I try to add the CommandBar, a COMException is thrown with the
message "Class not registered. Looking for object with CLID {.........}".
It sounds as if the CLSID is not being found in the regisry, thus it is not able to load the COM Server because it doesn't know it's location. Are you using a third-party component that hasn't been registered? If so, pull up a command prompt, navigate to the directory of your COM .dll and type the following:
regsvr32 "[YourComponent.dll]"
That did not work and caused an error.
I would have thought that any registrations that were required would be performed when I build and debug the Add-In. Also I have added a floating toolbar to the IDE with no problems, and I can add new items directly to the Edit menu with out error, so I can't see why I am having problems adding a sub menu to it.
This is very strange.
Chris
|
|
|
|
|
Try running regasm.exe on your .NET assembly. It is equivalent to regsvr32.exe but is for managed assemblies. Since such assemblies do not export DllRegisterServer or DllUnregisterServer , regsvr32.exe is useless.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
Since such assemblies do not export DllRegisterServer or DllUnregisterServer, regsvr32.exe is useless.
I would have suggested that but since it was throwing a COMException I figured it was due to a problem on the other side of the fence.
Oh well, it's the weekend after all.
-Nick Parker
VB gets under people's skin because one can be ignorant of computer architecture and ASM and still
get a lot done. -Don Box
|
|
|
|
|
VS.NET uses the DTE components via COM (even if written in managed code), so if it can't find the registered class (either because it wasn't registered correctly or because he moved the DLL after registering it) it would throw such a COMException .
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi:
I am doing a project ,in which I must use journal-hook
But all the help fille and example-code I saw is about
local-hook,what should I do in C# .
thanks
|
|
|
|
|
Continueing this repost trend wont give you an answer. Wtf is journal hooks anyways? How is it done in C++?
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
In C#.NET I wrapped WOpenEnum, WCloseEnum and WEnumResource so that I may go through the network domains, servers, and shares much like one would with the Directories class... (Directories.GetDirectories(string path)... you know...)... anyway to the problem:
In the Console (my dev environment) runs like a champ... no errors, the amount of memory used or threads opened doesn't change... really stable... I incorporate this set of files in a Forms environment though and errors start occuring randomly, more often when I'm querying faster... errors such as infinite recursion, null referance is mscrolib...etc... I really want to say it has something to do with GC, but I'm not an expert... but because the console is garbageless (I think) and Forms are constantly getting rid of things the GC doesn't think you need I'm looking that way... I don't know though. I've tried the KeepAlive method and other things but the problem still comes. I'm really not much on low level wrappers, but like I said, in the Console window it's running great... and I peiced this thing together best I can but am open to suggestions and learning experiance. I just can't get it to work worth a darn otherwise outside the console and it's frustrating the heck out of me. If you can help please email me and I'll send you the code... I don't care if it's public or not... a lot of people I'm sure could use something that would help them get network resources easier... I'm just not sure how to post a file if you even can... I'm new here.
Thanks,
Brian J.
If you ever meet somebody who says they know it all, they are obviously ignorant and probably write terrible code.
|
|
|
|
|
One word: Paragraphs!
I think (without reading your post) the problem is, that you cant write to the Console form another thread.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
I'm with leppie on this one - use paragraphs next time. It's very difficult to follow your problem.
Since I can't really distinguish what you're problem is, let me give you a lesson or two on the .NET Framework. The GC only collects objects to which no references exist. If something is referencing an object in memory, it will NOT be GC'd. As far as your wrapper class for the Network API, all the methods you P/Invoked are static, which means they are methods of the Type - not an instance - so it can't be GC'd. If you get back a handle from one of those methods and aren't storing it (hence, not making a reference to it in your instance), then it will be GC'd.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I'll try to clarify...
I made a set of classes that make interface with the WOpenEnum, WCloseEnum, and WEnumResources API functions simpiler. In that set of classes I also have a public class called Network that has static methods for retrieving the domains, servers, or shared folders in a network using the three API above (GetDomains(), GetServers(string domain), GetSharedFolders(string server). This set of classes also has three public structs (Domain, Server, SharedFolder) that I use for returning the information gathered in the three functions above. If you've worked with those three API before you know there are 8 items of information that come back, but only two that are important to the user, the 'Remote Name' and the 'Comment', this is what I put in those structs.
Now in a seperate project I make a reference to those set of class (which I just call EnumNetwork.dll)... With just a simple console project I can put it in a loop (normally wouldn't do this, nor use goto) as the following:
Start:
Server [] myServers = Network.GetServers("myDomain");
foreach(Server s in myServers)
{
Console.WriteLine(s.Name); //write the name of the server
}
goto Start:
And with this the servers will scroll out the console window forever without a glitch.
Now in a Windows Form I have a ListView object to make things look what users are use too... assume I already have a computer icon set for the second parameter of Item.Add below (the 0):
Server [] myServers = Network.GetServers("myDomain");
this.lstView.BeginUpdate();
this.lstView.Items.Clear();
foreach(Server s in myServers)
{
this.lstView.Items.Add(s.Name, 0);
}
this.lstView.EndUpdate();
What happens with this is that occasionally when closing the window itself you get 'Null Reference in mscrolib', or 'object not set to a reference of an object in unknown module'... and if running this code more that once in a 10 second period, or if there are many servers you get 'Infinite Recursion' and and 'Unhandled exception in sscrolib'...
Now I don't know what you mean by paragraphs unless you were saying I need to type better... in which case sorry for that... otherwise I'm ignorant to the meaning... but what I'm getting at is calling that method in the console window constantly results in no errors... over hours (yes I tested it for that long)... yet calling it in a method on a form results in unpredicatable errors... and try...catch statements don't do anything because the errors are caused in the Application.Run line... like I said, if you need the source code... not a problem... I'll email... thanks for any help, and thanks for the good info on the GC...
Brian
If you ever meet somebody who says they know it all, they are obviously ignorant and probably write terrible code.
|
|
|
|
|
Structs are not reference types - they are values types. If you think that different classes have reference to the same struct, you'd be wrong. They each have a separate copy of the struct because it is, once again, a value type.
This might have something to do with the ListView you're using, too. Since the ListViewItem is representing something that is getting destroyed by the GC (once structs are out of scope and the GC has a slice of time it cleans them out - including the values in the struct). Instead, when adding the s.Name to the list, use s.Name.Clone().ToString() . A copy of the string will be used instead of the string itself - which will get destroyed by the GC and a string is a reference type. This might be your problem.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks again for you response...
Clone(), CopyTo(), and Copy() all tried and all have the same problem... I would be glad to send you the source code if you think you'd have time to look over it. As I've said I'm not the most experienced... everyday I'm learning, so if you want to tear my code apart and tell me I'm an idoit... I'm fine with that ... otherwise any other ideas would be more than welcome.
Brian
If you ever meet somebody who says they know it all, they are obviously ignorant and probably write terrible code.
|
|
|
|
|
You didn't mention that you were getting a NullReferenceException when using the field - only when you closed the application. The solution to this is simple - and is necessary in any good application - error handling! If you're not sure about input (and never trust user input for that matter!), always check to see if something is null (only reference types can be null, so a string can be). Instead, change your loop to something like:
foreach (Server s in servers)
{
if (s != null && s.Name != null)
this.listView.Items.Add(s.Name);
} Likewise, you should always include exception handling in your code - especially when you can trust a source or that an object you didn't instantiate (like a parameter) isn't null. Always check your inputs, never trust user input (validate!), and always make sure that errors / exceptions are handled gracefully and - if possible - recovered. This is key in every programming language / framework.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Actually I do have that check in my code already:
if(myServers!=null)
{
foreach(Server s in myServers)
{
if(s.Name!=null)
{
this.lstViewNetwork.Items.Add(s.Name.Clone().ToString(), 0);
}
}
}
This is the most common error and the one you mentioned:
An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll Additional information: Object reference not set to an instance of an object.
When hitting break it goes to assembly... not a line of code as you normally get with null reference... when it does have the mscrolib error it get the green arrow break (don't know what the differance between that and the yellow is) but that is in the '}' underneath application.run(form)
Like I said, I'll send you the code if you have the time to look it.
Thanks again
Brian
If you ever meet somebody who says they know it all, they are obviously ignorant and probably write terrible code.
|
|
|
|
|
Here is the code for the struct I use in the example:
<br />
public struct Server<br />
{<br />
private string n, c;<br />
public string Name<br />
{<br />
get { return n; }<br />
set { n = value; }<br />
}<br />
public string Comment<br />
{<br />
get { return c; }<br />
set { c = value; }<br />
}<br />
public Server(string name, string comment)<br />
{<br />
n = name;<br />
c = comment;<br />
}<br />
}<br />
Here is the code for the GetServers function, this function is part of the public class Network(), the dotNet_OpenEnum, dotNet_CloseEnum, and dotNet_EnumResources are static functions in a wrapper class for each of the API network functions... I did this versus calling the external function directly, the Flags class is simply const int's for various flags used when using the API network functions:
<br />
public static Server[] GetServers(string domainName)<br />
{<br />
int ret;<br />
IntPtr ptrBuffer;<br />
IntPtr ptrHandle = new IntPtr();<br />
int BufferSize = short.MaxValue;<br />
int NumberRequested = -1;<br />
NETRESOURCE objNR = new NETRESOURCE();<br />
objNR.lpRemoteName = domainName;<br />
object obj = (object) objNR;<br />
if(obj==null)<br />
{<br />
return null;<br />
}<br />
ret = dotNet_WNetOpenEnum.Execute(Flags.RESOURCE_GLOBALNET, Flags.RESOURCETYPE_ANY, Flags.RESOURCEUSAGE_ALL, obj, out ptrHandle);<br />
if(ret!=0)<br />
{<br />
if(ptrHandle!=IntPtr.Zero)
{<br />
ret = dotNet_WNetCloseEnum.Execute(ptrHandle);<br />
}<br />
return null;<br />
}<br />
ret = 234;<br />
ptrBuffer = Marshal.AllocHGlobal(0);<br />
while(ret==234 || ret==487)
{<br />
NumberRequested=-1;<br />
ret = dotNet_WNetEnumResource.Execute(ptrHandle, ref NumberRequested, ptrBuffer, ref BufferSize);<br />
if(ret!=0)<br />
{<br />
Marshal.FreeHGlobal(ptrBuffer);<br />
BufferSize*=2;
ptrBuffer = Marshal.AllocHGlobal(BufferSize);<br />
}<br />
}<br />
if((ret!=0) || (NumberRequested < 1))<br />
{<br />
if(ptrBuffer!=IntPtr.Zero)<br />
Marshal.FreeHGlobal(ptrBuffer);
if(ptrHandle!=IntPtr.Zero)
{<br />
ret = dotNet_WNetCloseEnum.Execute(ptrHandle);<br />
}<br />
return null;<br />
} <br />
Server [] servers = new Server[NumberRequested];<br />
int PtrMovement;<br />
NETRESOURCE nr;<br />
PtrMovement = ptrBuffer.ToInt32();<br />
for(int n=0;n<NumberRequested;n++)<br />
{ <br />
nr = (NETRESOURCE) Marshal.PtrToStructure(new IntPtr(PtrMovement), typeof(NETRESOURCE));<br />
servers[n] = new Server(nr.lpRemoteName, nr.lpComment);<br />
PtrMovement += Marshal.SizeOf(typeof(NETRESOURCE));<br />
}<br />
Marshal.FreeHGlobal(ptrBuffer);
ret = dotNet_WNetCloseEnum.Execute(ptrHandle);<br />
return servers;<br />
}<br />
Thanks for any help!
If you ever meet somebody who says they know it all, they are obviously ignorant and probably write terrible code.
|
|
|
|
|
Heath -
So I took out all of the additions we made and put it back to square one and at the bottom of the function I added GC.Collect():
<br />
string domain="Domain1";<br />
this.lstViewNetwork.Items.Clear();<br />
Server [] myServers;<br />
myServers = Network.GetServers(domain);<br />
this.lstViewNetwork.BeginUpdate();<br />
if(myServers!=null)<br />
{<br />
foreach(Server s in myServers)<br />
{<br />
if(s.Name!=null)<br />
{<br />
this.lstViewNetwork.Items.Add(s.Name, 0);<br />
}<br />
}<br />
}<br />
count++;<br />
this.lstViewNetwork.EndUpdate();<br />
this.lblRefresh.Text = count.ToString();<br />
GC.Collect();<br />
}<br />
Now I know longer get errors, and everything is working perfectly (... some weird things still happen, when the screen saver started the form became the screen saver... weird... and once I got an error on closing the form, but after several attempts to get it to happen I haven't been able to, and something similiar when losing and regain focus to the form, it can now go throughs several thousand iterations before either of these errors happen whereas before we couldn't go more than 150. I'm not sure why GC.Collect() has made the error go away, but I know a 'fix to the problem' and 'fixing the problem' are two seperate worlds, and I was hoping maybe with this information and the other information I've given since your last reply will set some bells off in your head... any ideas?
Thanks again for all your help with this.
Brian
If you ever meet somebody who says they know it all, they are obviously ignorant and probably write terrible code.
|
|
|
|
|
Are you executing this method in a separate thread? If so, you must make all UI updates on the main UI thread. See Control.InvokeRequired and Control.Invoke for more information. Basically, you invoke your method (using a delegate with a matching signature to this.lstViewNetwork.Items.Add(s.Name, 0) and call Control.Invoke on that. This can cause similar problems to what you're seeing if you do add items on a separate thread. This is just the way Windows works (and most other window managers that I'm familiar with).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath,
Thanks again for all your help, I solved it. I am flawless now... it wasn't what we were expecting... it was something really stupid - something we looked over. I was over-allocating memory in my function - apparently when you send to much memory to WNetEnumResources it fills the rest of the memory with items, then when calling it again your not getting the new memory, but the remainder of the old, and the new memory for the new objects is pushed up the stack - I know that's a terrible explination but it appears that is what was happening. Now that I'm allocating it correctly I have no problems whatsoever in any context... console or form and I have reloaded my ListView control every second for over an hour with simple .Add(s.Name) and not so much as a flicker.
I wanted to thank you once again for you help along the way. I learned a lot on this one... if you ever want a copy, please email me.
Brian
If you ever meet somebody who says they know it all, they are obviously ignorant and probably write terrible code.
|
|
|
|
|
We have an issue with using the IE ActiveX control where about 1 in 20 users are expriencing total system lockup when our application loads.
The application is being deployed with the following files:
AxInterop.SHDocVw.dll
Interop.SHDocVw.dll
partial.mshtml.dll
The partial.mshtml.dll file comes from SharpReader[^], and by all accounts fixed their deployment problems, which are similar to our own.
I have extensive trace output in the app, and can verify that the point of lockup is when the web browser control is instantiated. Please note that I am navigating to about:blank in the constructor to ensure the control has a handle.
Has anyone else ran into similar problems deploying a C# app with the IE control? if so, any ideas?
|
|
|
|
|
I doubt this would cause a lockup, but what versions of Internet Explorer are the 1 in 20 users using? If the partial.mshtml.dll was created with a newer version that those few users don't have, and you're trying to use those newer interfaces that don't exist in the MSHTML DOM, this would most likely cause a problem. Your installer should make sure they have the proper version (or higher) of IE.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I am working closely with one affected user on the issue.
He is using Win98SE, with IE 6 SP1. I have added a bunch of trace output to the app, and the total system lockup is happening right after the ActiveX is instantiated, when the control would be receiving a handle I guess.
I've tried compiling the app for both 1.0 and 1.1 framework versions, and I've referenced & distributed the entire Microsoft.mshtml.dll assembly.
As for the control itself, I am only calling the Navigate method, and catching the OnNavigateComplete2 event - nothing else.
Note that I have 26 other people using the app with Win98 + IE 5-6 without problem, but this one fellow is experiencing lockups on both of his Win98 SE systems. Outside of him, who knows how many people have dismissed the app as inoperable and simply not advised me!
|
|
|
|
|
Man, I don't know. How much memory does this person have in his machines? I mean, the .NET Framework would throw an exception and exhausting the memory wouldn't lock up the system, but it might appear that way. I doubt this is the problem, though.
Have you checked the MS KB? Besides that, all I can think to tell you is to post a message to an appropriate MS newsgroup (msnews.microsoft.com), but I doubt that'll help since replies to more advanced or "odd" problems like this almost never get answered.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
How much memory does this person have in his machines?
One has 64MB, the other 128MB, however my low-end test machine (that runs the app fine) has just 56MB usable RAM (8 MB is taken up by the video card).
Heath Stewart wrote:
Have you checked the MS KB?
Yes. The only possibly related article I could find was a COM import bug in fx 1.0 that was fixed in 1.0 SP1. However, compiling the app for fx 1.1 should have worked around this issue if it was the problem.
Heath Stewart wrote:
Besides that, all I can think to tell you is to post a message to an appropriate MS newsgroup
Have now posted the problem to microsoft.public.dotnet.framework, but as you noted and I've personally experienced, difficult questions seem to get lost in the ether...
Thanks for your help anyway Heath
|
|
|
|
|
Hey
I´m trying to make a File Explore like windows explore. I get the Logical drives GetLogicalDrives and then iterate through them. At this point I´m using GetDirectories.
My problem is that I want to show all the drives, also if there is no media like a cdrom or floppy. But using GetDirectories on a:\ with no floppy inserted throws an exception I can't catch.
Please help I want to avoid this.
|
|
|
|
|
naxos wrote:
But using GetDirectories on a:\ with no floppy inserted throws an exception I can't catch.
I somehow doubt this.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|