473,382 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

D3DXSaveSurfaceToFile() does not exist under C#!

This is really starting to piss me off. Someone please prove me wrong.

Here is a link to the function in DX 9 sdk.
http://msdn.microsoft.com/library/de...facetofile.asp

Following dll's are referenced in my program.
Microsoft.DirectX.dll
Microsoft.DirectX.Direct3D.dll
Microsoft.DirectX.Direct3DX.dll

The code:

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
..
..
//here trying to call D3DXSaveSurfaceToFile
//the parameters are wrong but thats not the problem
D3DXSaveSurfaceToFile();

The eror I get: "The name does not exist in MainFrom..." bla bla

In other words, I cannot locate the function. Where is it?
Please help.

If it helps, here is the link to what I am trying to do. The only
problem the link is in C++.
http://www.codeproject.com/dialog/sc...doing%20it%20:

Thanks in advance.
Nov 16 '05 #1
11 5331
"Nick" <pa*****@optonline.net> wrote in message
news:QA*****************@news4.srv.hcvlny.cv.net.. .
This is really starting to piss me off. Someone please prove me wrong.

Here is a link to the function in DX 9 sdk.
http://msdn.microsoft.com/library/de...facetofile.asp
Following dll's are referenced in my program.
Microsoft.DirectX.dll
Microsoft.DirectX.Direct3D.dll
Microsoft.DirectX.Direct3DX.dll

The code:

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
.
.
//here trying to call D3DXSaveSurfaceToFile
//the parameters are wrong but thats not the problem
D3DXSaveSurfaceToFile();

The eror I get: "The name does not exist in MainFrom..." bla bla

In other words, I cannot locate the function. Where is it?
Please help.

If it helps, here is the link to what I am trying to do. The only
problem the link is in C++.

http://www.codeproject.com/dialog/sc...doing%20it%20:

You will have to use interop to call API methods in the dll. There are
plenty of examples on the net, I suggest you check google or codeproject.
The idea is to map the entries in the dll (the ones you need) to a C#
equivalent method, and call the mapped methods.

HTH,
---
Tom Tempelaere
Nov 16 '05 #2
TT (Tom Tempelaere) wrote:
"Nick" <pa*****@optonline.net> wrote in message
news:QA*****************@news4.srv.hcvlny.cv.net.. .
This is really starting to piss me off. Someone please prove me wrong.

Here is a link to the function in DX 9 sdk.


http://msdn.microsoft.com/library/de...facetofile.asp
Following dll's are referenced in my program.
Microsoft.DirectX.dll
Microsoft.DirectX.Direct3D.dll
Microsoft.DirectX.Direct3DX.dll

The code:

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
.
.
//here trying to call D3DXSaveSurfaceToFile
//the parameters are wrong but thats not the problem
D3DXSaveSurfaceToFile();

The eror I get: "The name does not exist in MainFrom..." bla bla

In other words, I cannot locate the function. Where is it?
Please help.

If it helps, here is the link to what I am trying to do. The only
problem the link is in C++.


http://www.codeproject.com/dialog/sc...doing%20it%20:

You will have to use interop to call API methods in the dll. There are
plenty of examples on the net, I suggest you check google or codeproject.
The idea is to map the entries in the dll (the ones you need) to a C#
equivalent method, and call the mapped methods.

HTH,
---
Tom Tempelaere


I'm sorry if I am missing something, but how do I know the C# equivalent
method? The only documentation of the method that I found is in C++.

The following is from the header file d3dx9tex.h, which is part of dx 9 sdk.

//----------------------------------------------------------------------------
// D3DXSaveSurfaceToFile:
// ----------------------
// Save a surface to a image file.
//
// Parameters:
// pDestFile
// File name of the destination file
// DestFormat
// D3DXIMAGE_FILEFORMAT specifying file format to use when saving.
// pSrcSurface
// Source surface, containing the image to be saved
// pSrcPalette
// Source palette of 256 colors, or NULL
// pSrcRect
// Source rectangle, or NULL for the entire image
//
//----------------------------------------------------------------------------

HRESULT WINAPI
D3DXSaveSurfaceToFileA(
LPCSTR pDestFile,
D3DXIMAGE_FILEFORMAT DestFormat,
LPDIRECT3DSURFACE9 pSrcSurface,
CONST PALETTEENTRY* pSrcPalette,
CONST RECT* pSrcRect);

