|
Try the COM object Access.Application.
You should be able to do it this way.
Eran Aharonovich (eran.aharonovich@gmail.com )
Noviway
|
|
|
|
|
How do I terminate all the threads my program has started when it closes? I've tryed this code:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)<br />
{<br />
if (serverThread != null)<br />
serverThread.Abort();<br />
if (clientThread != null)<br />
clientThread.Abort();<br />
if (receiveRoutineThread != null)<br />
receiveRoutineThread.Abort();<br />
}
However, the form closes and a process with my application's name remains running. Can anyone suggest me other way of doing this?
|
|
|
|
|
Just set the IsBackground[^] property on each thread you create to true and you should be done. When the GUI thread shuts down, .NET forces those threads to abort.
Regards
Senthil
_____________________________
My Blog | My Articles | My Flickr | WinMacro
|
|
|
|
|
Thread.Abort() actually aborts the thread when that operation can be performed.
For example, if the thread calls a time-consuming method, the thread won't be aborted until that method returns.
_____________________________________________
Tozzi is right: Gaia is getting rid of us.
My Blog [ITA] - Developing ScrewTurn Wiki 1.0 Beta3
|
|
|
|
|
Hi All ,
I have some struct and hashtable.
In the hashTable i add objects of this struct.
How can i update the objects of the struct in the hashTable?
Example :
Public struct Struct_1
{
public int a;
public int b;
}
.
.
.
HashTable T;
Struct_1 R
T.add(R.a, R);
Question.... How can i update now the field a or b whan the object is in T ???
Thanks for any help.
|
|
|
|
|
You can do
int originalA = R.a;
Struct_1 newR = T[R.a];
newR.a = 42;
newR.b = 42;
T[originalA] = newR;
However, note that the above code changes the value for the previous key and because the key itself is part of the value, it can be confusing if you depend on key == ((R)T[key]).a .
Regards
Senthil
_____________________________
My Blog | My Articles | My Flickr | WinMacro
|
|
|
|
|
Hi,
I am trying to convert a little delphi source to CSharp. The code reads the names of exported methods out of a native library. In Delphi, it works very fine, but now I need to convert it to CSharp. The most work is already done, but there are two thinks to do left.
1. The variable "Name" should be of type string
2. The variable "virtualAddressOfMappedFile" should be an Int[]
You can find the bookmarks 1. and 2. in the attached source code.
For testing the source, simply create a new Console Application, and replace the code with the following.
Thanks,
Thomas van Veen (specialwork)
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
pInvoke.LOADED_IMAGE loadedImage = new pInvoke.LOADED_IMAGE();
try
{
if (pInvoke.MapAndLoad("advapi32.dll", null, ref loadedImage, true, true))
{
int dirSize = 0;
IntPtr pImageExportDirectory = pInvoke.ImageDirectoryEntryToData(loadedImage.MappedAddress, false, pInvoke.IMAGE_DIRECTORY_ENTRY_EXPORT, ref dirSize);
pInvoke.IMAGE_EXPORT_DIRECTORY imageExportDirectory = (pInvoke.IMAGE_EXPORT_DIRECTORY)Marshal.PtrToStructure(pImageExportDirectory, typeof(pInvoke.IMAGE_EXPORT_DIRECTORY));
pInvoke.IMAGE_SECTION_HEADER imageSectionHeader = new pInvoke.IMAGE_SECTION_HEADER();
IntPtr virtualAddressOfMappedFile = pInvoke.ImageRvaToVa(ref loadedImage.FileHeader, loadedImage.MappedAddress, imageExportDirectory.AddressOfNames, ref imageSectionHeader);
for (int i = 0; i < imageExportDirectory.NumberOfNames; i++)
{
IntPtr Name = pInvoke.ImageRvaToVa(ref loadedImage.FileHeader, loadedImage.MappedAddress, virtualAddressOfMappedFile.ToInt32(), ref imageSectionHeader);
Console.WriteLine(Name);
}
pInvoke.UnMapAndLoad(ref loadedImage);
}
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
pInvoke.UnMapAndLoad(ref loadedImage);
}
finally
{
Console.ReadLine();
}
}
}
public class pInvoke
{
public const int IMAGE_SIZEOF_SHORT_NAME = 8;
public const int IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16;
public const ushort IMAGE_DIRECTORY_ENTRY_EXPORT = 0;
[DllImport("Imagehlp.dll")]
public static extern bool MapAndLoad(string ImageName, string DllPath, ref LOADED_IMAGE LoadedImage, bool DotDll, bool ReadOnly);
[DllImport("ImageHlp.dll")]
public static extern bool UnMapAndLoad(ref LOADED_IMAGE LoadedImage);
[DllImport("Dbghelp.dll")]
public static extern IntPtr ImageDirectoryEntryToData(IntPtr Base, bool MappedAsImage, ushort DirectoryEntry, ref int Size);
[DllImport("Dbghelp.dll")]
public static extern IntPtr ImageRvaToVa(ref IMAGE_NT_HEADERS NtHeaders, IntPtr Base, int Rva, ref IMAGE_SECTION_HEADER LastRvaSection);
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct LOADED_IMAGE
{
public string ModuleName;
public IntPtr hFile;
public IntPtr MappedAddress;
public IMAGE_NT_HEADERS FileHeader;
public IMAGE_SECTION_HEADER LastRvaSection;
public int NumberOfSections;
public IMAGE_SECTION_HEADER Sections;
public int Characteristics;
public bool fSystemImage;
public bool fDOSImage;
public LIST_ENTRY Links;
public int SizeOfImage;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct IMAGE_EXPORT_DIRECTORY
{
public int Characteristics;
public int TimeDateStamp;
public short MajorVersion;
public short MinorVersion;
public int Name;
public int Base;
public int NumberOfFunctions;
public int NumberOfNames;
public int AddressOfFunctions;
public int AddressOfNames;
public int AddressOfOrdinals;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct IMAGE_NT_HEADERS
{
public int Signature;
public IMAGE_FILE_HEADER FileHeader;
public IMAGE_OPTIONAL_HEADER OptionalHeader;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct LIST_ENTRY
{
public IntPtr Flink;
public IntPtr Blink;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct IMAGE_SECTION_HEADER
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = IMAGE_SIZEOF_SHORT_NAME)]
public byte[] Name;
public uint PhysicalAddress;
public uint VirtualAddress;
public uint SizeOfRawData;
public uint PointerToRawData;
public uint PointerToRelocations;
public uint PointerToLinenumbers;
public short NumberOfRelocations;
public short NumberOfLinenumbers;
public uint Characteristics;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct IMAGE_FILE_HEADER
{
public ushort Machine;
public ushort NumberOfSections;
public uint TimeDateStamp;
public uint PointerToSymbolTable;
public uint NumberOfSymbols;
public ushort SizeOfOptionalHeader;
public ushort Characteristics;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct IMAGE_OPTIONAL_HEADER
{
public ushort Magic;
public byte MajorLinkerVersion;
public byte MinorLinkerVersion;
public uint SizeOfCode;
public uint SizeOfInitializedData;
public uint SizeOfUninitializedData;
public uint AddressOfEntryPoint;
public uint BaseOfCode;
public uint BaseOfData;
public uint ImageBase;
public uint SectionAlignment;
public uint FileAlignment;
public ushort MajorOperatingSystemVersion;
public ushort MinorOperatingSystemVersion;
public ushort MajorImageVersion;
public ushort MinorImageVersion;
public ushort MajorSubsystemVersion;
public ushort MinorSubsystemVersion;
public uint Win32VersionValue;
public uint SizeOfImage;
public uint SizeOfHeaders;
public uint CheckSum;
public ushort Subsystem;
public ushort DllCharacteristics;
public uint SizeOfStackReserve;
public uint SizeOfStackCommit;
public uint SizeOfHeapReserve;
public uint SizeOfHeapCommit;
public uint LoaderFlags;
public uint NumberOfRvaAndSizes;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = IMAGE_NUMBEROF_DIRECTORY_ENTRIES)]
public IMAGE_DATA_DIRECTORY[] DataDirectory;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct IMAGE_DATA_DIRECTORY
{
public uint VirtualAddress;
public uint Size;
}
}
}
|
|
|
|
|
hi all
i have made an activex by visual c++6 and want to use it in c#
i added the refrence to activex in my app and try to call one of it's methid. ut i got an catastrophic failure . what should i do?
is it enough to compile the activex ? or should i register it ? if so how to register it ?
thank you in advance .
|
|
|
|
|
Without the error message, there isn't anything anyone can do to help you.
Yes, the ActiveX control has to be registered before you can use it. Open a command prompt, change directory to the folder where the control (.OCX) file is residing and type:
REGSVR32 filename.ocx
Then you can add a reference to the COM registered control. Do NOT set a reference to the OCX file directly.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
thank you for your reply .
the error is system.runtime.interopservices.comexception(0x8000ffff)
i set a refrence to the .tlb file , but there is still error.
the activex work in vb6 .
should i do something more than adding the refrence?
|
|
|
|
|
thank you for your reply .
the error is system .runtime.interopservices.comexception(0x8000ffff)
i added the tlb file as a refrence but there still the error.
should i do something more than just adding the refrence??????????
|
|
|
|
|
Don't set the reference to the .TLB file! Set it to the registered copy of the .OCX. Just open the References dialog, click on the COM tab and find your control. Do NOT browse for the file!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
hello,
I'm a visual c++ programmer,
i wanted some information about .net technology and how should i start with it and where to finish it,and how much time does it take,I study almost 8hours a day,
Best regards,
khodadad pakdaman.
|
|
|
|
|
|
It's all up to you my friend in how many hours you grasp a particular topic. If you nee books regarding .Net i can help you on it.By the way i am working on C# if u have any query you may ask i'll give you the answers if they are in my knowledge.Best Of Luck
fahad.ashraf.ali@gmail.com
Fahad
|
|
|
|
|
Hi...
You mentioned that your working on c# and i'm currently strugling on this language. Can you help me?
I'm trying to convert this code from vb to c#:
Private Shared mFormDefInstance As frmBillingAll
Private Shared mInitializingDefInstance As Boolean
Public Shared Property defInstance() As frmBillingAll
Get
If mFormDefInstance Is Nothing OrElse mFormDefInstance.IsDisposed Then
mInitializingDefInstance = True
mFormDefInstance = New frmBillingAll
mInitializingDefInstance = False
End If
defInstance = mFormDefInstance
End Get
Set(ByVal Value As frmBillingAll)
mFormDefInstance = Value
End Set
End Property
Here's my convertion
Private static frmFloatDialog floatDialog = new frmFloatDialog();
Private static bool mInitializingDefInstance;
Public static Property defInstance() As frmBillingAll --> I dont know how to convert this thing...
Get
If mFormDefInstance Is Nothing OrElse mFormDefInstance.IsDisposed Then
mInitializingDefInstance = True
mFormDefInstance = New frmBillingAll
mInitializingDefInstance = False
End If
defInstance = mFormDefInstance
End Get
Set(ByVal Value As frmBillingAll)
mFormDefInstance = Value
End Set
End Property
I could convert some of it but I think I done it wrongly...
Do you have an idea on how to call other MDIchild by another MDIchild?
I tried using formName.show() but its not working.
Please advice...
thankz....
|
|
|
|
|
kh.pakdaman wrote: hi friends!
It would be better to put in a useful subject line. For example: "Need advice for studying C#"
|
|
|
|
|
Guys,
How can I map other web servers in order for me to retrieve files and open it.
Ex. My web page is running on Server1 and the files that I need to open is in Server3 Once I open the page my program will automatically map server3 + directories and display all the files associated with that directory.
I really need answer or idea.
Thanks;
Dabuskol
|
|
|
|
|
Im not sure what you mean by this question?
1: Do you mean that when someone views server1 it actually displays server3.
2: The ability to view and manage the file system on server3 from server1.
1: Easy, simply retrieve the page.
2: This would probably require a web service, or depending on how you plan to get this information, ajax (plain aspx file that takes a querystring of the path).
You simply send the path you want to view and the web service or page will return the directory layout as requested.
|
|
|
|
|
I making an app. to help install lots of programs for a PC i will soon be getting, so i have a few cd's on with the app, and variouse programs, and then things like the adobe photoshop cd.
By using various while, and if statements and System.IO.DriveInfo.GetDrives() etc. i can make sure that the right cd is in a drive, get the drive letter and run the setup application. But this could involve removing the cd with the app on it, wich shouldnt be a problem until the setup program finishes and the computer goes back to the app, which may no longer be there. I'll then probably get some error saying that the cd was removedand that i should put it back, which i dont want.
Anyone got any ideas about this? or an easyer way of finding a drive with a particular label, and getting its letter, at the moment i have about 30 lines of code just to find a drives label and the letter (well, that may be exagerating but...) which i need to use about four times (or more).
|
|
|
|
|
The Undefeated wrote: I making an app.
Unless it is very large the OS will load the whole .EXE into memory and should never need to read the executable file again. However this is not usually how installers work. They normally have a bootstrap .exe that copies the files to the hard drive and then launches the installer executable from there.
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
led mike wrote: Unless it is very large the OS will load the whole .EXE into memory and should never need to read the executable file again.
Actually it's not like that. Every time the program (EXE file) is invoked, Windows maps the disk file to the memory address space of the created process through file-mapping. It never copies the EXE file to the memory. That is why you cannot delete the EXE file when it's running
Best,
Jun
|
|
|
|
|
Well, you could always argue that that's what he meant by "loading" the EXE into memory .
Regards
Senthil
_____________________________
My Blog | My Articles | My Flickr | WinMacro
|
|
|
|
|
Jun Du wrote: Actually it's not like that.
Actually it is like that.
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
int readkey()
{
int n = getch();
while(kbhit()) getch();
return n;
}
int _tmain(int argc, _TCHAR* argv[])
{
int nret;
cout << "Hello Jun Du remove disk or data stick then enter a key." << endl;
nret = readkey();
cout << "Still here Jun Du" << endl;
nret = readkey();
return nret;
}
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
hi
i wrote a database app in vs2005 and i use oledb and mdb file.
i have a table as asami .
in form1.load i fill dataset
and my table have 3 columns and i want when table load to datagridview , values of the columns of the selected row show to textbox seperately.
i wrote this code in currentcell_changed of the datagridview for update textbox with columns of selected row :
private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
{
DataTable dt = ds_Asami1.Tables["Asami"];
DataRow currentrow = dt.Rows[dataGridView1.CurrentCell.RowIndex]; ->error occured in this line when i delete selected row
txt_code.Text = currentrow["id"].ToString();
txt_name.Text = currentrow["name"].ToString();
txt_family.Text = currentrow["family"].ToString();
}
to this section my program was work correctly .. but when i delete a row in runtime by delete button .. vs2005 show me this error :
Object reference not set to an instance of an object.
i used this idea in vs2003 without error but when i use datagridview in vs2005 the above error occured .
how to solve my problem ??
|
|
|
|