|
|
I'm trying to create my own DLL as a part of interpreter. I'm having trouble to load the dll...
The DLL source code is (TestDLL.dll in system32 directory):
using System;
namespace StringDLL
{
public class DllStringTest
{
public string StringReturn(int value)
{
switch (value)
{
case 0: return "Zero";
case 1: return "One";
case 2: return "Two";
case 3: return "Three";
default: return "Unknown";
}
}
}
}
and in the main code I use to load the DLL is:
[DllImport("DllTest")] public static extern string StringReturn(int value);
then to call the function in the event handler:
MessageBox.Show(StringReturn(0));
I'm trying to return the string value from DLL library. I have been getting the error "unable to find the entry point in TestDLL dll."
I want to load dll only when needed. Can anyone help?
|
|
|
|
|
Hi,
The DllImport attribute is used when using functions exposed by non-.NET libraries. In order to use the assembly you're creating (TestDll.dll), you need to add a reference to it in Visual Studio .NET.
AFAIK, the assembly will not be loaded until you call anything located in it, so there's no no need to implement dynamic loading.
Regards,
Serge (Logic Software, Easy Projects .NET site)
|
|
|
|
|
DllImportAttribute is for calling native functions from native DLLs. Your code is managed code and the only entry point exposed is for the static Main method (by default, which is a compiler feature) of a .EXE assembly.
.NET assemblies you simply reference like you do System.dll, System.Windows.Forms.dll, etc.
In your project where you want to call StringReturn , right-click on your project and select Add Reference. If the project is in the same solution as your other project, click the Projects tab and double-click the project to add it. Otherwise, select or browse to the assembly that defines that method and add it to your project. Then use the fully-qualified class name (or add the namespace to your using statements toward the top of your source file) and call the method. Since it's an instance method, you'll need to instantiate DllStringText .
If you're trying to call arbitrary methods in any assembly dropped into your process's current working directory, you'll need to implement more of a plug-in style application, which usually uses an interface or abstract class to provide abstract access to an implementation and a way to find that implementation. Searching through an assembly is far too expensive to find such types (though possible), so one usually uses a .config file and custom IConfigurationSectionHandler implementation to register types (this is used for the provider pattern-style of programming).
Try the following search for several good plug-in articles:
http://www.codeproject.com/info/search.asp?cats=3&cats=5&searchkw=plug-ins[^]
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
To clarify this... I would need to have the dll be explicively load the dll. I would like to avoid using the "Add Resource" in the .net editor.
|
|
|
|
|
Update:
I tried replacing "AfterSelect" with DoubleClick, but when I compile I get this error:"D:\Documents\Visual Studio Projects\WindowsApplication5\Form1.cs(70): Cannot implicitly convert type 'System.Windows.Forms.TreeViewEventHandler' to 'System.EventHandler'
" from this line: "this.treeView1.DoubleClick += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_DoubleClick);". I tried casting this.treeView1.DoubleCLick to a TreeViewEventHandler, but it won't let me do that either. Any suggestions? (sorry, I'm very new to C#) Also, would it be possible to change the event from DoubleClick to when the user presses the "Enter" key? If so, what is the event for this?
Thanks,
Justin
Original Question:
I am relativley new to C#, and I'm trying to write an app, using the compact framework, that will allow a handheld user to scroll through a treeview, hit enter on a selected node, and then do something specific to that node. I figured that the doubleclick event was as close as I could get to actually pressing enter/return, but I still cannot figure out how to write a method that is specific to a node of the treeview, rather than the entire treeview. When I doubleclick on the treeview in design mode, regardless of what node I click on, the only code it creates for me is private void treeView1_AfterSelect(...). So, does anyone know how to setup a function that will do something when the user doubleclicks/hits enter on a node of a treeview? Examples are much appreciated.
Thanks,
j1e1g1
|
|
|
|
|
Take a look at the TreeView.AfterSelect Event[^] documentation on MSDN. The TreeViewEventArgs contain a Node which you can refer to within your method as the selected node.
private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
TreeNode node = e.Node;
if(node != null)
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
Since the TreeNode doesn't fire any everys, you can't wire up any code to it. The DoubleClick event is fired by the TreeView control, not the TreeNode you clicked on. In your DoubleClick event handler, you'll used the SelectedNode property to find out which node the used clicked on. You can modify the function that the designer creates by renaming the treeView1_AfterSelect function to treeView1_DoubleClick and making the same change in the Windows Forms Designer gnerated code section. A search and replace for "AfterSelect" ought to do it nicely.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I tried replacing "AfterSelect" with DoubleClick, but when I compile I get this error:"D:\Documents\Visual Studio Projects\WindowsApplication5\Form1.cs(70): Cannot implicitly convert type 'System.Windows.Forms.TreeViewEventHandler' to 'System.EventHandler'
" from this line: "this.treeView1.DoubleClick += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_DoubleClick);". I tried casting this.treeView1.DoubleCLick to a TreeViewEventHandler, but it won't let me do that either. Any suggestions? (sorry, I'm very new to C#) Also, would it be possible to change the event from DoubleClick to when the user presses the "Enter" key? If so, what is the event for this?
Thanks,
Justin
|
|
|
|
|
Oooops... My mistake. That line should read:
this.treeView1.DoubleClick += new System.EventHandler(this.treeView1_DoubleClick);
There is no specific event fired for the Enter key. You might want to look into handling the KeyPress event, or KeyDown/KeyUp events, or possibly the Click event, to see which one will suit your needs. You can do this easily enough by displaying a MessageBox when those event fire.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
This line:
this.treeView1.DoubleClick += new System.EventHandler(this.treeView1_DoubleClick);
Still throws an error, because I'm not passing this.treeView1_DoubleClick any parameters. I'm not sure what I should pass here, other than (?nulls), because I don't have a sender object or an event arg to pass it.
Here is the error:
Method 'WindowsApplication5.Form1.treeView1_DoubleClick(object, System.Windows.Forms.TreeViewEventArgs)' does not match delegate 'void System.EventHandler(object, System.EventArgs)'
Sorry if this seems elementary, I'm still learning..
Thank you for your patience and your helpful responses,
Justin
|
|
|
|
|
Because DoubleClick is not of type TreeViewEventHandler , it is of type EventHandler , as the documentation would tell you if you read it.
You can get the TreeNode that was double-clicked like so:
this.treeView1.DoubleClick += new EventHandler(treeView1_DoubleClick);
private void treeView1_DoubleClick(object sender, EventArgs e)
{
Point p = PointToClient(MousePosition);
TreeNode node = GetNodeAt(p);
if (node != null)
{
}
} If you want to use the Enter key instead (really, it's better to use both), then handle the KeyDown event and get the select node using the TreeView.SelectedNode property.
If you want to know what events, methods, and properties are available for the TreeView , then you really should read the class documentation. See TreeView Members[^] in the .NET Framework SDK. The only true way to learn what all is available is to read.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have looked at the SDK, but it is all still a little overwhelming to a new .Net programmer. I guess I just need more practice with the syntax and necessary declarations of form control objects.
Also, its still throwing an error, because I'm not passing treeView1_DoubleClick any parameters in this line: this.treeView1.DoubleClick += new EventHandler(treeView1_DoubleClick);
I'm not sure what sender object or event args I should pass here, since I'm really just initializing the DoubleClick event...
Error:'WindowsApplication5.Form1.treeView1_DoubleClick(object, System.Windows.Forms.TreeViewEventArgs)' does not match delegate 'void System.EventHandler(object, System.EventArgs)'
Thanks for your help and patience,
Justin
|
|
|
|
|
j1e1g1 wrote:
I have looked at the SDK, but it is all still a little overwhelming to a new .Net programmer. I guess I just need more practice with the syntax and necessary declarations of form control objects.
It's not about syntax; it's about the classes available to a language (a "syntax"). The base class library (BCL) and any other class libraries for .NET are available to all managed languages like C#, VB.NET, etc. They call compile to Intermediate Language (IL), which is one of the features of the Common Language Infrastructure (CLI). The only way to learn all this is to read.
You don't pass parameters to a delegate (your EventHandler ) - the caller does. But the signature for the method has to match declaration of the delegate. Look at my code sample again; your treeView1_DoubleClick has to be declared as this:
private void treeView1_DoubleClick(object sender, EventArgs e)
{
} The important aspects of this method signature are in bold.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
The solution depends on the treeview depth. If it finite and small (e.g. 3 fixed levels), you can write a function that will tell your program, what kind of node it clicked on based on its treeview position.
If the depth is indeterminate, you can assign some kind of identity object to the TreeNode's Tag property to tell one node type from another.
Regards,
Serge (Logic Software, Easy Projects .NET site)
|
|
|
|
|
I write the following code in my porject:
<br />
ppApp = new PowerPoint.Application();<br />
<br />
objPres = ppApp.Presentations.Add(MsoTriState.msoCTrue);<br />
<br />
for(int i=0; i<Page_number; i++)<br />
{<br />
objSlide = objPres.Slides.Add(i+1, PowerPoint.PpSlideLayout.ppLayoutText);<br />
<br />
objShape = objSlide.Shapes.AddPicture(SavePath + "\\PSPage" + (i+1).ToString()+ ".bmp",MsoTriState.msoFalse,MsoTriState.msoTrue,9,22,702,496);<br />
<br />
<br />
objPres.SlideShowSettings.ShowType = PowerPoint.PpSlideShowType.ppShowTypeWindow;<br />
objPres.SlideShowSettings.Run();<br />
objPres.SlideShowWindow.Activate(); <br />
I can add a presentation, add a slide, insert a picture,
and I can show the SlideShowWindow,
but I don't know how to active the window in PowerPoint 2003,
to do the code ppApp.ActiveWindow.View.Paste();
and I want to show the presentation with standard mode not SlideShowWindow,
Does anyone know how to do this...??
I can't find the solutions for a long time...
|
|
|
|
|
You could try to enumerate the Windows where the Presentation is current being displayed and call Activate (untested, but it should work):
DocumentWindows windows = presentation.Windows;
if (windows.Count > 0) windows[0].Activate(); You can also enumerate the DocumentWindows (using foreach , for example) and find a named view you want, then call Activate .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
For a while now ... i keep seeing ...
[Serializable] or [other stuff] in '[]' ... and I don't fully understand what that meens .. if you can help me ... !
I'd also like to know all the thincs that can be wrote in [ ]
Lazar Mihai
Elev clasa XI C
Grup Scolar Sanitar
|
|
|
|
|
Attributes define metadata for class members.
Every Attribute is a class, e.g. SerializableAttribute. You can find more about those attribute classes in the .NET documentation.
|
|
|
|
|
|
Hello.
I've got the following problem:
There is a web application (ASP.NET), that needs to
authenticate users against local machine and Active Directory.
By default, the application works as ASPNET account (Win2000, XP).
When working on ASPNET account the apllication is able to do the following:
string path = "WinNT://" + evironment.MachineName + ",computer";<br />
DirectoryEntry entry = new DirectoryEntry(path, username, pwd);<br />
try<br />
{ <br />
Object o = entry.NativeGuid;<br />
}<br />
catch(...)<br />
{<br />
}
When run as ASPNET account (on XP) , the code is able to work correctly. However, when run as SYSTEM account, exception is thrown
"A specified logon session does not exist. It may already have been terminated."
I need to switch to system account, because I also need to authenticate users in Acitive Directory, and ASPNET this time cannnot connect to AD, whereas SYSTEM account can.
So, currently I can authenticate users either in local system (when run as ASPNET) or in AD (when run as SYSTEM), but not concurrently (i.e. I can not do this without restarting the process)
SYSTEM ASPNET (running XP)
LOCAL USERS - +
DOMAIN USES + -
SYSTEM ASPNET (running Win2000)
LOCAL USERS - -
DOMAIN USES + -
Questions:
1. Is there any way to grant local ASPNET account ability to connect to AD ?
2. Is there any way to allow SYSTEM account to authenticate users against local machine. (The inability seems ridiculous...) (Note: I cannot temporarily use impersonation [SYSTEM is granted right to
impersonate someone elese] to check credentials, since the application is a muliti user system and the fraction of time the app would work as somebody else (not system but e.g John.Smith ) would leed to errors. Ok, I might lock entire application functionality when somebody performs logon but this would be hugely ineffective and would require to redesign plenty of code. (The application is pretty complex))
Thanks for help
Michał Januszczyk
|
|
|
|
|
Michal,
I think you may get a better response if you try asking in the ASP.NET[^] forum specifically. I believe there may be some articles here on CP that cover this topic as well. HTH.
- Nick Parker My Blog | My Articles
|
|
|
|
|
hi, i wrote a small program in C# which uses threads.
But when i close the application ( this.close() ), it is not terminating the application. Application is still running in the task manager, but all windows of the applications are got closed.
I tried with closing all the threads ( t.abort() ), but it is not working.
Can any one solve the problem ?
M.V.Ravikumar
|
|
|
|
|
Declare your threads as background threads by setting the IsBackground property true, so they do not prevent the process from terminating.
www.troschuetz.de
|
|
|
|
|
Thank you for your quick response.
It solved my problem. But i didn't get the actual thing. If you have time, please enlighten me in this area, by giving some more info.
Application.exit() or the start form.close() , are both of them equal?
If we set isbackground property to true. after the form.close(), all the threads of the application will automatically aborted?
M.V.Ravikumar
|
|
|
|
|