HRESULT WINAPI
D3DXSaveSurfaceToFileW(
LPCWSTR pDestFile,
D3DXIMAGE_FILEFORMAT DestFormat,
LPDIRECT3DSURFACE9 pSrcSurface,
CONST PALETTEENTRY* pSrcPalette,
CONST RECT* pSrcRect);

#ifdef UNICODE
#define D3DXSaveSurfaceToFile D3DXSaveSurfaceToFileW
#else
#define D3DXSaveSurfaceToFile D3DXSaveSurfaceToFileA
#endif

-------------------------------------------------------------------------------

I would really apreciate it if you could help me get this function to work.

This is what I have so far.

[DllImport("Direct3DX.dll",EntryPoint="D3DXSaveSurf aceToFile")]
//I have no clue about the last two arguments so I left them out, they
//can be null, but I still need a C# equivalent.
//ImageFileFormat I basically guessed, so dont know if thats the right
//equivalent to D3DXIMAGE_FILEFORMAT
//I'm pretty sure that HRESULT in C# is Int32
//and LPCSTR is String
static extern Int32 D3DXSaveSurfaceToFile(String
pDestFile,ImageFileFormat DestFormat,Surface pSrcSurface);

//and then use it as
D3DXSaveSurfaceToFile("2.bmp",ImageFileFormat.Bmp, mySurface);

The program doesn't crash or anything, but 2.bmp is not there. =(

Also, I tried running "tdump Direct3DX.dll" and the funtions were not
listed.

Thank you for the help.
Nov 16 '05 #3
"Nick" <pa*****@optonline.net> wrote in message
news:_f*******************@news4.srv.hcvlny.cv.net ...
TT (Tom Tempelaere) wrote:
"Nick" <pa*****@optonline.net> wrote in message
news:QA*****************@news4.srv.hcvlny.cv.net.. .
This is really starting to piss me off. Someone please prove me wrong.

Here is a link to the function in DX 9 sdk.

http://msdn.microsoft.com/library/de...facetofile.asp
Following dll's are referenced in my program.
Microsoft.DirectX.dll
Microsoft.DirectX.Direct3D.dll
Microsoft.DirectX.Direct3DX.dll

The code:

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
.
.
//here trying to call D3DXSaveSurfaceToFile
//the parameters are wrong but thats not the problem
D3DXSaveSurfaceToFile();

The eror I get: "The name does not exist in MainFrom..." bla bla

In other words, I cannot locate the function. Where is it?
Please help.

If it helps, here is the link to what I am trying to do. The only
problem the link is in C++.


http://www.codeproject.com/dialog/sc...doing%20it%20:
You will have to use interop to call API methods in the dll. There are
plenty of examples on the net, I suggest you check google or codeproject. The idea is to map the entries in the dll (the ones you need) to a C#
equivalent method, and call the mapped methods.

HTH,
---
Tom Tempelaere


I'm sorry if I am missing something, but how do I know the C# equivalent
method? The only documentation of the method that I found is in C++.

The following is from the header file d3dx9tex.h, which is part of dx 9

sdk.
//--------------------------------------------------------------------------
-- // D3DXSaveSurfaceToFile:
// ----------------------
// Save a surface to a image file.
//
// Parameters:
// pDestFile
// File name of the destination file
// DestFormat
// D3DXIMAGE_FILEFORMAT specifying file format to use when saving.
// pSrcSurface
// Source surface, containing the image to be saved
// pSrcPalette
// Source palette of 256 colors, or NULL
// pSrcRect
// Source rectangle, or NULL for the entire image
//
//--------------------------------------------------------------------------
--
HRESULT WINAPI
D3DXSaveSurfaceToFileA(
LPCSTR pDestFile,
D3DXIMAGE_FILEFORMAT DestFormat,
LPDIRECT3DSURFACE9 pSrcSurface,
CONST PALETTEENTRY* pSrcPalette,
CONST RECT* pSrcRect);

HRESULT WINAPI
D3DXSaveSurfaceToFileW(
LPCWSTR pDestFile,
D3DXIMAGE_FILEFORMAT DestFormat,
LPDIRECT3DSURFACE9 pSrcSurface,
CONST PALETTEENTRY* pSrcPalette,
CONST RECT* pSrcRect);

#ifdef UNICODE
#define D3DXSaveSurfaceToFile D3DXSaveSurfaceToFileW
#else
#define D3DXSaveSurfaceToFile D3DXSaveSurfaceToFileA
#endif

-------------------------------------------------------------------------- -----
I would really apreciate it if you could help me get this function to work.
This is what I have so far.

