|
there are interfaces declared in a dll below
-------------------- Encrypt.dll -------------------------
interface IDESCoder
{
string CreateCode(string IVString,string KeyString,string StringToEncode);
string GetCode(string IVString, string KeyString, string StringToDecode);
}
interface IMD5Encoder
{
string CreateCode(string StringToEncode);
}
public class ClsDES : IDESCoder
{
public string CreateCode(string IVString, string KeyString, string StringToEncode)
{
}
public string GetCode(string IVString, string KeyString, string StringToDecode)
{
}
private Boolean CheckIVKey(string IVString, string KeyString, string StringToEncode)
{
}
}
public class CldMD5 : IMD5Encoder
{
public string CreateCode(string StringToEncode)
{
}
}
-----------------------------------------------------------------------
and there is a Host
-------------------- test.exe ----------------------------------------
string filepath = @"E:\Encrypt.dll";
Assembly myDllAssembly = Assembly.LoadFrom(filepath);
Type dllType = myDllAssembly.GetType("IDESCoder");
if (dllType!=null)
{
......??????
}
-------------------------------------------------------------------------
then,what should i do next with Reflection if i want to use Interface declared in the dll??
|
|
|
|
|
string filepath = @"E:\Encrypt.dll";
Assembly myDllAssembly = Assembly.LoadFrom(filepath);
Type dllTypeInterface = myDllAssembly.GetType("IDESCoder");//this statement may have some question
Type dllTypeClass = myDllAssembly.GetType("ClsDES");//this statement may have some question
if (dllType!=null)
{
//TODO---you can use Factory pattern to improve it
dllTypeInterface interf=Activator.CreateInstance(dllTypeClass );
}
and you can choose another simpler way to resolve the problem.
first of all,You should Add references into your application in VS.NET.
then you can use it like using some interface or class in mscorlib.dll.
for example. using System.Int32;
It is very useful for everyone to show your own ideas to others.---Discussion is the power of improvement.
|
|
|
|
|
i know the way you said, and, you see , if i just know the interface'name ,can i have the dllTypeInterface object?
|
|
|
|
|
Hi all,
I am trying to use a DLL that modifies a stream of bytes (basically it's an encryption/decryption DLL). This DLL comes from a third party and I have to use it "as is". It wasn't designed for C#, but I really don't see any reason I shouldn't be able to use it.
The DLL reads and writes to a byte array (reads encrypted data, writes decrypted data), and this is giving me the error "Attempted to read or write protected memory."
I think the problem is quite simply that I don't understand how C# handles this kind of thing, so was wondering if I could get a little help.
The code goes something like this:
<br />
[DllImport("ABCdecrypt.dll", EntryPoint = "ABCdecrypt", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]<br />
unsafe public static extern bool ABCdecrypt([MarshalAs(UnmanagedType.I4)] int type, byte* data, int datalength);<br />
<br />
private void buttonGo_Click(object sender, EventArgs e)<br />
{<br />
byte[] yData = File.ReadAllBytes(textBoxInput.Text);
unsafe<br />
{<br />
fixed (byte* pBuf = &yData[0])<br />
{<br />
ABCdecrypt(100, pBuf, yData.Length);
File.WriteAllBytes(textBoxOutput.Text, yData);
}<br />
}<br />
MessageBox.Show("Done");<br />
}<br />
If I'm not being clear, please ask me to clarify. Essentially, all I want to do is use the library to decrypt the file referred to by textBoxInput.Text and save it out as the file referred to by textBoxOutput.Text
|
|
|
|
|
Hi YttriumOxide,
I've been struggling with something very similar recently. You can read my question here[^]:
I seem to have found an answer and it turned out to be far simpler than I thought it was going to be. Having said that, I might still be doing something wrong which will come back to bite me later but for now I seem to be OK and on my way.
What I did different from you was not to pass a pointer to the byte array as a parameter to the function but the byte array itself. I did not even do it in an unsafe block (which I probably should) but it worked.
So, leaving your declaration of your function unchanged (where you import it from the DLL), I would have called it like this:
ABCdecrypt(100, yData, yData.Length);
I have to stress though that I am by no means an expert in this field. I'm only just starting to meddle in C# and I haven't the faintest clue about marshalling. By the way, why did you marshal your first parameter as UnmanagedType.I4? And why did you not marshal the other two parameters? Do you know of any sites where I can read up on the MarshalAs attribute when used in this context?
Good luck
|
|
|
|
|
I am a C# programmer with mostly ASP.NET experience. I have done very little Win32 (WinForms) programming. Any suggestions for a good book on Windows Forms? I don't mean a general C# or .NET book, but one that specifically addresses the topic of Windows Forms.
|
|
|
|
|
I use this one at work, and it is pretty good.
Edit: Sorry, just noticed you said not specifically for C#.
|
|
|
|
|
No, your answer is great - I don't want a VB book, I want a C# one. What I meant was I don't want a C# book on General .NET. I want a C# book written specifically for windows forms, and that's exactly what you found.
Thanks
|
|
|
|
|
I use "Windows Forms Programming in C#" by Chris Sells....Excellent book.
Theres a version for .NET 2.0 out now also.
Hope that helps
Mike
Everybody gotta be somebody
|
|
|
|
|
|
I used Charles Petzolds book on Forms programming, but I am not very happy with it. It gives a very global overview and he refues to use the IDE functions, which are really great help when trying to create forms.
Petzold gives a lot of attention to the use of panels. However, panels have serious disadvantages. For a more complex form with, say 10 controls, you need a lot of panels. This makes maintenance a hell. So I decided to stop using panels.
Petzold gives very little attention to important but complex controls like listboxes and listviews. I think this very dissappointing.
|
|
|
|
|
hi guys,
how do i connect to a gateway using csharp and get its output so taht i can manipulate them...
as im a biginner in csharp 1 idea i had was uusing telnet and get the data..
is there any good solutions for this??
aneef
|
|
|
|
|
Hello all,
I'm in the process of writing a windows service. We would like to provide a small application that lives in the system tray so that people can monitor the status of the service. This application doesn't really need to do anything other than display an icon in the taskbar and maybe a context menu. All of the options selected from the context menu will either do something in the background (stopping/starting the service) or will launch another application. Is there a more eloquent way to handle this that just putting the component on an other wise empty form, loading the form and then making it invisible?
I generally hate task tray icons and usually turn them off, so I've never run into this problem before.
Will
|
|
|
|
|
I don't know of any other way of doing it. So yes blank form with the component on the empty form.
Ben
|
|
|
|
|
Hi,
I have a C++ DLL exporting a function that takes a callback of the following type:
typedef muFloat_t* (*muFacFun_t)(const muChar_t*, void*);
Is there any chance i can wrap this into a delegate? The Problem is that the function returns a pointer but C# has no pointers.
Regards,
Ingo
|
|
|
|
|
|
Generally speaking, System.IntPtr is used for marshalling pointers. Sometimes ref or out is used to pass variables in by reference.
I notice your function has a void pointer. Check out this[^] MSDN example of marshalling void pointers.
This[^] example may help as well.
|
|
|
|
|
I have a DataSet containing several tables.
Client, ClientEvent, Purchase, Return, PaymentMade
The relationships are:-
Client to ClientEvent
ClientEvent to Purchase
ClientEvent to Return
ClientEvent to PaymentMade
I use this tables to populate grids in my program but when I show the Purchase table I want the Client.Surname, Client.Telephone and Client.ClientType columns to show.
I would like to use an expression to do this but when I try "Parent(ClientEvent2Purchase).Parent(Client2ClientEvent).Surname" I get the following error:
Unhandled Exception: System.Data.SyntaxErrorException: Expected token 1 (Name), but actual token at the position 24 is token 15 (Parent).
Is there a way to do this using expressions and if not how could I do it? (I would prefer not to use sql to load the data directly using a join as I am working with the data already stored in memory)
-- modified at 16:11 Wednesday 28th March, 2007
|
|
|
|
|
I'm not sure if the expressions will work, but I believe you can solve that problem by adding DataRelation(s) to your DataSet. This basically joins parent/child DataTables based on whatever columns you specify. Once you have a relation set up for the parent/child relationships, you can use dataRow.GetChildRows() or dataRow.GetParentRows() to get the data you're after.
HTH
|
|
|
|
|
Helloo all
am using xmltextWriter to write node in xml file
XmltextWriter w=null
w=new Xmltextwriter(-----);
but the problem not in using writer
the problem is
I have listbox have this values
----------
Level1
Level2
Level2
Level2
Level3
Level3
Level1
Level2
Level3
Level4
Level2
Level2
-----------
and soon on
i want to make witer get values for list and write it to xml
every level1 present base node(root node) and sublevels is subnodes
i want be unlimeted level
xml file show be appear like this
<root>
<level1>
<level2/>
<level2/>
<level2>
<level3/>
<level3/>
</level2>
</level1>
<level1>
<level2>
<level3>
<level4/>
</level3>
</level2>
</level2>
</level2>
</level1>
</root>
I want make it recursive;;;;
|
|
|
|
|
Tkml236 wrote: I want make it recursive;;;;
Sounds like a TreeView might go along with want you want better than a listbox will.
|
|
|
|
|
no ...data is stored in listbox
(my real problem is stored in othere place but i simplifeid the problem to me clear)
i went to get data and write it in XML
|
|
|
|
|
It's easy.
In this routine, you will iterate throught the items in the listbox, fetching their values one by one.
Now i assume that you are getting the info on which list-item is a child and which is a parent from the value of the listbox item. In that case, you need to assign all items in the list box with a unique level number (depending on their nesting in the XML). Based on this, when you iterate through items in the list box, you would know which item to nest under which node and at which level.
It won't help much by trying to make this recursive. Keep it simple and straight. Any by the way, it's pretty hard understanding your written english Please be a little more clearer with your questions.
Excelsior
Arjun Bahree
"By The Might of Mjolnir"
I Came! I Coded! I Conquered!
|
|
|
|
|
ok..how can I solve this problem if I have unlimeted nested levels for level1
please see the example it will be clear for you?
|
|
|
|
|
As I said.... If you have unlimited nested levels for level 1, keep on making a list of all the nestings that you have already written in a stringdictionary or so. the key wud be level number and value would be name, in the StringDict. This list will kee on growing as your list size. if ur list item is unlimited, recursive is a real bad idea since it will give you stack overflow soon enough. Putting in a bit of logic to use a normal collection instead of a recursive stack is a much much better idea for unlimited list items.
Excelsior
Arjun Bahree
"By The Might of Mjolnir"
I Came! I Coded! I Conquered!
|
|
|
|