Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: noele1995 en 15 Julio 2012, 22:34 pm



Título: [Solucionado]Ayuda pruebas con DLLs
Publicado por: noele1995 en 15 Julio 2012, 22:34 pm
Bueno estaba haciendo ciertas pruebas creando dlls y llamandolas implicitamente y explicitamente para aprender un poco y ahora que le he puesto algunos argumentos me ejecuta la funcion de dll pero despues de ejecutarla me salta este error:

Código:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.
This is usually a result of calling a function declared with one calling convention with a function
pointer declared with a different calling convention.

El codigo del programa llamador es el siguiente:

main.cpp
Código
  1. #include <Windows.h>
  2. #include <iostream>
  3.  
  4. typedef void (__stdcall *PROC_info)(char *,char *,long *,long *);
  5.  
  6. struct PLUGIN
  7. {
  8. HMODULE dll_entrypoint;
  9. PROC_info info_func;
  10. };
  11.  
  12. int main()
  13. {
  14.  
  15. PLUGIN plugin1;
  16.  
  17. plugin1.dll_entrypoint = LoadLibraryA("C:\\Dll-Test1.dll");
  18. if(plugin1.dll_entrypoint == NULL)
  19. {
  20. FreeLibrary(plugin1.dll_entrypoint);
  21. MessageBoxA(0,"No se encuentra la DLL","Error",0);
  22. return 1;
  23. }
  24. else{
  25. char *Version = "";
  26. char *Autor = "";
  27. long *numAutor = 0;
  28. long *numVersion = 0;
  29.  
  30.  
  31. plugin1.info_func = (PROC_info)GetProcAddress(plugin1.dll_entrypoint,"func1");
  32.  
  33. plugin1.info_func(Version,Autor,numVersion,numAutor);
  34. FreeLibrary(plugin1.dll_entrypoint);
  35. }
  36. system("pause");
  37.  
  38. return 0;
  39. }

Y el codigo de la DLL

plugin_main.h
Código
  1. #define DLLDEXPORT  __declspec(dllexport)   // export DLL information
  2.  
  3. extern "C" {
  4.       DLLDEXPORT void func1(char *, char *,long *,long *);
  5. };
  6.  
  7.  


plugin_main.cpp
Código
  1. #include "plugin_main.h"
  2. #include <windows.h>
  3.  
  4. BOOL APIENTRY DllMain(HMODULE hModule,DWORD  ul_reason_for_call,LPVOID lpReserved){
  5. switch (ul_reason_for_call)
  6. {
  7. case DLL_PROCESS_ATTACH: //PROCESO CARGA
  8. break;
  9. case DLL_THREAD_ATTACH: //THREAD CARGA
  10. break;
  11. case DLL_THREAD_DETACH: //THREAD DESCARGA
  12. break;
  13. case DLL_PROCESS_DETACH: //PROCESO DESCARGA
  14. break;
  15. }
  16. return TRUE;
  17. }
  18.  
  19. DLLDEXPORT void func1(char *Version, char *Autor,long *numVersion,long *numAutor)
  20. {
  21. MessageBoxA(0,"Soy el texto","Soy el caption",1);
  22. }


Si alguien me ayuda seria genial ya que despues de frustrarme para que ejecute la funcion ahora me saltan errores.



Pff siento las molestias resulto ser una tonteria...
Lo arregle cambiando en la declaracion de PROC_Info el __stdcall por un __cdecl

Saludos, Noele1995