[DllImport("Direct3DX.dll",EntryPoint="D3DXSaveSurf aceToFile")]
//I have no clue about the last two arguments so I left them out, they
//can be null, but I still need a C# equivalent.
//ImageFileFormat I basically guessed, so dont know if thats the right
//equivalent to D3DXIMAGE_FILEFORMAT
//I'm pretty sure that HRESULT in C# is Int32
//and LPCSTR is String
static extern Int32 D3DXSaveSurfaceToFile(String
pDestFile,ImageFileFormat DestFormat,Surface pSrcSurface);

//and then use it as
D3DXSaveSurfaceToFile("2.bmp",ImageFileFormat.Bmp, mySurface);

The program doesn't crash or anything, but 2.bmp is not there. =(

Also, I tried running "tdump Direct3DX.dll" and the funtions were not
listed.

Thank you for the help.


You will have to map the functions you use from the API, which includes
mapping of parameters & return values (aka marshalling). Also structs used
in the API should be mapped, which involves memory-layout and packing
specifications. The problem is that the dll you use is not written for .NET
or C# (If I Read Correctly) but for C/C++. Then there is no choice but to
use interoperability features in .NET if you want to use the dll. Check for
articles on the net, e.g. google, or http://www.codeproject.com or
http://www.codeguru.com. There are plenty.

Otherwise, try to find a .NET assembly which does the same. I don't make
programs that use DirectX directly, so I can't help you with that.

HTH,
---
Tom Tempelaere
Nov 16 '05 #4
"Nick" <pa*****@optonline.net> wrote in message
news:_f*******************@news4.srv.hcvlny.cv.net ...
TT (Tom Tempelaere) wrote: [...] Also, I tried running "tdump Direct3DX.dll" and the funtions were not
listed.


You could use Dependeny Walker to check the API signature. But that doesn't
reveal packing...

---
Tom Tempelaere
Nov 16 '05 #5
Version 2.1.3623 of dependency walker allows to view C++ mangling
undecorated which might come in handy. But I suspect the dll is targeted for
C.

---
Tom Tempelaere
"TT (Tom Tempelaere)" <_|\|_0§P@|/\|titi____AThotmail.com|/\|@P§0_|\|_>
wrote in message news:YD**********************@phobos.telenet-ops.be...
"Nick" <pa*****@optonline.net> wrote in message
news:_f*******************@news4.srv.hcvlny.cv.net ...
TT (Tom Tempelaere) wrote: [...]
Also, I tried running "tdump Direct3DX.dll" and the funtions were not
listed.


You could use Dependeny Walker to check the API signature. But that

doesn't reveal packing...

---
Tom Tempelaere

Nov 16 '05 #6
TT (Tom Tempelaere) wrote:
"Nick" <pa*****@optonline.net> wrote in message
news:QA*****************@news4.srv.hcvlny.cv.net.. .
This is really starting to piss me off. Someone please prove me wrong.

Here is a link to the function in DX 9 sdk.


http://msdn.microsoft.com/library/de...facetofile.asp
Following dll's are referenced in my program.
Microsoft.DirectX.dll
Microsoft.DirectX.Direct3D.dll
Microsoft.DirectX.Direct3DX.dll

The code:

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
.
.
//here trying to call D3DXSaveSurfaceToFile
//the parameters are wrong but thats not the problem
D3DXSaveSurfaceToFile();

The eror I get: "The name does not exist in MainFrom..." bla bla

In other words, I cannot locate the function. Where is it?
Please help.

If it helps, here is the link to what I am trying to do. The only
problem the link is in C++.


http://www.codeproject.com/dialog/sc...doing%20it%20:

You will have to use interop to call API methods in the dll. There are
plenty of examples on the net, I suggest you check google or codeproject.
The idea is to map the entries in the dll (the ones you need) to a C#
equivalent method, and call the mapped methods.

HTH,
---
Tom Tempelaere


I found a workaround for that funtion.
Here is the code:

try
}
//seting up a D3D device
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed=true;
presentParams.SwapEffect = SwapEffect.Discard;

Device myDevice = new
Device(0,DeviceType.Hardware,this,CreateFlags.Soft wareVertexProcessing,
presentParams);

//creating a Surface the size of screen
Surface mySurface =
myDevice.CreateOffscreenPlainSurface(SystemInforma tion.PrimaryMonitorSize.Width,SystemInformation.Pr imaryMonitorSize.Height,Format.A8R8G8B8,Pool.Defau lt);

