PlaySound() with DLL Injection

Hey guys,

I'm somewhat new to C++, and iv been interested in DLL Injection lately, and what I wanted to do was to load my DLL into a process and hopefully be able to play a sound with SoundPlay(). Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "windows.h"
#include "MMSystem.h"


bool tmp;

void SoundPlay();

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )


{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		MessageBox(NULL, L"Message Text", L"Message Title", MB_OK);
		tmp=PlaySound(L"C:\\mywavsound.wav", NULL, SND_FILENAME|SND_ASYNC);
		if (tmp) {
			MessageBox(NULL,L"true",L"title",MB_OK);
		}
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}


When injected, the MessageBox works, but when it hit's the PlaySound(), the process locks up. No return, or anything.

Help is greatly appreciated,

Thanks,
Starman4xz

Also: I made a similar program that uses PlaySound() as a Win32 console application, and it ran fine. Just the DLL version is not working.
Last edited on
Topic archived. No new replies allowed.