Visualizzazione dei risultati da 1 a 8 su 8
  1. #1

    [c#] Dll import ???

    Ragazzi,
    come faccio a scandire il percorso logico o fisico della Dll creata da me??

    [DllImport("rettangoli.dll")] --> così va bene e ci siamo

    string DIR = "c:\\alex\\prova\\";
    string Dll ="rettangoli.dll";

    [DllImport(DIR + Dll)] --> così non va bene e mi dice :
    L'argomento di un attributo deve essere un'espressione costante, un'espressione typeof o un'espressione per la creazione di matrici
    FestaDj.it - DeeJay per feste musica per l'intrattenimento
    ExpoLine.it - Passatempo e Risorse per Webmaster.
    SuperAst.it - Mercatino web annunci gratuiti.

  2. #2
    Posta tutto il codice... secondo me c'è un problema di scope delle variabili...
    Amaro C++, il gusto pieno dell'undefined behavior.

  3. #3
    Originariamente inviato da MItaly
    Posta tutto il codice... secondo me c'è un problema di scope delle variabili...

    protected string strPath = System.IO.Path.GetDirectoryName(System.Reflection. Assembly.GetExecutingAssembly().CodeBase);


    [DllImport(strPath + "\\rettangoli.dll")]
    public static extern int rettangoli(char[] inputNomeFile, char[] outputNomeFile, int soglia, char[] outputFileDimensioni);

    public int avviaRettangoli(string inputNomeFile, string outputNomeFile, int soglia, string outputFileDimensioni)
    {
    int z;

    char[] nomeFile1 = inputNomeFile.ToCharArray();
    char[] nomeFile2 = outputNomeFile.ToCharArray();
    char[] nomeFile3 = outputFileDimensioni.ToCharArray();

    z = rettangoli(nomeFile1, nomeFile2, soglia, nomeFile3 );

    return z;
    }
    FestaDj.it - DeeJay per feste musica per l'intrattenimento
    ExpoLine.it - Passatempo e Risorse per Webmaster.
    SuperAst.it - Mercatino web annunci gratuiti.

  4. #4
    codice:
    protected static string strPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
    Amaro C++, il gusto pieno dell'undefined behavior.

  5. #5
    Originariamente inviato da MItaly
    codice:
    protected static string strPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
    no non è quello...
    FestaDj.it - DeeJay per feste musica per l'intrattenimento
    ExpoLine.it - Passatempo e Risorse per Webmaster.
    SuperAst.it - Mercatino web annunci gratuiti.

  6. #6
    Gli attributi accettano come parametri solo valori costanti; inoltre non ti è necessario aggiungere il percorso della tua dll, perché viene automaticamente cercata nella cartella del tuo programma.
    Amaro C++, il gusto pieno dell'undefined behavior.

  7. #7
    Originariamente inviato da MItaly
    Gli attributi accettano come parametri solo valori costanti; inoltre non ti è necessario aggiungere il percorso della tua dll, perché viene automaticamente cercata nella cartella del tuo programma.
    e no proprio no anch'io pensavo fosse così invece no!
    FestaDj.it - DeeJay per feste musica per l'intrattenimento
    ExpoLine.it - Passatempo e Risorse per Webmaster.
    SuperAst.it - Mercatino web annunci gratuiti.

  8. #8
    Ti assicuro che è così: il .NET Framework dietro le quinte per caricare le dll non gestite usa l'API LoadLibrary, nella cui documentazione si legge:
    When no path is specified, the function searches for loaded modules whose base name matches the base name of the module to be loaded. If the name matches, the load succeeds. Otherwise, the function searches for the file in the following sequence:
    1. The directory from which the application loaded.
    2. The current directory.
    3. The system directory. Use the GetSystemDirectory function to get the path of this directory.
    4. The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
    Windows Me/98/95: This directory does not exist.[/b]
    5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
    6. The directories that are listed in the PATH environment variable.
    Windows Server 2003, Windows XP SP1: The default value of HKLM\System\CurrentControlSet\Control\Session Manager\SafeDllSearchMode is 1 (current directory is searched after the system and Windows directories).
    Windows XP: If HKLM\System\CurrentControlSet\Control\Session Manager\SafeDllSearchMode is 1, the current directory is searched after the system and Windows directories, but before the directories in the PATH environment variable. The default value is 0 (current directory is searched before the system and Windows directories).

    The first directory searched is the one directory containing the image file used to create the calling process (for more information, see the CreateProcess function). Doing this allows private dynamic-link library (DLL) files associated with a process to be found without adding the process's installed directory to the PATH environment variable.
    .
    Che errore ti dà quando richiami quella funzione?
    Amaro C++, il gusto pieno dell'undefined behavior.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.