Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C/C++ - Invalid conversion from `void*' to `WCHAR*'
Forum - C/C++ - Invalid conversion from `void*' to `WCHAR*'

Pagine: [ 1 2 ] Precedente | Prossimo
Avatar
fede.97 (Normal User)
Newbie


Messaggi: 7
Iscritto: 29/11/2012

Segnala al moderatore
Postato alle 19:47
Giovedì, 29/11/2012
Salve a tutti, sono nuovo al C e avrei un problemino con un codice trovato sulla rete per una applicazione nativa.
Io ho i due file
Native.c
Codice sorgente - presumibilmente Delphi

  1. //======================================================================
  2. //
  3. // Native.c
  4. //
  5. // Mark Russinovich
  6. // http://www.ntinternals.com
  7. //
  8. // This is a demonstration of a Native NT program. These programs
  9. // run outside of the Win32 environment and must rely on the raw
  10. // services provided by NTDLL.DLL. AUTOCHK (the program that executes
  11. // a chkdsk activity during the system boot) is an example of a
  12. // native NT application.
  13. //
  14. // This example is a native 'hello world' program. When installed with
  15. // the regedit file associated with it, you will see it print
  16. // "hello world" on the initialization blue screen during the system
  17. // boot. This program cannot be run from inside the Win32 environment.
  18. //
  19. //======================================================================
  20. #include "ntddk.h" // include this for its native functions and defn's
  21. #include "stdio.h"
  22. #include "native.h"
  23. //
  24. // Our heap
  25. //
  26. HANDLE Heap;
  27. //----------------------------------------------------------------------
  28. //
  29. // NtProcessStartup
  30. //
  31. // Instead of a 'main' or 'winmain', NT applications are entered via
  32. // this entry point.
  33. //
  34. //----------------------------------------------------------------------
  35. void NtProcessStartup( PSTARTUP_ARGUMENT Argument )
  36. {
  37.     PUNICODE_STRING commandLine;
  38.     PWCHAR stringBuffer, argPtr;
  39.     UNICODE_STRING helloWorld;
  40.     RTL_HEAP_DEFINITION  heapParams;
  41.     //
  42.     // Initialize some heap
  43.     //
  44.     memset( &heapParams, 0, sizeof( RTL_HEAP_DEFINITION ));
  45.     heapParams.Length = sizeof( RTL_HEAP_DEFINITION );
  46.     Heap = RtlCreateHeap() 2, 0, 0x100000, 0x1000, 0, &heapParams );
  47.     //
  48.     // Point at command line
  49.     //
  50.     commandLine = &Argument->Environment->CommandLine;
  51.     //
  52.     // Locate the argument
  53.     //
  54.     argPtr = commandLine->Buffer;
  55.     while( *argPtr != L' ' ) argPtr++;
  56.     argPtr++;
  57.     //
  58.     // Print out the argument
  59.     //
  60.     stringBuffer = RtlAllocateHeap( Heap, 0, 256 );
  61.     swprintf( stringBuffer, L"\n%s", argPtr );
  62.     helloWorld.Buffer = stringBuffer;
  63.     helloWorld.Length = wcslen( stringBuffer ) * sizeof(WCHAR);
  64.     helloWorld.MaximumLength = helloWorld.Length + sizeof(WCHAR);
  65.     NtDisplayString( &helloWorld );
  66.     //
  67.     // Free heap
  68.     //
  69.     RtlFreeHeap( Heap, 0, stringBuffer );
  70.     //
  71.     // Terminate
  72.     //
  73.     // COMMENTO NtTerminateProcess( NtCurrentProcess(), 0 );
  74. }


Native.h
Codice sorgente - presumibilmente Delphi

  1. //======================================================================
  2. //
  3. // Native.h
  4. //
  5. // Mark Russinovich
  6. // http://www.ntinternals.com
  7. //
  8. // This file includes the definitions required by the Native.exe sample
  9. // NT native program to do what it does.
  10. //
  11. //======================================================================
  12. //
  13. // Environment information, which includes command line and
  14. // image file name
  15. //
  16. typedef struct {
  17.        ULONG            Unknown[21];    
  18.        UNICODE_STRING   CommandLine;
  19.        UNICODE_STRING   ImageFile;
  20. } ENVIRONMENT_INFORMATION, *PENVIRONMENT_INFORMATION;
  21. //
  22. // This structure is passed as NtProcessStartup's parameter
  23. //
  24. typedef struct {
  25.        ULONG                     Unknown[3];
  26.        PENVIRONMENT_INFORMATION  Environment;
  27. } STARTUP_ARGUMENT, *PSTARTUP_ARGUMENT;
  28. //
  29. // Data structure for heap definition. This includes various
  30. // sizing parameters and callback routines, which, if left NULL,
  31. // result in default behavior
  32. //
  33. typedef struct {
  34. ULONG     Length;
  35. ULONG     Unknown[11];
  36. } RTL_HEAP_DEFINITION, *PRTL_HEAP_DEFINITION;
  37. //
  38. // Native NT api function to write something to the boot-time
  39. // blue screen
  40. //
  41. NTSTATUS
  42. NTAPI
  43. NtDisplayString(
  44.   PUNICODE_STRING String
  45.   );
  46. //
  47. // Native applications must kill themselves when done - the job
  48. // of this native API
  49. //
  50. NTSTATUS
  51. NTAPI
  52. NtTerminateProcess(
  53.      HANDLE ProcessHandle,
  54.      LONG ExitStatus
  55.      );
  56. //
  57. // Definition to represent current process
  58. //
  59. #define NtCurrentProcess() ( (HANDLE) -1 )
  60. //
  61. // Heap creation routine
  62. //
  63. HANDLE
  64. NTAPI
  65. RtlCreateHeap(
  66.        ULONG Flags,
  67.        PVOID BaseAddress,
  68.        ULONG SizeToReserve,
  69.        ULONG SizeToCommit,
  70.        PVOID Unknown,
  71.        PRTL_HEAP_DEFINITION Definition
  72.        );
  73. //
  74. // Heap allocation function (ala "malloc")
  75. //
  76. PVOID
  77. NTAPI
  78. RtlAllocateHeap(
  79.   HANDLE Heap,
  80.   ULONG Flags,
  81.   ULONG Size
  82.   );
  83. //
  84. // Heap free function (ala "free")
  85. //
  86. BOOLEAN
  87. NTAPI
  88. RtlFreeHeap(
  89.      HANDLE Heap,
  90.      ULONG Flags,
  91.      PVOID Address
  92.      );



