|
I think the D3D10LoadTexureformTexure() will be the right answer. But it is very slow.It is not a best answer but a right one.
|
|
|
|
|
Hi everyone.
Recently i'm working on a project which is to record games. Some trouble comes to me, for d3d10 and d3d11. I can hook the Present() through IDXGISwapChain:
PFN_D3D10_CREATE_DEVICE_AND_SWAP_CHAIN1 pDirect3DCreate10 = (PFN_D3D10_CREATE_DEVICE_AND_SWAP_CHAIN1)GetProcAddress("D3D10CreateDeviceAndSwapChain1");
if (pDirect3DCreate10 == NULL)
{
return false;
}
IDXGISwapChain * pSwapChain;
ID3D10Device1 * pDevice;
HRESULT hRet = pDirect3DCreate10(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_FEATURE_LEVEL_9_1,
D3D10_1_SDK_VERSION, &swapChainDesc, &pSwapChain, &pDevice);
if (FAILED(hRet))
{
return false;
}
UINT_PTR* pVTable = (UINT_PTR*)(*((UINT_PTR*)pSwapChain));
m_nDX10_Present = pVTable[8];
m_nDX10_ResizeTarget = pVTable[14];
Using VTable to get the address. And I can save backbuffer. But when change game's size, the game will crash. It seems change size wouldn't go to ResizeTarget(). So I want to ask:
1. When the game change size for d3d10_1.dll, what does he do, and what should I do?
2. There is other question, when the game exit, what should i do. i want to stop my project when the game is exit.
Thanks for any advices. I'm a newer in directx. There are so many publishs for directx, i.e d3d9, d3dx9_43, d3d10, d3d10_1, d3d11, d3d11_1 and so on. 
modified 19-Jul-13 0:53am.
|
|
|
|
|
I find when resize game's window it will call IDXGISwapChain()->ResizeBuffers(). I can hook ResizeBuffers(). And it also crash(the game is stablish, cant move any more.).I dont konw what should i do? please help!
|
|
|
|
|
Hello,
I am trying to call a GUI function from a worker thread in a Doc/View application in MFC in VS2008. It was working fine on XP 32bit, but throws error in Windows 7 32bit.
I am calling the following function within a worker thread-
parent->UpdateAllViews(NULL);
The error that it throws is at Line 900 in wincore.cpp which is
ASSERT(pMap != NULL);
Also my other function which was working fine under XP is giving fatal error
AfxGetMainWnd()->PostMessage(WM_CLOSE, 0, 0);
The above function is also called in the same worker thread.
Any suggestions/ideas?
thanks
PKNT
|
|
|
|
|
Every normal gui framework is single threaded that means: you can access gui related data and functions only from the gui thread (that is the main thread in case of MFC). Its only blind luck that your app worked on WinXP most of the time. Multithreaded programs become quite non-deterministic and the same is true for the occurrence/reproduction of their bugs. Now you are "lucky" that you have a quite reliable repro case for your bug that was a bug even on WinXP!
1. AfxGetMainWnd() is a gui related call so I would call it only from the main/gui thread. Call AfxGetMainWnd() from the gui thread when you create the worker thread and pass the window pointer to the thread as a CreateParam. Since SendMessage() and PostMessage() are thread safe WinAPIs the same is true for the SendMessage() and PostMessage() methods of the window.
2. On the worker thread use the PostMessage() or SendMessage() method on the window pointer you received as a ThreadCreateParam. PostMessage(WM_CLOSE, 0, 0) should work if you use directly the window pointer without AfxGetMainWnd().
3. To call UpdateAllViews() do the following: Define your own window message. Either WM_APP+(0..1000 or whatever) or WM_USER+... Then use again PostMessage() on the window pointer to post your own window message. In the message map of your window receive your user defined message with ON_MESSAGE(WM_MYMESSAGE, OnMyMessageMethod). Your OnMyMessageMethod() will be called from the gui thread so it will be safe to call UpdateAllViews() from there. Use PostMessage() instead of SendMessage() if you don't want the worker thread to block until the end execution of OnMyMessageMethod() on the gui thread.
BTW: Here is the implementation of AfxGetMainWnd() of VS2010:
_AFXWIN_INLINE CWnd* AFXAPI AfxGetMainWnd()
{ CWinThread* pThread = AfxGetThread();
return pThread != NULL ? pThread->GetMainWnd() : NULL; }
If your worker thread was created with non-mfc api then this AfxGetMainWindow() returns NULL always if called from your worker thread.
|
|
|
|
|
Passing a window pointer between threads is not a good idea in MFC.
Instead, you must pass the window handle behind the pointer.
You can convert the handle to a pointer using the CWnd::FromHandle static method.
Rest of the things are spot on.
|
|
|
|
|
If you can guarantee that the lifetime of the window spans that of the worker thread activity (and it does since it is the main window) then its OK to pass the pointer but it has no advantage over your solution because PostMessage and SendMessage is available in both cases.
|
|
|
|
|
Thanks for your reply. Probably I should show how I am currently defining my thread and how I am using it.
Declaration:
static DWORD WINAPI ThreadProcess(LPVOID pParam);
Definition:
DWORD WINAPI CMainDoc::ThreadProcess(LPVOID pParam)
{
CMainDoc *parent = (CMainDoc *)pParam;
while(TRUE) {
switch(::WaitForSingleObject(2, parent->m_eMsg, FALSE, INFINITE)) { case WAIT_OBJECT_0:
parent->UpdateAllViews(NULL);
break;
case WAIT_OBJECT_1: pObject->PostMessage(WM_CLOSE, 0, 0);
break;
}
}
Now if I do the way you suggested, do I need to send the handle returned from AfxGetMainWnd() along with a pointer to the document in 'pParam'?
PKNT
|
|
|
|
|
If you don't call MFC functions from your worker thread (its best not to call them) then its OK to go with non MFC threads so the kind of your thread doesn't matter. As I see you have already used up your pParam to send the doc pointer. You can send any number of parameters to your thread this way:
struct MyThreadParamStruct
{
CMainDoc* parent;
CWnd* mainwnd;
};
void StartThreadTask()
{
MyThreadParamStruct* thread_param = new MyThreadParamStruct;
CreateThread(..., thread_param, ...)
...
}
DWORD WINAPI CMainDoc::ThreadProcess(LPVOID pParam)
{
std::unique_ptr<MyThreadParamStruct> thread_param((MyThreadParamStruct*)pParam);
...
}
|
|
|
|
|
Looks like std::unique_ptr is not defined in VS2008. I got it working using standard form like
ThreadNetMsgParamStruct *pThreadParams = (ThreadNetMsgParamStruct *)pParam;
But the problem is, a CDocument class can not process windows messages. Is there any other straight forward way to replicate UpdateAllViews() command without calling it directly?
thanks
PKNT
|
|
|
|
|
unique_ptr is like std::auto_ptr (its younger brother in stl). It deletes the pointer automatically when it goes out of scope (in this case at the end of the function or if you return from the func). The struct instance must be deleted otherwise you cause a memory leak. You have to send a message to a window and not to a document object. If you can't solve the problem using the info I provided (theory + 90% of the code needed) then either ask a colleague to do it for you or start learning about multithreading+gui and their relationship.
|
|
|
|
|
Kiran Satish wrote: I am trying to call a GUI function from a worker thread... Bad idea. See here for why.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Just dont do it. Think of your thread as being in a different process, how would you communicate between them? With PostMessage and SendMessage. So create some custom IDs, handle them in your main window proc and post or send using those IDs from the thread.
You have to keep it clean on Windows, you cant bodge stuff. It might work for a bit, but eventually it will break.
|
|
|
|
|
Thanks, that's exactly how I did it over the weekend and it works well.
PKNT
|
|
|
|
|
Hi there,
Is there a way to disallow users from pasting anything to CEdit box control?
Right now they can right click and select the PASTE menu option.
And also do a Control + V.
How to disable this?
please give some sample code.
Thanks in advance.
|
|
|
|
|
|
Oh, but he said "Please give me some code". Are you sure he can handle a link? It might involve thinking....
|
|
|
|
|
Erudite_Eric wrote: might involve thinking
If 99% of the people asking questions here actually put forth any effort in thinking, then 99% of the questions would disappear.... 
|
|
|
|
|
Here you go:
<pre> if (add_uevent_var(env,
"MODALIAS=usb:"
"v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X",
le16_to_cpu(copy_dev->descriptor.idVendor),
le16_to_cpu(copy_dev->descriptor.idProduct),
le16_to_cpu(copy_dev->descriptor.bcdDevice),
copy_dev->descriptor.bDeviceClass,
copy_dev->descriptor.bDeviceSubClass,
copy_dev->descriptor.bDeviceProtocol,
alt->desc.bInterfaceClass,
alt->desc.bInterfaceSubClass,
alt->desc.bInterfaceProtocol))
return -ENOMEM;
modified 18-Jul-13 9:11am.
|
|
|
|
|
Hi,
I'm using wofstream to write text to a file
my problem is that, with any level of optimization, neither write() or << allows me to write a wstring or c string in the form of (WCHAR*).
example
WCHAR* str = new WCHAR[MAX_PATH];
wcscpy(str, L"walk");
myfile.write(str, wcslen(str));
No string written to file
wstring str2 = L"walk";
myfile << str2;
No string written to file
I am able to to do
myfile << "String";
how do I fix?
|
|
|
|
|
Unfortunately you don't. The wstream types take wide characters in but write them out as normal ASCII. You should use the old C-style fwrite or the newer WriteFile functions which allow you to specify the output character size.
Use the best guess
|
|
|
|
|
so wofstream can't be optimized? it all works well without optimization
|
|
|
|
|
doug25 wrote: so wofstream can't be optimized? it all works well without optimization Sorry, I don't understand what you are saying here. As far as Irecall from all the tests I have run, you cannot write wide characters via a wstream. I would be interested to see the code you have that does work. In the meantime I will retry my own tests.
Use the best guess
|
|
|
|
|
sorry, I've discovered what was happening, it isn't a problem with wstring optimazation. I was converting the file to another format the functions i'm using behave differently with optimization.
The problem is nothing to do with vectors or wstrings. it's a directx set of functions i'm using that fail when optimazation is turned on. It was difficult to determine tat this was where the program was failing.
modified 17-Jul-13 12:17pm.
|
|
|
|
|
doug25 wrote: the functions i'm using behave differently with optimization. I find that very difficult to believe. Much more likely is that you have a bug somewhere that only shows when you have optimization turned on.
Use the best guess
|
|
|
|