//this is where the runtime error occurs, not necessarily the real
//problem. Not sure about first parameter.
myDevice.GetFrontBufferData(0,mySurface);

//from this point on works
//with GetFrontBufferData commented out this saves a bitmap with random
//noise. I guess whatever the Surface object had in memory at its
//location gets translated into noise.
GraphicsStream myGraphicsStream = mySurface.LockRectangle(LockFlags.None);

Bitmap dxWholeScreenBitmap = new
Bitmap(SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height,System Information.PrimaryMonitorSize.Width,PixelFormat.F ormat32bppArgb,myGraphicsStream.InternalData);

dxWholeScreenBitmap.Save("2.bmp");

}
catch(Exception ex){MessageBox.Show(ex.ToString());}

So instead of letting DirectX do the file saving, which I would need
D3DXSaveSurfaceToFile for, I am copying the data from Surface to bitmap
directly. This parameter in bitmap constructor is the stride of the
bitmap. I'm not sure how to get it yet but thats not the problem so far.
So if you know whats wrong with this code, please let me know.

Also, I tried opening Direct3DX.dll in Dependency Walker (nice program)
and unfortunately no functions are being listed in it. When I open some
other dll, like user32.dll, it has several functions. I guess that means
that direct3dx.dll is for C, right?

You've been tremendous help. Thank you.
Nov 16 '05 #7
"Nick" <pa*****@optonline.net> wrote in message
news:Rx********************@news4.srv.hcvlny.cv.ne t...
[...]
So instead of letting DirectX do the file saving, which I would need
D3DXSaveSurfaceToFile for, I am copying the data from Surface to bitmap
directly. This parameter in bitmap constructor is the stride of the
bitmap. I'm not sure how to get it yet but thats not the problem so far.
So if you know whats wrong with this code, please let me know.
If you have new problems, I suggest you start a new thread. I don't know too
much of what you're doing.
Also, I tried opening Direct3DX.dll in Dependency Walker (nice program)
and unfortunately no functions are being listed in it. When I open some
other dll, like user32.dll, it has several functions. I guess that means
that direct3dx.dll is for C, right?
I don't really know.
You've been tremendous help. Thank you.


No probs,
---
Tom Tempelaere
Nov 16 '05 #8
"TT (Tom Tempelaere)" <_|\|_0§P@|/\|titi____AThotmail.com|/\|@P§0_|\|_>
wrote in message news:A7**********************@phobos.telenet-ops.be...
"Nick" <pa*****@optonline.net> wrote in message
news:Rx********************@news4.srv.hcvlny.cv.ne t...
[...]
Also, I tried opening Direct3DX.dll in Dependency Walker (nice program)
and unfortunately no functions are being listed in it. When I open some
other dll, like user32.dll, it has several functions. I guess that means
that direct3dx.dll is for C, right?


I don't really know.


Actually I know that it is targeted towards C compilers, but you can't
deduce that from dependency walker. But if yuo the entries then normally you
should be able to use interoperability and map the function to a .NET
callable syntax.

Cheers,
---
Tom Tempelaere
Nov 16 '05 #9
"TT (Tom Tempelaere)" <_|\|_0§P@|/\|titi____AThotmail.com|/\|@P§0_|\|_>
wrote in message news:e9**********************@phobos.telenet-ops.be...
"TT (Tom Tempelaere)" <_|\|_0§P@|/\|titi____AThotmail.com|/\|@P§0_|\|_>
wrote in message news:A7**********************@phobos.telenet-ops.be...
"Nick" <pa*****@optonline.net> wrote in message
news:Rx********************@news4.srv.hcvlny.cv.ne t...

[...] Actually I know that it is targeted towards C compilers, but you can't
deduce that from dependency walker. But if yuo the entries then normally you

But if you know the API entries ...
should be able to use interoperability and map the function to a .NET
callable syntax.


Tom T.
Nov 16 '05 #10
Nick wrote:
This is really starting to piss me off. Someone please prove me wrong.

Here is a link to the function in DX 9 sdk.
http://msdn.microsoft.com/library/de...facetofile.asp
Following dll's are referenced in my program.
Microsoft.DirectX.dll
Microsoft.DirectX.Direct3D.dll
Microsoft.DirectX.Direct3DX.dll

The code:

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
.
.
//here trying to call D3DXSaveSurfaceToFile
//the parameters are wrong but thats not the problem
D3DXSaveSurfaceToFile();

