Problem mit DLL-Erstellung unter VC++, help!



  • Hallö'chen,
    Ich wollte mich mal weiter mit dem "Microsoft Visual Studion C++ 6.0" beschäftigen und dachte du probierst es noch mal mit nem Global KbHoob 😃
    Naja aber irgendwie hat der Compiler was dagegen. Ich habe das Codebeispiel von 'toom' aus der FAQ http://www.c-plusplus.net/forum/viewtopic-var-t-is-39383.html
    verwendet. Habe also folgende Schritte im VC++ gemacht:
    -> Neues Project
    -> Menüpunkt "Win32 Dynamic-Link Library" ( wens interessiert Name: "KbHook" )
    -> Weiter
    -> "Ein einfaches DLL Projekt"
    -> Weiter
    -> dann habe ich erstmal die:

    BOOL APIENTRY DllMain( HANDLE hModule,  DWORD ul_reason_for_call, LPVOID lpReserved ) {
    
        return TRUE;
    }
    

    durch das ersetzt (obweohl das eigentlich nur ne kleine Schönheitskorektur war)

    int WINAPI DllMain( HINSTANCE hInstance, DWORD fdReason, PVOID pvReserved ) {
    
       return true;
    }
    

    -> Dann habe ich dem Projekt noch einen Header zugefügt mit gleichen Namen der .cpp-Datei und die Prototypen reingesteckt

    #ifdef __cplusplus
    #define EXPORT extern "C" __declspec( dllexport )
    #else
    #define EXPROT __declspec( dllexport )
    #endif
    
    EXPORT BOOL CALLBACK InstallKbHook( HWND );
    EXPORT BOOL CALLBACK UnistallKbHook( );
    

    -> Und den rest habe ich so wie im FAQ-Thread auch übernommen:

    //--- Includes -----------------------------------------------------
    
    #include "stdafx.h"
    
    //--- Gloabals -----------------------------------------------------
    
    #pragma data_seg( "shared" )
    HWND hWnd = 0;
    #pragma data_seg( )
    #pragma comment( linker, "/section:shared,RWS" )
    
    HHOOK hHook;
    HINSTANCE hInstDLL;
    
    //--- Prototypes ---------------------------------------------------
    
    LRESULT CALLBACK KeyboardProc( int, WPARAM, LPARAM );
    
    //--- DllMain ------------------------------------------------------
    
    int WINAPI DllMain( HINSTANCE hInstance, DWORD fdReason, PVOID pvReserved ) {
    
    	switch( fdReason ) {
    
    		case DLL_PROCESS_ATTACH: {
    
    			hInstDLL = hInstance;
    			break;
    		}
    
    		case DLL_THREAD_ATTACH: {
    
    			break;
    		}
    
    		case DLL_PROCESS_DETACH: {
    
    			break;
    		}
    
    		case DLL_THREAD_DETACH: {
    
    			break;
    		}
        return TRUE;
    }
    
    //--- Definitons ---------------------------------------------------
    
    // ***** This func set the global hook *****
    EXPORT BOOL CALLBACK InstallKbHook( HWND hWindow ) {
    
    	hWnd = hWindow;
    
    	hHook = SetWindowsHookEx( WH_KEYBOARD, KeyboardProc, hInstDLL, 0 );
    	return true;
    }
    
    // ***** This func remove the global hook *****
    EXPORT BOOL CALLBACK UnistallKbHook( ) {
    
    	UnhookWindowsHookEx( hHook );
    	return true;
    }
    
    // ***** This func is the message rotine *****
    LRESULT CALLBACK KeyboardProc( int nCode, WPARAM wParam, LPARAM lParam ) {
    
    	if( nCode == HC_ACTION ) {
    
    		SendMessage( hWnd, ( WM_USER + 2 ), wParam, lParam );
    	}
    	return( CallNextHookEx( hHook, nCode, wParam, lParam ) );
    }
    
    //--- EXIT ---------------------------------------------------------
    

    -> achja ich hab den eingefügten header in die stdafx.h gepackt, dürfte aber nicht relevant sein.

    Tjo und dann wollte ich das ganz mal Compilieren und das hatte ich nun davon:

    --------------------Configuration: KbHook - Win32 Debug--------------------
    Compiling...
    KbHook.cpp
    C:\Programme\Microsoft Visual Studio\MyProjects\Global KbHook\KbHook\KbHook.cpp(64) : error C2598: linkage specification must be at global scope
    C:\Programme\Microsoft Visual Studio\MyProjects\Global KbHook\KbHook\KbHook.cpp(64) : error C2601: 'InstallKbHook' : local function definitions are illegal
    C:\Programme\Microsoft Visual Studio\MyProjects\Global KbHook\KbHook\KbHook.cpp(73) : error C2598: linkage specification must be at global scope
    C:\Programme\Microsoft Visual Studio\MyProjects\Global KbHook\KbHook\KbHook.cpp(73) : error C2601: 'UnistallKbHook' : local function definitions are illegal
    C:\Programme\Microsoft Visual Studio\MyProjects\Global KbHook\KbHook\KbHook.cpp(80) : error C2601: 'KeyboardProc' : local function definitions are illegal
    C:\Programme\Microsoft Visual Studio\MyProjects\Global KbHook\KbHook\KbHook.cpp(91) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.
    
    KbHook.dll - 6 error(s), 0 warning(s)
    

    Ich weiß echt nicht wieso aber ich hoffe ihr könnts mir sagen und mir halfen.

    Gruß Tobi.



  • keiner ne idee?



  • wirklich niemand? oO



  • 😃 oO... ich habs jetzt
    wooah wie ich diese kleinen Fehler immer hasse eh ich die gefunden hab is immer Winachten... einmal ne Klammer vergessen und und einmal stat EXPOR, EXPROT getippt wo bei das den fahler nicht verursacht haett ^^


Anmelden zum Antworten