Esap1,
Let me preface this by saying that I am not a Direct3D guru, but have some experience with COM.
The only thing that really jumped out at me was the fact that you were Querying an uninitialized interface pointer for itself..:
lpd3d->QueryInterface(IID_IDirect3D2, ...)
that line should read:
lpdd->QueryInterface(IID_IDirect3D2, (void**)&lpd3d)
Since you need to query the IDirectDraw interface for the IDirect3D interface.
As a side note, you might want to consider taking the time to create your own exception handling class, something that takes an HRESULT and maps it to a string definition of what went wrong.
HTH,
-mordell