The eror I get: "The name does not exist in MainFrom..." bla bla

In other words, I cannot locate the function. Where is it?
Please help.

If it helps, here is the link to what I am trying to do. The only
problem the link is in C++.
http://www.codeproject.com/dialog/sc...doing%20it%20:
Thanks in advance.


Finally got it to work. Here is the code.

try
{

//basic D3D device initialization
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
Device myDevice = new
Device(0,DeviceType.Hardware,this,CreateFlags.Soft wareVertexProcessing,presentParams);

//create a surface the size of screen (has to be the size of screen)
//format had to be A8R8G8B8, because that is what GetFrontBufferData returns
//last argument has to be either Pool.Scratch or Pool.System memory
Surface mySurface =
myDevice.CreateOffscreenPlainSurface(SystemInforma tion.PrimaryMonitorSize.Width,SystemInformation.Pr imaryMonitorSize.Height,Format.A8R8G8B8,Pool.Syste mMemory);

//Get the front buffer.
//Getting backbuffer or rendertarget does not work when capturing
//the desctop. I assume these are good if you are doing some rendering
//in your application. When used here file is saved as ~320x20 pixel noise.
myDevice.GetFrontBufferData(0,mySurface);

//this is the function I was looking for and it saves any surface to file
SurfaceLoader.Save("1.bmp",ImageFileFormat.Bmp,myS urface);

}
catch{}
Some interesting bits of info:
-If you want to know what kind of functions are included in lets say
Direct3DX.dll go to *your windows dir*\Microsoft.NET\Managed
DirectX\v9.00.1126(*version of dx*)\.
Here are located the directx dll's that you reference in your program
along with .xml files with corresponding file names. The xml files list
all functions and their arguments, as well as short descriptions, inside
the dll's in managed code.
-The front buffer that GetFrontBufferData returns surprisingly is *NOT*
the stuff you see on the screen. For most applications it would
work, but when, for example, I run a divx video and take a screenshot,
an interesting thing happens. Lets suppose the video is still playing, I
open the resulting screenshot and in the place where the video was
running there is either blackness or the video continues running (yes
video running inside an image, I'm sure). Once you close the video the
place in the image stays permanently black.
Workarounds:
-display properties, settings, advanced, trobleshoot, set acceleration
to none and take the screen shot.
-Programmatically this is the only feasable thing I came across.
http://www.codeproject.com/audio/capvidscrn.asp (c++)
-Another way but not quite relable. Disabling video acceleration
through registry.
http://groups.google.com/groups?hl=e...phx.gbl&rnum=9
(also c++)

Sorry for the amount of irrelavant info to the newsgroup, but google
searches it all and I know some of this info was hard to find. =)
Nov 16 '05 #11
Hi Nick,

I think you may be looking for SurfaceLoader.Save

Cheers,
Marty

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: jeanfor | last post by:
I get a http 500 error on all asp pages. When turning off the friendly message box, the message is "Class does not exist". What is the fix for that? This affect all asp pages incling the default...
2
by: adam | last post by:
hello What query shoul I send to SQL serwer ( in transact SQL language ) to check does some database exist on serwer ? It similar to problem "does some table exist in database" - resolve to it...
0
by: Dirk Försterling | last post by:
Hi all, a few days ago, I upgraded from PostgreSQL 7.2.1 to 7.4, following the instructions in the INSTALL file, including dump and restore. All this worked fine without any error (message). ...
3
by: Olivogt | last post by:
Hello, I was just puting an application on the web server but it did not work as usual... - I do develop on my notebook and move released applications to the Web server - both have Sql Server...
52
by: paytam | last post by:
Hi all Can anyone tell me how can I check that a file exist or no.I mean when you use this commands FILE *fp; if(!fp) //Could not open the file doen't show why it can not open it,may be the...
3
by: Mike | last post by:
Thanks for the reply, I have been trying that, but I keep getting the same results. The result I get is that the file exits, when it really doesn't. All my msgbox display twice and I'm not sure...
1
by: Atia Amin | last post by:
Hi, I am a new member. Hello to every one. I am new in ASP.NET area. I wrote an ASP.NET web application which was running ok with my old laptop. Currently I have given a new laptop. Now I copied...
11
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG'...
3
by: moltendorf | last post by:
I copied the files from my "test" database on my old server (MySQL was not running) to my new server ("./mysql/data/test" folder), and after starting the server, SHOW TABLES; shows all of the tables...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.