Visualizzazione dei risultati da 1 a 9 su 9
  1. #1
    Utente bannato
    Registrato dal
    Oct 2010
    Messaggi
    1,219

    [c++]creazione dll,errore di compilazione

    Salve,sto provando a creare una dll,il codice dovrebbe solo dire "hello world",ma mi da i seguenti errori di compilazione:
    codice:
    E:\Cpp\Sys64\main.cpp|7|error: function 'void HelloWorld()' definition is marked dllimport|
    E:\Cpp\Sys64\main.cpp||In function 'void HelloWorld()':|
    E:\Cpp\Sys64\main.cpp|7|warning: 'void HelloWorld()' redeclared without dllimport attribute: previous dllimport ignored|
    ||=== Build finished: 1 errors, 1 warnings ===|
    Questo è il codice della main:

    codice:
    /* Replace "dll.h" with the name of your header */
    #include "dll.h"
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    DLLIMPORT void HelloWorld ()
    {
       MessageBox (0, "Hello World from DLL!n", "Hi", MB_ICONINFORMATION);
    }
    
    
    BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                          DWORD reason        /* Reason this function is being called. */ ,
                          LPVOID reserved     /* Not used. */ )
    {
       switch (reason)
       {
         case DLL_PROCESS_ATTACH:
           MessageBox(0, "Hello world!!!!", "DLL Loaded", MB_OK);         return TRUE;
    
         case DLL_PROCESS_DETACH:
           break;
    
         case DLL_THREAD_ATTACH:
           break;
    
         case DLL_THREAD_DETACH:
           break;
       }
    
       /* Returns TRUE on success, FALSE on failure */
       return TRUE;
    }
    E questo l' header dll.h:

    codice:
    #ifndef _DLL_H_
    #define _DLL_H_
    
    #if BUILDING_DLL
    # define DLLIMPORT __declspec (dllexport)
    #else /* Not BUILDING_DLL */
    # define DLLIMPORT __declspec (dllimport)
    #endif /* Not BUILDING_DLL */
    
    
    DLLIMPORT void HelloWorld (void);
    
    
    #endif /* _DLL_H_ */
    In pratica dopo che ho compilato la dll voglio provare a eseguire il processo come fosse una dll,ma non viene nemmeno compilata.

  2. #2
    Se non erro il DLLIMPORT va dopo il tipo restituito.
    Amaro C++, il gusto pieno dell'undefined behavior.

  3. #3
    Utente bannato
    Registrato dal
    Oct 2010
    Messaggi
    1,219
    Ho provato anche a invertirli,niente da fare.
    Sembrerebbe come che il compilatore considera vietata l' operazione dll import:
    codice:
    E:\Cpp\Sys64\main.cpp|7|error: function 'void HelloWorld()' definition is marked dllimport
    Come fosse proibito

  4. #4
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Ehm...
    codice:
    #if BUILDING_DLL
    # define DLLEXPORT __declspec (dllexport)
    #else /* Not BUILDING_DLL */
    # define DLLIMPORT __declspec (dllimport)
    #endif /* Not BUILDING_DLL */
    Se no che senso ha definire la macro?
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

  5. #5
    Utente bannato
    Registrato dal
    Oct 2010
    Messaggi
    1,219
    Anche se scrivo come hai detto tu continua a dare lo stesso errore

  6. #6
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Quali modifiche hai fatto? Se non lo dici / posti, continueremo a girare attorno al problema.
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

  7. #7
    Utente bannato
    Registrato dal
    Oct 2010
    Messaggi
    1,219
    Adesso è così l' header file:
    codice:
    #ifndef _DLL_H_
    #define _DLL_H_
    
    #if BUILDING_DLL
    # define DLLEXPORT __declspec (dllexport)                  /* Ho modificato qua */
    #else /* Not BUILDING_DLL */
    # define DLLIMPORT __declspec (dllimport)
    #endif /* Not BUILDING_DLL */
    
    
    
    DLLIMPORT void HelloWorld (void);
    
    
    #endif /* _DLL_H_ */

  8. #8
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Pardon. Errore mio (ero di fretta e non ho letto bene).
    Rimodifica com'era in origine e controlla l'errore del compilatore:
    codice:
    E:\Cpp\Sys64\main.cpp|7|error: function 'void HelloWorld()' definition is marked dllimport|
    la macro DLLIMPORT viene espansa come __declspec (dllimport) invece di __declspec (dllexport), quindi la macro BUILDING_DLL non è definita.
    Prova a definirla appena sopra e vedi che succede.
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

  9. #9
    Utente bannato
    Registrato dal
    Oct 2010
    Messaggi
    1,219
    Ah no scusate,praticamente code::blocks ha già l' opzione di creare una dll e se selezioni un progetto dll ti crea già l' header file già fatto,io avevo selezionato dinamic link library,però avevo modificato alcune cose.
    Adesso ne ho creata una nuova senza cambiare niente e funziona,l' header che crea automaticamente code::blcoks è questo:
    codice:
    #ifndef __MAIN_H__
    #define __MAIN_H__
    
    #include <windows.h>
    
    /*  To use this exported function of dll, include this header
     *  in your project.
     */
    
    #ifdef BUILD_DLL
        #define DLL_EXPORT __declspec(dllexport)
    #else
        #define DLL_EXPORT __declspec(dllimport)
    #endif
    
    
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    
    void DLL_EXPORT SomeFunction(const LPCSTR sometext);
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif // __MAIN_H__
    E funziona.

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 © 2024 vBulletin Solutions, Inc. All rights reserved.