Il problema si verifica quando vado a compilare, codeblocks mi restituisce:
Codice sorgente - presumibilmente C/C++

  1. error: invalid conversion from `void*' to `WCHAR*'


Aiutino? :)

PM Quote
Avatar
Bonny (Member)
Expert


Messaggi: 437
Iscritto: 24/04/2009

Segnala al moderatore
Postato alle 11:16
Venerdì, 30/11/2012
Nel file Native.c alla riga 55 siamo sicuri che questa istruzione vada scritta cosi:
Codice sorgente - presumibilmente Plain Text

  1. while( *argPtr != L' ' ) argPtr++;


penso che vada scritta cosi:
Codice sorgente - presumibilmente Plain Text

  1. while( *argPtr != 'L' ) argPtr++;


Ultima modifica effettuata da Bonny il 30/11/2012 alle 11:17
PM Quote
Avatar
fede.97 (Normal User)
Newbie


Messaggi: 7
Iscritto: 29/11/2012

Segnala al moderatore
Postato alle 13:27
Venerdì, 30/11/2012
Testo quotato

Postato originariamente da Bonny:

Nel file Native.c alla riga 55 siamo sicuri che questa istruzione vada scritta cosi:
Codice sorgente - presumibilmente Plain Text

  1. while( *argPtr != L' ' ) argPtr++;


penso che vada scritta cosi:
Codice sorgente - presumibilmente Plain Text

  1. while( *argPtr != 'L' ) argPtr++;

  


Grazie, intanto ho corretto :k:, purtroppo però l'errore non era quello.

PM Quote
Avatar
Bonny (Member)
Expert


Messaggi: 437
Iscritto: 24/04/2009

Segnala al moderatore
Postato alle 14:54
Venerdì, 30/11/2012
Scusa ma il compilatore non ti dice anche la riga in qui si trova l'errore?
postala grazie:)

PM Quote
Avatar
Bonny (Member)
Expert


Messaggi: 437
Iscritto: 24/04/2009

Segnala al moderatore
Postato alle 14:56
Venerdì, 30/11/2012
Anche a riga 61 c'è un errore di sintassi
Codice sorgente - presumibilmente Plain Text

  1. swprintf( stringBuffer, L"\n%s", argPtr );



Ultima modifica effettuata da Bonny il 30/11/2012 alle 14:56
PM Quote
Avatar
fede.97 (Normal User)
Newbie


Messaggi: 7
Iscritto: 29/11/2012

Segnala al moderatore
Postato alle 14:59
Venerdì, 30/11/2012
Certo che mi dice la riga! Che stupido a non postarla!8-|
Riga 60

Per l'errore: Non lo vedo, dove mancherebbe la virgola? :-|

PM Quote
Avatar
Bonny (Member)
Expert


Messaggi: 437
Iscritto: 24/04/2009

Segnala al moderatore
Postato alle 15:29
Venerdì, 30/11/2012
Cioè il secondo parametro non mi sembra scritto bene
Codice sorgente - presumibilmente Plain Text

  1. swprintf( stringBuffer, L"\n%s", argPtr );


PM Quote
Avatar
Bonny (Member)
Expert


Messaggi: 437
Iscritto: 24/04/2009

Segnala al moderatore
Postato alle 15:33
Venerdì, 30/11/2012
in riga 60 prova a sostituire con questo:
Codice sorgente - presumibilmente Plain Text

  1. stringBuffer = (WCHAR *) RtlAllocateHeap( Heap, 0, 256 );


PM Quote
Avatar
fede.97 (Normal User)
Newbie


Messaggi: 7
Iscritto: 29/11/2012

Segnala al moderatore
Postato alle 16:03
Venerdì, 30/11/2012
Vuoi che ci arrivi da solo per il parametro, giusto? :k:

Ho sostituito ed ora il debug restituisce
Codice sorgente - presumibilmente Delphi

  1. NATIVE.C||undefined reference to `_Z13RtlCreateHeapmPvmmS_P19RTL_HEAP_DEFINITION@24'|
  2. NATIVE.C||undefined reference to `_Z15RtlAllocateHeapPvmm@12'|
  3. NATIVE.C||undefined reference to `_Z15NtDisplayStringP15_UNICODE_STRING@4'|
  4. NATIVE.C||undefined reference to `_Z11RtlFreeHeapPvmS_@12'|
  5. NATIVE.C||undefined reference to `_Z18NtTerminateProcessPvl@8'|
  6. main.c||undefined reference to `WinMain@16'|
  7. ||=== Build finished: 6 errors, 0 warnings ===|



Ora devo studiare, dopo vedo di lavorarci per provare a risolvere da solo. Probabilmente sarò ancora qui a chiedere aiuto... :rofl:

PM Quote
Pagine: [ 1 2 ] Precedente | Prossimo