|
Okay, this may sound silly but I've never had to create a DLL in c# until now. I've written a C# dialog app and I want to run some crystal reports from a dll. So can someone point me to a tutorial that shows how to create dll's and how to call them from my C# app? Oh and in my dll I will need to pop up a dialog showing the report in it. Is this doable? I've done it plenty times in MFC.
Thanks
Tom Wright
tawright915@yahoo.com
-- modified at 18:12 Monday 1st May, 2006
|
|
|
|
|
If you need Win32 dll - you can't create it in c#. You have to make it in c++ or any other native language. About using Win32 dlls from c# - search for Platform Invoke (p/invoke). This can be useful, for example
If you need .net dll - just set in project properties, on Application tab, "output type" property to "Class library".
Using .net dlls on design-time is very easy - add reference to needed dll and use it through Namespace.Class.Function system. For example, if your dll contains function ShowReport() in class Report in namespace MyReportNamespace, you just have to call for MyReportNamespace.Report.ShowReport().
About showing dialog - I don't know what about CrystalReport, but I've used a lot of forms, called from dlls.
____________________________________________
Robin Panther http://www.robinland.com
|
|
|
|
|
I've tried to use this method just as I see it after Googling every way I can find, and the usage is all the same:
string strCompressed = PassportIdentity.Compress(strToCompress);
But when I try to use it, I get an exception: "Unable to load dll (aspnet_isapi.dll)". I added a reference to System.Web and a using directive for System.Web.Security, and it just won't work. Any clues as to what I'm screwing up?
My Music | My Pics | My Articles
BlackDice
|
|
|
|
|
1) Are you trying to use it in ASP.NET with Microsoft IIS installed?
2) How are you trying to use it?
--
I've killed again, haven't I?
|
|
|
|
|
I've found out I'm using the wrong thing. What I need to use is System.IO.Compression to achieve what I'm trying to do (compress a long string that is sent both ways from client and server using sockets on specific ports)
My Music | My Pics | My Articles
BlackDice
|
|
|
|
|
Long time Java programmer running into a C# issue I can not figure out.
I have a class that contains a List. Other classes need iterate through the list. What I have below is not working. I get an excpetion at runtime about Current being outofRange.
Should I just return an Enumerator from the List or is there a way to do it like this that I'm missing.
thanks for the help.
Class Foo<br />
{<br />
List<Bar> list;<br />
<br />
list = fill_it_up();
<br />
public class FooIterator : IEnumerator<br />
{<br />
protected int lastVisited;<br />
<br />
public FooIterator ()<br />
{<br />
lastVisited = -1;<br />
<br />
}<br />
<br />
#region IEnumerator Members<br />
<br />
public object Current<br />
{<br />
get<br />
{<br />
<br />
return list[lastVisited].thisBar;<br />
<br />
}<br />
}<br />
<br />
public bool MoveNext()<br />
{<br />
return ++lastVisited < list.Count - 1;<br />
}<br />
<br />
public void Reset()<br />
{<br />
throw new Exception("The method or operation is not implemented.");<br />
}<br />
<br />
#endregion<br />
}<br />
}<br />
<br />
}
|
|
|
|
|
You might as well just return the List's enumerator (accessed via GetEnumerator()) if you are not doing any special/custom processing in your enumerator.
Josh
|
|
|
|
|
Just tried this and got an InvalidOperationException saying that the enumeration has either not started or finished.
|
|
|
|
|
looks like you get an error when lastVisited is -1.
Probably you have to do something like this:
public object Current<br />
{<br />
get<br />
{<br />
if (lastVisited == -1) return null;<br />
return list[lastVisited].thisBar;<br />
}<br />
}
____________________________________________
Robin Panther http://www.robinland.com
|
|
|
|
|
Tried this but did not work. See following post for why and a new question.
|
|
|
|
|
I think I figured out why I'm having the problem but I still can not figure a way around it yet.
FooIterator in an inner class so it can only acess list if list is a static attribute. So I made changes like so:
<br />
<br />
public object Current<br />
{<br />
get<br />
{<br />
<br />
return Foo.list[lastVisited].thisBar;<br />
<br />
}<br />
But when checking the degugger, when I load Foo.list is is fine. When I access it via the Iterator inner class it is empty.
I tried to get rid of the inner class and return the static list and that did not work.
What I need to do is immitate the Java Iterator but this seems impossible because of the static attribute contrate on inner classes.
|
|
|
|
|
The problem is more complex than I wrote here but I will show my solution to this problem.
Here is what we had.
Class Foo<br />
{<br />
protected static List<T> list;<br />
<br />
list = fill_it_up();
<br />
public class FooIterator : IEnumerator<br />
{<br />
protected int lastVisited;<br />
<br />
public FooIterator ()<br />
{<br />
lastVisited = -1;<br />
<br />
more enumeration code....<br />
}
The FooIterator was neede by other class to enumerate through the List<>. The inner class was not working because the List has to be static.
Class Bar is an object that contains 2 other objects.
Here is the change:
Class Foo<br />
{<br />
protected List<Bar> list;<br />
<br />
list = fill_it_up();
<br />
public class FooIterator <br />
{<br />
private List<Bar> list;<br />
public FooIterator (List<Bar> anotherList)<br />
{<br />
list = anotherList;<br />
}<br />
public IEnumerator<FeFiFoe> GetEnumerator()<br />
{<br />
foreach (Bar b in list)<br />
{<br />
yield return b.thisFeFiFoe;<br />
<br />
}<br />
}<br />
<br />
}
Hope this helps someone else.
|
|
|
|
|
I have an ActiveX control that is wrapped as an AxHost class. It draws an image when certain properties are input to it. Is there any way that I could draw that control to an image instead of on a form? I tried using this:
<br />
using System;<br />
using System.Drawing;<br />
using System.Runtime.InteropServices;<br />
using System.Windows.Forms;<br />
<br />
public class ControlPainter<br />
{<br />
private const int<br />
WM_PRINT = 0x317, PRF_CLIENT = 4,<br />
PRF_CHILDREN = 0x10, PRF_NON_CLIENT = 2,<br />
COMBINED_PRINTFLAGS = PRF_CLIENT | PRF_CHILDREN | PRF_NON_CLIENT;<br />
<br />
[DllImport("USER32.DLL")]<br />
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, int lParam);<br />
<br />
public static void PaintControl(Graphics graphics, Control control)<br />
{
IntPtr hWnd = control.Handle;<br />
IntPtr hDC = graphics.GetHdc();<br />
SendMessage(hWnd, WM_PRINT, hDC, COMBINED_PRINTFLAGS);<br />
graphics.ReleaseHdc(hDC);<br />
}<br />
}<br />
and it paints everything besides the ActiveX control. Does anyone know how to do this?
|
|
|
|
|
|
I'm sorry, I forgot to mention that I am using Framework 1.1... I think DrawToBitmap is only a 2.0 method.
|
|
|
|
|
I am displaying a folder in my windows app. This is the functionality I am trying to achieve:
User can go to Options > Locations > Change Location > and tell the program what folder to watch. On clicking 'OK' button I want my form (that displays the folder content) to be refreshed so that we can view the recently assigned filder's content.
What is the best way to do it?
Thanks in advance.
Note: this.Refresh(); does not work, I am assuming it just re-paint the form on the screen instead of refreshing the contents.
|
|
|
|
|
Whatever code is populating the list of file names the first time, just clear out the list and call that same code again when they change the target folder and click the OK button. If you are yet to create the code which lists the files in a folder, check out the System.IO namespace for classes that will help you get that info.
Josh
|
|
|
|
|
Thanks for the reply. Sounds like this should do the trick.
Just one more quick question as to how can I call the same code again; since the Click button is on a different form?
Here is how I did it (if there is a better of doing it plz let me know) When user goes to menu Options > Locations > and click 'Change Location' I open a new form and capture user input and save the new folder path to the Properties.Settings.Default.Folder_Location
|
|
|
|
|
student_rhr wrote: Just one more quick question as to how can I call the same code again; since the Click button is on a different form?
Either expose that code as a static method in a utility class, or as a public (possibly static) method on the Form-derived class which currently contains it. That will allow any code in any file to use that same method.
Josh
|
|
|
|
|
This is how I have the method within the frmMain()
public partial class frmMain : Form
{
public TreeNode parentNode;
public TreeView treeView1;
public string folderLocation = Video_Watcer.Properties.Settings.Default.Folder_Location.ToString();
public int progress;
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
PopulateTreeView();
}
public void PopulateTreeView()
{
DirectoryInfo di = new DirectoryInfo(folderLocation);
treeView1.ImageList = imageList1;
parentNode = treeView1.Nodes.Add(di.Name.ToString());
StatusBarLabelFolderPath.Text = di.FullName.ToString();
SetParentNodeImage();
string CurrentFileName;
for (int i = 0; i <= di.GetFiles().GetUpperBound(0); i++)
{
FileInfo[] fi = di.GetFiles();
txtWatcherStatus.Text = txtWatcherStatus.Text + Environment.NewLine + fi[i].ToString();
CurrentFileName = fi[i].ToString();
SetFileNodes(CurrentFileName);
}
}
}
But I am not able to see any thing in frmOptions when I type frmMain. PopulateTreeView does not pop-up in the intellisense. what am I doing wrong here
This is the code for my frmOptions form:
private void btnApply_Click(object sender, EventArgs e)
{
try
{
Properties.Settings.Default.Folder_Location = txtFolderPath.Text.ToString();
Properties.Settings.Default.Save();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
|
|
|
|
|
frmMain is a class, not an instance of a class. Since the PopulateTreeView method is not static, then you can't call it without an instance of frmMain. Make the PopulateTreeView method static and alter the parameter list so that it accepts an instance of frmMain (to access the TreeView, StatusBar, etc.)
Josh
|
|
|
|
|
Thanks a lot for helping me with this problem, but as you can see I am just a beginer in C#, I was not entirely sure as to how I am suppose to alter the parameter list. Did you ask me to do something like PopulateTreeView(object frm) or something like PopulateTreeView(TreeView tv, StatusBar, SB) ?? or neither?? if neither then a code example will really be helpful (if at all possible)
your replies are much appreciated
|
|
|
|
|
You may ignore my last post
I changed the code to following:
public static void PopulateTreeView(frmMain d)
{
DirectoryInfo di = new DirectoryInfo(d.folderLocation);
d.treeView1.ImageList = d.imageList1;
d.parentNode = d.treeView1.Nodes.Add(di.Name.ToString());
d.StatusBarLabelFolderPath.Text = di.FullName.ToString();
d.SetParentNodeImage();
string CurrentFileName;
for (int i = 0; i <= di.GetFiles().GetUpperBound(0); i++)
{
FileInfo[] fi = di.GetFiles();
d.txtWatcherStatus.Text = d.txtWatcherStatus.Text + Environment.NewLine + fi[i].ToString();
CurrentFileName = fi[i].ToString();
d.SetFileNodes(CurrentFileName);
}
}
And frmMain_Load call to following:
private void frmMain_Load(object sender, EventArgs e)
{
PopulateTreeView(this);
}
But the contents have not been updated, I must be doing something wrong here.
|
|
|
|
|
This doesn't really make any sense. If you need a reference to the frmMain instance so that you can pass it as a parameter, you might as well just make the method non-static and not take in a parameter of type frmMain (it would reference the fields via this instead of the parameter).
Basically what you want to do is make the logic which refreshes the list of items in a folder publicly available so that any other form can call that method on a myForm instance. It only makes sense to have it be static if it is a method contained in a completely different class.
Josh
|
|
|
|
|
Josh Smith wrote: Make the PopulateTreeView method static and alter the parameter list so that it accepts an instance of frmMain (to access the TreeView, StatusBar, etc.)
.
This is what I was trying to do. Did you mean that I need to put the PopulateTreeView method is a seperate class and pass it an instance of frmMain?
I guess the problem is my lack of knowldge, if you would be so kind to provide a code example that would really be helpful. Thanks.
Best Regards,
rhr
|
|
|
|