|
Umm, AFAIK, you can do this only using the regsvr32 executable. Thus, you will have to pass it a shell command. What's wrong with that? You can still use C# code to execute the shell command:
Process proc = new Process();
proc.StartInfo.FileName = "regsvr32";
proc.StartInfo.Arguments = "myComDll.dll";
proc.Start();
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Islamic Domination: Coming to a Jewish state near you!
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Thank you for your help
I know that I can still use C# code by using shell commands. But actually I am doing it for someone that asked me to do it using windows API without using the shell commands!
So please if you/anyone have any ideas please send it.
Thank you
|
|
|
|
|
As far as I know, COM dlls are registered on the system using regsvr32. I've never seen an API that registers a COM dll manually. That said, I'm no COM expert.
I mean, dll registration is simply adding the dll to the system and making it known throughout the registry; all things that can be done with the Win32 API of course. In the end though, I see no reason not to simply use the regsvr32 executable; that's what it's there for.
I suppose you might want to try the COM forum instead, as this more pertains to COM than C#.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Islamic Domination: Coming to a Jewish state near you!
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
There is no one API call that does this. You have to open the component file, parse and get the ALL of the GUIDs and names for each object, method, property, ...whatnot.... Then write each GUID and name to the registry in the appropriate locations.
You can try to implement something like this, probably taking you 6 months of work as you figure out the internals of COM and the API's involved. Or, do it the easy way, and shell out to RegSrv32, and have it done in 5 minutes.
Which option do you think would be more cost effective?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi,
I'm sending data from my server app to my client app via TCP socketing...
The data I send is the content of a file, which I know is not larger than 8k.
Thus I fit the entire file content into one pack.
This is my function which handles incomming data, and writes it to the file(Buffer and Pack are classes written by me):
private void myDataArrivalFunction(Buffer bf)
{
while (bf.PacksCount > 0)
{
Pack p = bf.GetNextPack();
string fileName = "blablabla the path to my file";
File.WriteAllBytes(fileName, p.Data);
Application.DoEvents();
try
{
File.Delete(fileName);
}
catch (Exception ex)
{
}
}
}
Once the file has been opened once, File.Delete() fails, saying the file is being used by another process.
I originally used a FileStream object and tried to gain some additional access rights and stuff, but nothing worked.
Even after closing the FileStream object I received the same exception.
Any ideas?
-- modified at 11:16 Monday 15th May, 2006
|
|
|
|
|
Did you close the file after writing to it?
|
|
|
|
|
Yes, I did...
shyagam wrote: Even after closing the FileStream object I received the same exception.
|
|
|
|
|
Could you please post the whole code for the method? The method as it is posted will work fine. My guess is there's something in the "analyze the new file" part that is opening the stream again.
Otherwise, if you're using multiple threads, perhaps another thread is calling this same method or accessing the file somewhere else?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Islamic Domination: Coming to a Jewish state near you!
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Judah Himango wrote: Otherwise, if you're using multiple threads, perhaps another thread is calling this same method or accessing the file somewhere else?
Indeed, I am using multiple threads.
Though the method IS accessed by multiple threads at the same time, every thread has its own fileName...
Thus, there is no chance (I hope I'm not wrong ) that one thread is accessing another's file.
Taking this a bit further, I've got an array of sockets.
All sockets call this method.
The files I'm sending are jpg files...
I have a class with a Bitmap field, and an array of objects of this class.
On "Analyze the new file" part, I have a call to a method located inside this class, which loads the file into the Bitmap object.
I obtain the index of the socket received the data, and use it as the index in the other array, to load the jpg file into the appropriate object.
public void FromFile(string fileName)
{
bmp.FromFile(fileName);
}
Before posting my original message, I've guessed this might be the problem.
So I've attempted the following:
public void FromFile(string fileName)
{
Bitmap tmp = (Bitmap)Bitmap.FromFile(fileName);
bmp = tmp.Clone();
tmp.Dispose();
tmp = null;
GC.Collect();
}
Didn't work either...
Is it possible that loading the jpg file into the Bitmap object causes a lock of the file?
-- modified at 13:30 Monday 15th May, 2006
|
|
|
|
|
I'm not sure if this helps, but:
Open the file using a stream, load the bitmap from the stream and close the stream.
---
b { font-weight: normal; }
|
|
|
|
|
Damn! I can't beleive it!
It worked!
public void FromFile(string FileName)
{
Stream s = new FileStream(FileName, FileMode.Open, FileAccess.Read);
content = (Bitmap)Bitmap.FromStream(s);
s.Close();
s = null;
GC.Collect();
} Simple, yet deadly...
Thanks Guffa.
Shy.
|
|
|
|
|
shyagam wrote:
s.Close();
s = null;
GC.Collect();
This should give you the same results as the above without abusing the GC. Any object implementing IDisposable should be disposed as soon as you're done with it to free resources.
s.Close();
s.Dispose();
|
|
|
|
|
I'll keep that in mind...
Anyway... I've read somewhere that Close() is the same as Dispose().
What's the difference?
|
|
|
|
|
If you're using multiple threads and something weird is going on, assume multiple threads are modifying/reading the same resource (in this case, a file stream). I'd suggest doing some debug work to verify that 2 threads aren't trying to access the same file.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Islamic Domination: Coming to a Jewish state near you!
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I'm somewhat new to threading...
Could you tip me as for how to check stuff like that?
I know there's the "Debug Location" toolbar, which can help...
But is there anything other than that which might be useful?
|
|
|
|
|
|
Thanks a lot you guyz!
Been hacking at it for more than a week!
Almost gave up! (HAHA! No chance of that happening )
Thanks again...
PS
Judah... Would you still give me those tips please?
Shy.
|
|
|
|
|
Hi. I've a NotifyIcon and a ContextMenu with some options. The problem is that I want to press Left Click (primary button) to open the contextMenu.
I resolve that in this way, may be someone have a better idea (it'll be welcome !!
private void notifyIcon_MouseClick(object sender, MouseEventArgs e){
Control ctrl = new Control();
ctrl.CreateControl();
Point pos = Cursor.Position;
pos.Offset(0,-30);
this.contextMenuAplicacion.Show(ctrl, pos,LeftRightAlignment.Left);
}
The problem is if I press the left button over the icon I see the menu, but if I press the button and then I move out and I click in another window for example the internet explorer, the contextmenu is still there and it's like it's there forever, I must select one option of the menu to close it.
Any ideas? Any of you have an example of use left click button to this notify icon to show me a contextmenu??
Thanks a lot people !!
|
|
|
|
|
Why get so hard?
if (e.Button == MouseButtons.Left)
contextMenuStrip1.Show(MousePosition);
as simple as it gets as simple as it needs!
this will show the contextmenustrip on the mouseposition when left button will be clicked.
and if you must incist:
contextMenuStrip1.Show(MousePosition, ToolStripDropDownDirection.Left);
|
|
|
|
|
Thanks NaNg15241, but if you click another window, you'll see that the contextmenu is still there.
Thanks a lot.
|
|
|
|
|
Well, you can solve it in many ways, one of them is implementing the "mouse leave" event in the context menu to hide it or dispose it. something like this:-
private void contextMenuStrip1_MouseLeave(object sender, EventArgs e)
{
contextMenuStrip1.Visible = false;
//or maybe contextMenuStrip1.Close();
//or any other code to hide or dispose the menu
}
This way, the menu will stay hanging on the screen until the user moves his mouse over it and then out of it, then we will know that he noticed the menu, but doesn't want to make a choice now, and the menu will close.
Another way is to se the contextMenuStrip1.Show() method in the MouseUp of the notifyIcon event to check the position of the mouse first, like:
private void notifyIcon1_MouseUp(object sender, EventArgs e)
{
if(e.Button == MouseButtons.Left)
conextMenuStrip1.Show();
}
This way the menu will not show unless the mouse button has been released over the notify icon.
If this doesn't solve it and you still need help, just post.
Programming is like sculpturing, cutting your way through the rock until you see a shape of your work.. It needs patience.
-- modified at 20:14 Monday 15th May, 2006
|
|
|
|
|
Hi Nader, is there a mouseLeave event for the contextMenu? I'cant see it.
Thanks a lot.
|
|
|
|
|
Well, that depends on whether you are using the old ContextMenu control, or the new ContextMenuStrip control which has MouseLeave event.
If you insist on using the older ContextMenu control you may use a timer to check for MousePosition or maybe perform a HitTest, but I strongly suggest the contextMenuStrip control.
I hope I was of some help
|
|
|
|
|
Thanks a lot Nader !!. I update my information . I have now this problem, may be you had see it, when I click (left button event) on the notify button and call the show method like this:
this.contextMenuStripOp.Show(ctrl, Cursor.Position, ToolStripDropDownDirection.Left);
I see in the Task bar a window of the contextMenuStrip. But when I press the right button the window isn't in the Task Bar.
Thanks !!
|
|
|
|
|
I see. That is because you show your contextmenustrip by the "show" method. and by default the "TopMost" property is set to true. This way your context menu will show an icon in the taskbar.
You have to set it to false first then show you menu. unfortunately this may make your menu not to show at all because it's niether a topmost, nor a child to any control. It's a bit of a predicament. I haven't solve it yet, but you try to make the topmost false, and figure a way to show your menu as achild of another control "but notifyicon won't work". I will work on it later on this night. If I get to something I will keep you posted.
|
|
|
|
|