Problema Funcion Beep de kernel32.dll

Iniciado por dRak0, 23 Julio 2014, 02:07 AM

0 Miembros y 1 Visitante están viendo este tema.

dRak0

Que tal , estaba repasando un poco las funciones de kernel32 y , no se porque , no me funciona Beep.


#include <stdio.h>
#include <windows.h>

int main(int argc,char **argv)
{
typedef int (*punteroExitProcess)(UINT);
typedef int (*punteroBeep)(DWORD,DWORD);
typedef DWORD (*punteroGetCurrentProcessId)(void);
HMODULE dirKernel32=GetModuleHandle("kernel32.dll");
punteroExitProcess punteroExit=NULL;
punteroBeep punteroBep=NULL;
punteroGetCurrentProcessId GetCurrentProcessId2=NULL;
punteroExit=(punteroExitProcess)GetProcAddress(dirKernel32,"ExitProcess");
punteroBep=(punteroBeep)GetProcAddress(dirKernel32,"Beep");
GetCurrentProcessId2=(punteroGetCurrentProcessId)GetProcAddress(dirKernel32,"GetCurrentProcessId");
printf("Kernel32:%p\nExitProcess:%p\nBeep:%p\nGetCurrentProcessId:%p\n",dirKernel32,punteroExit,punteroBep,GetCurrentProcessId2);
printf("PID=%d\n",GetCurrentProcessId2());
punteroBep(1000,3000);
punteroExit(0);

}


Perdonen los nombres.La idea era obtener la direccion en memoria de kernel32 y jugar un poco con las funciones de este , a travez de punteros a funciones. Claro que hay formas mas faciles , solo era para repasar un poco.

Eternal Idol

#1
El codigo esta bien en principio y en mi maquina funciona, fijate cual es el estado del driver beep (sc query beep), tiene que estar cargado en memoria para que escuches el beep. Siempre comproba el retorno de las funciones y usa GetLastError donde corresponda.

Hay algo que deberias cambiar y es la convencion de llamada de los punteros a funcion, practicamente siempre deberia ser __stdcall (WINAPI) al ser la API de Windows (por defecto es C); eso lo consultas en la MSDN facilmente.

Trata de hacer coincidir el puntero a funcion, en su tipo de retorno, convencion de llamada y parametros. Ej.:

ExitProcess

typedef VOID (__stdcall *punteroExitProcess)(UINT);



Beep function

Remarks

A long time ago, all PC computers shared a common 8254 programable interval timer chip for the generation of primitive sounds. The Beep function was written specifically to emit a beep on that piece of hardware.

On these older systems, muting and volume controls have no effect on Beep; you would still hear the tone. To silence the tone, you used the following commands:

net stop beep

sc config beep start= disabled

Since then, sound cards have become standard equipment on almost all PC computers. As sound cards became more common, manufacturers began to remove the old timer chip from computers. The chips were also excluded from the design of server computers. The result is that Beep did not work on all computers without the chip. This was okay because most developers had moved on to calling the MessageBeep function that uses whatever is the default sound device instead of the 8254 chip.

Eventually because of the lack of hardware to communicate with, support for Beep was dropped in Windows Vista and Windows XP 64-Bit Edition.

In Windows 7, Beep was rewritten to pass the beep to the default sound device for the session. This is normally the sound card, except when run under Terminal Services, in which case the beep is rendered on the client.
La economía nunca ha sido libre: o la controla el Estado en beneficio del Pueblo o lo hacen los grandes consorcios en perjuicio de éste.
Juan Domingo Perón

dRak0

Cita de: Eternal Idol en 23 Julio 2014, 10:33 AM
El codigo esta bien en principio y en mi maquina funciona, fijate cual es el estado del driver beep (sc query beep), tiene que estar cargado en memoria para que escuches el beep. Siempre comproba el retorno de las funciones y usa GetLastError donde corresponda.

Hay algo que deberias cambiar y es la convencion de llamada de los punteros a funcion, practicamente siempre deberia ser __stdcall (WINAPI) al ser la API de Windows (por defecto es C); eso lo consultas en la MSDN facilmente.

Trata de hacer coincidir el puntero a funcion, en su tipo de retorno, convencion de llamada y parametros. Ej.:

ExitProcess

typedef VOID (__stdcall *punteroExitProcess)(UINT);



Beep function

Remarks

A long time ago, all PC computers shared a common 8254 programable interval timer chip for the generation of primitive sounds. The Beep function was written specifically to emit a beep on that piece of hardware.

On these older systems, muting and volume controls have no effect on Beep; you would still hear the tone. To silence the tone, you used the following commands:

net stop beep

sc config beep start= disabled

Since then, sound cards have become standard equipment on almost all PC computers. As sound cards became more common, manufacturers began to remove the old timer chip from computers. The chips were also excluded from the design of server computers. The result is that Beep did not work on all computers without the chip. This was okay because most developers had moved on to calling the MessageBeep function that uses whatever is the default sound device instead of the 8254 chip.

Eventually because of the lack of hardware to communicate with, support for Beep was dropped in Windows Vista and Windows XP 64-Bit Edition.

In Windows 7, Beep was rewritten to pass the beep to the default sound device for the session. This is normally the sound card, except when run under Terminal Services, in which case the beep is rendered on the client.


Gracias por la correccion, de ahora en mas pondre la convencion de llamada de la funcion,asi se limpia bien el stack.

Solucionado lo del beep.

Eternal Idol

La economía nunca ha sido libre: o la controla el Estado en beneficio del Pueblo o lo hacen los grandes consorcios en perjuicio de éste.
Juan Domingo Perón