| C# erreur namespace pas trouvé | |
|
|
Auteur | Message |
---|
PHENIXprod Utilisateur confirmé: Rang ****
Messages : 835
| Sujet: C# erreur namespace pas trouvé Ven 10 Juin 2011 - 16:51 | |
| Je bosse sur un truc en C# pour la première fois et j'ai une erreur de type: - Code:
-
error CS0246: The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?) Le code source est le suivant: - Code:
-
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.Diagnostics; using System.Security; using System.Threading; using System.Collections;
namespace PuttyShadow { class Program { static void Main(string[] args) { // Configure un nom unique au launcher puis le cache Console.Title = Guid.NewGuid().ToString(); Windows w = new Windows(); foreach (Window wItem in w) { if (wItem.Title == Console.Title) wItem.Visible = false; }
// Création du process a lancer Process p = new Process(); p.StartInfo.FileName = @"C:\Documents and Settings\Jérôme\Mes documents\Visual Studio 2008\Projects\Project3\miniRelay"; p.Start(); Thread.Sleep(100);
// On retrouve la fenêtre et on la cache ^^ w = new Windows(); foreach (Window wItem in w) { if (wItem.Title.Contains("miniRelay")) wItem.Visible = false; }
p.WaitForExit(); } } public class Window {
[DllImport("user32.dll")] private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")] private static extern bool IsIconic(IntPtr hWnd); [DllImport("user32.dll")] private static extern bool IsZoomed(IntPtr hWnd); [DllImport("user32.dll")] private static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] private static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId); [DllImport("user32.dll")] private static extern IntPtr AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, int fAttach);
private const int SW_HIDE = 0; private const int SW_SHOWNORMAL = 1; private const int SW_SHOWMINIMIZED = 2; private const int SW_SHOWMAXIMIZED = 3; private const int SW_SHOWNOACTIVATE = 4; private const int SW_RESTORE = 9; private const int SW_SHOWDEFAULT = 10;
private IntPtr m_hWnd; private string m_Title; private bool m_Visible = true; private string m_Process; private bool m_WasMax = false;
public IntPtr hWnd { get { return m_hWnd; } } public string Title { get { return m_Title; } } public string Process { get { return m_Process; } }
public bool Visible { get { return m_Visible; } set { if (value == true) { if (m_WasMax) { if (ShowWindowAsync(m_hWnd, SW_SHOWMAXIMIZED)) m_Visible = true; } else { if (ShowWindowAsync(m_hWnd, SW_SHOWNORMAL)) m_Visible = true; } } if (value == false) { m_WasMax = IsZoomed(m_hWnd); if (ShowWindowAsync(m_hWnd, SW_HIDE)) m_Visible = false; } } }
public Window(string Title, IntPtr hWnd, string Process) { m_Title = Title; m_hWnd = hWnd; m_Process = Process; }
public override string ToString() { if (m_Title.Length > 0) return m_Title; else return m_Process; } } public class Windows : IEnumerable, IEnumerator { [DllImport("user32.dll")] private static extern int GetWindowText(int hWnd, StringBuilder title, int size); [DllImport("user32.dll")] private static extern int GetWindowModuleFileName(int hWnd, StringBuilder title, int size); [DllImport("user32.dll")] private static extern int EnumWindows(EnumWindowsProc ewp, int lParam); [DllImport("user32.dll")] private static extern bool IsWindowVisible(int hWnd);
public delegate bool EnumWindowsProc(int hWnd, int lParam); private int m_Position = -1; ArrayList wndArray = new ArrayList();
private bool m_invisible = false; private bool m_notitle = false;
public Windows(bool Invisible, bool Untitled) { m_invisible = Invisible; m_notitle = Untitled; EnumWindowsProc ewp = new EnumWindowsProc(EvalWindow); EnumWindows(ewp, 0); }
public Windows() { EnumWindowsProc ewp = new EnumWindowsProc(EvalWindow); EnumWindows(ewp, 0); }
private bool EvalWindow(int hWnd, int lParam) { if (m_invisible == false && !IsWindowVisible(hWnd)) return (true);
StringBuilder title = new StringBuilder(256); StringBuilder module = new StringBuilder(256);
GetWindowModuleFileName(hWnd, module, 256); GetWindowText(hWnd, title, 256);
if (m_notitle == false && title.Length == 0) return (true);
wndArray.Add(new Window(title.ToString(), (IntPtr)hWnd, module.ToString()));
return (true); }
public IEnumerator GetEnumerator() { return (IEnumerator)this; }
public bool MoveNext() { m_Position++; if (m_Position < wndArray.Count) { return true; } else { return false; } } public void Reset() { m_Position = -1; } public object Current { get { return wndArray[m_Position]; } } } } Je ne comprends pas, j'ai pourtant tout bien défini non? |
|
| |
onilink_ Modérateur
Messages : 9180 Localisation : Montpellier Projet Actuel : Planet Centauri
OniDev
| Sujet: Re: C# erreur namespace pas trouvé Ven 10 Juin 2011 - 16:55 | |
| Il ne donne pas une/des ligne(s) d'erreur(s) le debugger ? |
|
| |
PHENIXprod Utilisateur confirmé: Rang ****
Messages : 835
| Sujet: Re: C# erreur namespace pas trouvé Ven 10 Juin 2011 - 17:04 | |
| si, je te met exactement ce qu'il dit: - Code:
-
------ Rebuild All started: Project: Project3, Configuration: Debug Any CPU ------ c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\Project3.exe /target:exe Program.cs C:\Documents and Settings\Jérôme\Mes documents\Visual Studio 2008\Projects\Project3\Project3\Program.cs(27,13): error CS0246: The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Jérôme\Mes documents\Visual Studio 2008\Projects\Project3\Project3\Program.cs(27,29): error CS0246: The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?)
Compile complete -- 2 errors, 0 warnings ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========== en gros c'est cette ligne qui le chagrine: - Code:
-
Process p = new Process(); |
|
| |
onilink_ Modérateur
Messages : 9180 Localisation : Montpellier Projet Actuel : Planet Centauri
OniDev
| Sujet: Re: C# erreur namespace pas trouvé Ven 10 Juin 2011 - 17:43 | |
| T'as essayé sans les using blabla et en mettant les namespaces a la main pour voir si ça viens vraiment de la ? Genre Namespace::Machin
Après j'ai jamais fait de C# mais je vois pas de soucis qui saute au yeux quoi. |
|
| |
Wargamer *Excellent utilisateur*
Messages : 6938 Projet Actuel : Bataille de cake au fruits
| Sujet: Re: C# erreur namespace pas trouvé Ven 10 Juin 2011 - 18:17 | |
| Ba le namespace de ton .cs de process est bien PuttyShadow? Sinon si t'as renommé le dossier c'est normal, tu peux pas. _________________ Règle #1 du CBNA, ne pas chercher à faire dans la subtilité; personne comprend |
|
| |
PHENIXprod Utilisateur confirmé: Rang ****
Messages : 835
| Sujet: Re: C# erreur namespace pas trouvé Ven 10 Juin 2011 - 18:57 | |
| renommé le dossier? lequel? non il ne me semble pas avoir renommé quoi que ce soit... sinon qqn pourrais compiler ce code sur son ordi, j'ai tout mis. Parce-que moi non plus je ne vois pas ce qui cloche |
|
| |
Wargamer *Excellent utilisateur*
Messages : 6938 Projet Actuel : Bataille de cake au fruits
| Sujet: Re: C# erreur namespace pas trouvé Ven 10 Juin 2011 - 23:28 | |
| Dans mon cas, mon Main est totalement différent, ca vient peut être de là - Spoiler:
namespace Projet_final_Comm { static class Program { /// <summary> /// Point d'entrée principal de l'application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Jeu()); } } }
_________________ Règle #1 du CBNA, ne pas chercher à faire dans la subtilité; personne comprend |
|
| |
PHENIXprod Utilisateur confirmé: Rang ****
Messages : 835
| Sujet: Re: C# erreur namespace pas trouvé Sam 11 Juin 2011 - 12:14 | |
| Ok, je vais essayer de modifier le main pour voir si ça marche. |
|
| |
Kryptos Utilisateur confirmé: Rang ****
Messages : 1058 Localisation : très loin dans un univers étrange Projet Actuel : Space Racer, un jeu multijoueur en ligne réalisé avec Unity 3D.
| Sujet: Re: C# erreur namespace pas trouvé Sam 11 Juin 2011 - 13:06 | |
| La classe Process est contenue dans le namespace System.Diagnostics que tu as bien inclus. Cependant cette classe hérite de ComponentModel, tu dois donc aussi inclure System.ComponentModel. Toutes ces informations se trouvent dans la documentation de C#, la moindre des choses est de la lire. http://msdn.microsoft.com/fr-fr/library/system.diagnostics.process.aspx_________________ Venez tester la beta de notre jeu de course Space Racer (conçu avec Unity 3D) |
|
| |
PHENIXprod Utilisateur confirmé: Rang ****
Messages : 835
| Sujet: Re: C# erreur namespace pas trouvé Sam 11 Juin 2011 - 16:54 | |
| Merci, maintenant la compil réussit |
|
| |
Contenu sponsorisé
| Sujet: Re: C# erreur namespace pas trouvé | |
| |
|
| |
| C# erreur namespace pas trouvé | |
|