MessageBox



  • Hallo zusammen,
    ich habe ein Probelm beim erzeugen einer MessageBox.
    folgender Code:

    #pragma once
    
    namespace Hook_Form {
    	#include "stdafx.h"
    	#include <windows.h>
        #include "..\Hook Dll\Hook.h"
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    
    	/// <summary>
    	/// Summary for Form1
    	///
    	/// WARNING: If you change the name of this class, you will need to change the
    	///          'Resource File Name' property for the managed resource compiler tool
    	///          associated with all .resx files this class depends on.  Otherwise,
    	///          the designers will not be able to interact properly with localized
    	///          resources associated with this form.
    	/// </summary>
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Add the constructor code here
    			//
    		}
    
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Button^  install_button;
    	private: System::Windows::Forms::Button^  uninstall_button;
    	protected: 
    
    	protected: 
    
    	private:
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		System::ComponentModel::Container ^components;
    
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			this->install_button = (gcnew System::Windows::Forms::Button());
    			this->uninstall_button = (gcnew System::Windows::Forms::Button());
    			this->SuspendLayout();
    			// 
    			// install_button
    			// 
    			this->install_button->Location = System::Drawing::Point(342, 92);
    			this->install_button->Name = L"install_button";
    			this->install_button->Size = System::Drawing::Size(75, 23);
    			this->install_button->TabIndex = 0;
    			this->install_button->Text = L"Install";
    			this->install_button->UseVisualStyleBackColor = true;
    			this->install_button->Click += gcnew System::EventHandler(this, &Form1::install_button_Click);
    			// 
    			// uninstall_button
    			// 
    			this->uninstall_button->Location = System::Drawing::Point(341, 154);
    			this->uninstall_button->Name = L"uninstall_button";
    			this->uninstall_button->Size = System::Drawing::Size(75, 23);
    			this->uninstall_button->TabIndex = 1;
    			this->uninstall_button->Text = L"UnInstall";
    			this->uninstall_button->UseVisualStyleBackColor = true;
    			this->uninstall_button->Click += gcnew System::EventHandler(this, &Form1::uninstall_button_Click);
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(807, 661);
    			this->Controls->Add(this->uninstall_button);
    			this->Controls->Add(this->install_button);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->ResumeLayout(false);
    
    		}
    #pragma endregion
    	private: System::Void install_button_Click(System::Object^  sender, System::EventArgs^  e) 
    		 {
    			 MessageBox("Hallo");
    			 InstallHooks();
    		 }
    	private: System::Void uninstall_button_Click(System::Object^  sender, System::EventArgs^  e) 
    		{
    			UnInstallHooks();
    		 }
    	};
    }
    

    ergibt folgenden Fehler:

    Error	1	error C2660: 'Hook_Form::MessageBox' : function does not take 1 arguments	c:\documents and settings\mw\my documents\visual studio 2005\projects\maus hook\hook_form\Form1.h	108
    

    Kann mir jemand helfen?



  • MessageBox::Show("Test", "Überschrift", MessageBoxButtons::OK, MessageBoxIcon::Exclamation );
    


  • Super, danke!
    Kannst DU mir auch sagen, warum ich in anderen Anwendungen die MB so aufrufen kann, wie ich es probiert habe?
    Was muss ich machen, außer
    #include <windows.h>???



  • Wollte das ganz nun in einer DLL machen:

    #define MAKE_DLL
    
    // INCLUDES //////////////////////////////////////////////////////////////
    
    #include <windows.h>
    #include <fstream>
    
    #include "Hook.h"
    
    // DEFINES ///////////////////////////////////////////////////////////////
    
    // CONSTANTS /////////////////////////////////////////////////////////////
    
    // GLOBALS ///////////////////////////////////////////////////////////////
    
    #pragma data_seg ("shared")
    //int iNumInstances = 0;
    int iKeystrokes[255] = {0};
    #pragma data_seg ()
    #pragma comment(linker,"/SECTION:shared,RWS")
    
    // PROTOTYPES ////////////////////////////////////////////////////////////
    
    LRESULT CALLBACK MouseHookProc(int, WPARAM, LPARAM);
    void OutputKeystrokes();
    
    // VARIABLES /////////////////////////////////////////////////////////////
    
    HINSTANCE	hDllInstance;
    HHOOK		hMouseHook;
    
    // METHODS ///////////////////////////////////////////////////////////////
    
    // FUNCTIONS /////////////////////////////////////////////////////////////
    
    int APIENTRY DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
    {
    	hDllInstance = hInstance;
    
    	return TRUE;
    }
    
    BOOL CALLBACK InstallHooks(void)
    {
    	MessageBox::Show("Test");
    	hMouseHook = SetWindowsHookEx(WH_MOUSE,
                                         MouseHookProc,
                                         hDllInstance,
                                         NULL
                                         );
    
        if (hMouseHook == NULL)
        {
            return FALSE;
        }
    
        return TRUE;
    }
    
    BOOL CALLBACK UnInstallHooks(void)
    {
        OutputKeystrokes();
    
        return UnhookWindowsHookEx(hMouseHook);
    }
    
    LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam,LPARAM lParam)
    {
    	if(nCode < 0)
    		return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
    
        // Verhindern das eine Nachricht mehrmals verarbeitet wird.
    	if(nCode == HC_ACTION)
        {
            // Prüfen ob die Taste nicht gedrückt gehalten wurde.
            // Wenn dies der Fall ist, ist das 31. Bit _nicht_ gesetzt.
            if (!(lParam&0x40000000))
            {
                // VK-Code als Index in ein Array, dessen Eintrag
                // pro Druck um eins erhöht wird.
                iKeystrokes[wParam]++;
            }
        }
    
    	return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
    }
    
    void OutputKeystrokes()
    {
        std::ofstream out("c:\\mousehook.txt");
    
        for (int i='A'; i<='Z'; i++)
        {
            out << (char)i << " = " << iKeystrokes[i] << "\n";
        }
    }
    

    Fehler:

    Error	1	error C2653: 'MessageBoxA' : is not a class or namespace name	c:\documents and settings\mw\my documents\visual studio 2005\projects\maus hook\hook dll\hook.cpp	56
    Error	2	error C3861: 'Show': identifier not found	c:\documents and settings\michael worobcuk\my documents\visual studio 2005\projects\maus hook\hook dll\hook.cpp	56
    

    Währe für nochmalige Hilfe dankbar...



  • Wenn Du <windows.h> einbindest, dann wird hier ein "define" für "MessageBox" eingebunden ,was dann diverse Verwirrungen auslösen kann.
    Deshalb vorher (also *nach* dem #include <windows.h>) ein

    #undef MessageBox
    

    machen, damit es wieder eindeutig wird...



  • Hi,
    nun also:

    #define MAKE_DLL
    
    // INCLUDES //////////////////////////////////////////////////////////////
    
    #include <windows.h>
    #undef MessageBox;
    #include <fstream>
    
    #include "Hook.h"
    
    // DEFINES ///////////////////////////////////////////////////////////////
    
    // CONSTANTS /////////////////////////////////////////////////////////////
    
    // GLOBALS ///////////////////////////////////////////////////////////////
    
    #pragma data_seg ("shared")
    
    // iNumInstances = 0;
    HHOOK hMouseHook =0;
    int iKeystrokes[255] = {0};
    #pragma data_seg ()
    #pragma comment(linker,"/SECTION:shared,RWS")
    
    // PROTOTYPES ////////////////////////////////////////////////////////////
    
    LRESULT CALLBACK MouseHookProc(int, WPARAM, LPARAM);
    void OutputKeystrokes();
    
    // VARIABLES /////////////////////////////////////////////////////////////
    
    HINSTANCE	hDllInstance;
    
    // METHODS ///////////////////////////////////////////////////////////////
    
    // FUNCTIONS /////////////////////////////////////////////////////////////
    
    int APIENTRY DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
    {
    	hDllInstance = hInstance;
    
    	return TRUE;
    }
    
    BOOL CALLBACK InstallHooks(void)
    {
    	MessageBox::("Test");
    	if (hMouseHook  ==0) hMouseHook = SetWindowsHookEx(WH_MOUSE, MouseHookProc, hDllInstance, NULL);
    
        if (hMouseHook == NULL)
        {
            return FALSE;
        }
    
        return TRUE;
    }
    
    BOOL CALLBACK UnInstallHooks(void)
    {
        OutputKeystrokes();
    
        return UnhookWindowsHookEx(hMouseHook);
    }
    
    LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam,LPARAM lParam)
    {
    	std::ofstream out("c:\\mousehook.txt");
    	if(nCode < 0) return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
    
    //	out << (char)lParam-> << "\n";
    
    	return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
    }
    
    void OutputKeystrokes()
    {
        /*
    
        for (int i='A'; i<='Z'; i++)
        {
            out << (char)i << " = " << iKeystrokes[i] << "\n";
        }*/
    }
    

    Das ergibt:

    Error	2	error C3861: 'MessageBox': identifier not found	c:\documents and settings\mw\my documents\visual studio 2005\projects\maus hook\hook dll\hook.cpp	59
    


  • Was willst Du jetzt eigentlich machen?
    Windows-Forms oder native Win32 ???

    In Deinem ersten Beispiel war es noch

    MessageBox::Show
    

    und jetzt plötzlich nicht mehr...

    Also, ganz simple Regel:
    Windows-Forms (also C++/CLI), dann

    #undef MessageBox
    

    Win32-API:
    (kein undef)



  • Auch bei einem

    MessageBox::Show("Test");
    

    kommt:

    Error	2	error C2653: 'MessageBox' : is not a class or namespace name	c:\documents and settings\mw\my documents\visual studio 2005\projects\maus hook\hook dll\hook.cpp	59
    Error	3	error C3861: 'Show': identifier not found	c:\documents and settings\mw\my documents\visual studio 2005\projects\maus hook\hook dll\hook.cpp	59
    

    auch bei einem

    #undef MessageBox
    

    Ich checks leider nicht... 😕


Anmelden zum Antworten