|
The original file must have a handle to it then - either you are getting this somewhere in your code, or another process is. To find out which, use ProcessExplorer and search for any handles to this file.
|
|
|
|
|
Thanks for your reply. I have fixed the problem. You were right in that my application was itself holding the file handle. Thanks for helping me.
Best Regards
Aseem
|
|
|
|
|
Do you mean Process Explorer is task manager or is it separate window in visual studio editor. If it belongs to visula studio, could you let me know where can I find it. Thanks in advance.
|
|
|
|
|
NarVish wrote: Do you mean Process Explorer is task manager or is it separate window in visual studio editor.
Neither. It's one of the most useful utilities you can download. You can get the latest info here[^].
|
|
|
|
|
|
Hello,
I need to make COM IntetrOp at runtime using reflections. My native COM Object's exposed methods have some parameters as pointers (DWORD*) and some double pointers (DWORD**) and some are user defined types(e.g SomeUDTType objSmeUDTType) and vice versa its pointer(i.e. SomeUDTType *pSomeUDTType).
Now for dynamic method invocation, we have single option for passing parameters as array of object i.e object[] and filling this array statically.
But I need to pass pointers and references and pointers to pointers. For now how can I be able to populate object array as mixed data of simple data types, pointers or references and pointers to pointers.
Working Example:
Native COM exposed method :
STDMETHODIMP MyCallableMethod(DWORD *value_1,BSTR *bstrName,WESContext a_wesContext)
Translated by tlbimp.exe (COMInterop)
UDTINIDLLib.RuntimeCallingClass.MyCallableMethod(ref uint, ref string, UDTINIDLLib.WESContext)
Now calling these methods at runtime using reflection at runtime,
See here :
Assembly asembly = Assembly.LoadFrom("E:\\UDTInIDL\\Debug\\UDTINIDLLib.dll");
Type[] types = asembly.GetTypes();
Type type = null;
//foreach (Type oType in types)
{
try
{
type = asembly.GetType("UDTINIDLLib.RuntimeCallingClass");
}
catch (TypeLoadException e)
{
Console.WriteLine(e.Message);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
object parameters = new object[3];
Type CustomType = asembly.GetType("UDTINIDLLib.WESContext");
object oCustomType = Activator.CreateInstance(CustomType);
FieldInfo fieldInfo = CustomType.GetField("MachineName", BindingFlags.Public | BindingFlags.Instance);
string MachineName = "ss01-cpu-102";
string MachineIp = "127.0.0.1";
string Certificate = "UK/78T";
fieldInfo.SetValue(oCustomType, MachineName);
fieldInfo.SetValue(oCustomType, MachineIp);
fieldInfo.SetValue(oCustomType, Certificate);
object obj = Activator.CreateInstance(type);
MethodInfo mInfo = type.GetMethod("MyCallableMethod");
int lengthOfParams = mInfo.GetParameters().Length;
ParameterInfo [] oParamInfos = mInfo.GetParameters();
object[] a_params = new object[lengthOfParams];
int ValueType = 0;
for(int iCount = 0; iCount<lengthOfParams; iCount++)
{
a_params[iCount] = ???; //Now here this array should be populated with corresponding pointers and other objects (i.e WESContext's obj)
}
mInfo.Invoke(obj, a_params);
Hope code will clarifies ...If any any confusion do let me know I'll edit my question accordingly.
I am stuck here , I'll be obliged if you help me out.(I am confused about "dynamic" keyword might hope it solves the problem)
Regards
Usman
|
|
|
|
|
i found many articles about creating custom files in .net, they explained well.
but in my scenario differ. my application is capturing four types of data simultaneously.
they are x,y coordinates , video , voice and ,pictures and save in relevant formats. now i want to create single file putting these four files in to one ,so i would like to know how can i do this and after creating single file how can i break this in to four formats again.
appreciate your ideas ...
thanx in advance.
|
|
|
|
|
You could combine the files into an archive with a custom extension. That is what a lot of application do, for instance a cab file is an archive many files with the cab extention.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I agree with Mark. Use an archive with a custom extention. This is also what MS have done for the latest office formats (docx, xlsx etc), they are just a collection of xml files in one zip with a custom extension.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
As mark says you could just use an existing container format, e.g. zip and create an archive with your individual files. You could also password protect the file and also change the extension if you need to.
Another option might be to make a custom object with all the data in it, and then serialise and de-serialize the data from disk. your application would then work with the data object as required.
|
|
|
|
|
I would probably go with a ZIP file too, however there are alternatives that may or may not fit your needs:
1.
create your own file format; its complexity would depend on the variability of the data, and to what extend you need access to the different components (especially during file creation).
2.
use a database and blob fields
3.
use "alternate data streams", a little-known feature of modern file systems. This would require P/Invoke to call native Win32 code.
|
|
|
|
|
Zip / cab is one way, as allready suggested. As Luc said, a DB is another.
Have a look at SqlCE databases: They will hold everything you are looking at properly, with all the feature you expect of a DB, but without the need to install any external components - SQLCE is built into .NET. It's memory footprint is also quite small, and it can cope with multiple files pretty well too.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Or can you create an object that holds the data, and then serialize it?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
hii all
I am working on project on Tablet PC
I want to create an Ink stroke from the BezierPoints
I have already record BezierPointsin the database
now i am retrieving the points from database using Dataset and want to recreate the ink stroke using that points
My code lines are as below
SqlDataAdapter da = new SqlDataAdapter("SELECT BPX,BPY from BezierTable", cn);// where BPX, BPY are Drawing Points
DataSet ds = new DataSet();
da.Fill(ds, "BezierTable");
Point[] BezierPoints = Convert.ChangeType(ds, BezierPoints);/// here iam getting error unable to cast dataset Ds to the system to drawing.point BezierPoints
Stroke newStroke = inkOverlay.Ink.CreateStroke(BezierPoints);
now how i can convert the dataset into System to drawingpoint as my CreateStroke method require argument as System.drawing.point
Please help me iam unable to create the stroke from database
with regards
amit
|
|
|
|
|
I see no problem. You want an array? create one using new. You want some data in the array? create a for/foreach loop and have it stuff the data in the array, one point at a time.
|
|
|
|
|
Hello, Is it possible to check at runtime whether given type is Custom data type or one of primitive data types of .NET?
I have defined user defined types in assembly and those all types are some structs. I need to call the methods of user defined types of whome parameters are those structs. So this needs to fill the data accordingly before calling those function at runtime using reflection.
Now Is there any method available in reflection by which we can track that given data type is custom or primitive data type. I know about IsClass attribute, but my targeted user defined data types are not classes , these public are STRUCTS.
Regard
|
|
|
|
|
Perhaps I'm not getting your issue. If you need to call a method on your type then you need to verify it exists before attempting to call it so what does it matter if its an intrinsic .net type or not. Unless you have overridden methods your method won't exist.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
If the other assembly is a .Net dll, why not just add a reference and use the structs.
Anyways, you can try IsValueType property if that helps. I am not 100% sure about what you are trying to do so the answer might not suite your needs.
|
|
|
|
|
Maybe see if it's in the System namespace? Perhaps check to see if it's in a System Assembly? Perchance even access the Attributes of the Assembly to check the creator?
But I don't think it would be 100% accurate.
You could also compare it to a known built-in type; if the type says it's a System.Int32, compare it to the System.Int32 type.
Just guessing, I haven't tried it.
|
|
|
|
|
PIEBALDconsult wrote: Maybe see if it's in the System namespace?
I think a form object in the windows application gives namespace as the application namespace and notSystem.Windows.Forms. So I guess this won't work.
|
|
|
|
|
Riiight... that's kinda what I said. Custom types wouldn't (or shouldn't) be in the System namespace.
|
|
|
|
|
i'm writing a little app that works with MySQL database. my app connects to MySQL server (for now it's a localhost) and works with it. it should do all the basic things like reading, adding, inserting, updating, deleting... i just started learning C#, and having little difficulties with it.
my app is used by 4 people, when one of them adds new data to database i want it to reflect in every client app that's running.
code that adds data to listView:
private void Form1_Load(object sender, EventArgs e)
{
string myConnectionString = "SERVER=localhost;" + "DATABASE=database;" + "UID=root;" + "PASSWORD=123123;";
MySqlConnection conn;
conn = new MySqlConnection();
conn.ConnectionString = myConnectionString;
try
{
conn.Open();
string sql = "SELECT * FROM table";
MySqlCommand cmd = new MySqlCommand(sql, conn);
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
ListViewItem item = new ListViewItem("" + rdr[0]);
item.SubItems.Add("" + rdr[1]);
item.SubItems.Add("" + rdr[2]);
item.SubItems.Add("" + rdr[3]);
item.SubItems.Add("" + rdr[4]);
item.SubItems.Add("" + rdr[5]);
item.SubItems.Add("" + rdr[6]);
item.SubItems.Add("" + rdr[7]);
item.SubItems.Add("" + rdr[8]);
item.SubItems.Add("" + rdr[9]);
item.SubItems.Add("" + rdr[10]);
listView1.Items.Add(item);
}
rdr.Close();
}
catch (MySqlException ex)
so that's what happening when the form loads. probably not the best... guide me here too pls...
and that's how i add new data:
private void addButton_Click(object sender, EventArgs e)
{
string myConnectionString = "SERVER=localhost; DATABASE=database; UID=root; PASSWORD=123123;charset=utf8";
MySqlConnection conn;
conn = new MySqlConnection();
conn.ConnectionString = myConnectionString;
try
{
conn.Open();
string sql = "INSERT INTO table VALUES ('', '" + textBox1.Text + "', '" +textBox2.Text + "', '" + textBox3.Text + "', '0', '0', '0', '0', '0', '0', '0')";
MySqlCommand cmd = new MySqlCommand(sql, conn);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
so how should i let every client app know that the new data was added and update the listView? thanks
|
|
|
|
|
A couple of things to point out first.
string myConnectionString = "SERVER=localhost;" + "DATABASE=database;" + "UID=root;" + "PASSWORD=123123;";
There is no need for the string concatenation here. You can have it one string as you are doing in your button event. You should also have this string defined in one place, say a CONST at the top of your file. That way you avoid issues of changing the string in multiple location and possibly forgetting one.
string sql = "INSERT INTO table VALUES ('', '" + textBox1.Text + "', '" +textBox2.Text + "', '" + textBox3.Text + "', '0', '0', '0', '0', '0', '0', '0')";
Never, ever, ever, accept un-validated user input and place it in your sql command. You are asking for a SQL injection attack. Yes, this app is only a small local instance, but learn to do it correctly.
As for the notification. Since you are using mySql it doesn't have the capabilities that SQL Server has so you will have to poll the database occasionally to check for updates. Or develop a complex method of shared communication between the instances of the app.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
thanks mark for correcting me about connection string, sql injection and all that... i know, i just testing my app... wanna put all the things to work, and then build it all again with everything ready. it's like a prototype app i was thinking to make some kind of "preferences page", where user would be able to set server, database, uid, and password them self, but i can't figure out how to encrypt my settings file so no sensitive information would ever be seen... any ideas?
about "mySql doesn't have the capabilities that SQL Server has" - what you mean? i will have a server and database. i choose MySQL because i worked with it before, but if there are some other BETTER methods of keeping information in database please let me know. so what's SQL server? what do i need? windows server 2010? or linux?
|
|
|
|
|
There is no such thing as Windows Server 2010. Linux? Then you are writing the app in c++ not c#. SQLCE is for small devices, such as handhelds, not for client server apps and has been depreciated. It seems you are just casting about with no thought.
Encrypting and Decrypting Configuration Sections[^]
SqlDependency Class[^]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|