|
I have two different applications appDad and appKid. appDad is a Windows Forms Application and it calls appKid.exe. appKid does a series of prinf´s that I want to display in a text box in appDad.
Some suggest that I use FILE * output = _popen ("ls", "r") or freopen ("/dev/tty", "w", stdout) but I´m not quite sure what I´m doing.
Am I being lazy for asking instead of researching a bit more? I hope not...
|
|
|
|
|
See here and here.
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Ok, thanks a lot. But... is there a simpler way to do it in .NET?
|
|
|
|
|
piul wrote: But... is there a simpler way to do it in .NET?
.NET is a framework, not a language. If you are referring to Managed C++, see here.
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
How to get a CBitmap from a LPDIRECTDRAWSURFACE7 ?
modified on Thursday, January 27, 2011 10:10 AM
|
|
|
|
|
Try something like this:
1. Use IDirectDrawSurface7::GetSurfaceDesc[^] to get the dimensions of the surface.
2. Use IDirectDrawSurface7::GetDC[^] to get a device context for the surface
3. Use CBitmap::CreateCompatibleBitmap[^], specify the DC you got from the surface, you might use CDC:Attach[^] to get a CDC from the HDC, just don't forget to also Detach it before releasing the DC. The dimensions for your bitmap you got in step 2.
4. Create a DC compatible with the surface DC using CDC::CreateCompatibleDC[^]
5. Select the bitmap you created in step 3 into the DC you created in step 4. Do a bit-block-transfer with CDC::BitBlt[^] to move the pixel data from the DC you got in step 2 to the DC you got in step 4.
6. Deselect the bitmap (3) from the DC (4), destroy the DC (4)
7. Use IDirectDrawSurface7::ReleaseDC[^] to free up the DC you got in step 2.
8. Live happily ever after.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
Hi thx for the awnser.
I haven't got it to work yet a get an assertion error when calling CreateCompatibleBitmap()
Not sure I do the right thing when geting CDC object.
DDSURFACEDESC2 SurfaceDesc;
m_pDrawSurface->GetSurfaceDesc(&SurfaceDesc);
HDC sourceHDC = NULL;
m_pDrawSurface->GetDC(&sourceHDC);
CDC *pCDC = CDC::FromHandle(sourceHDC);
pCDC->Attach(sourceHDC);
CBitmap *cBmp;
cBmp->CreateCompatibleBitmap(pCDC,SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
CDC dcMemory;
dcMemory.CreateCompatibleDC(pCDC);
dcMemory.SelectObject(cBmp);
dcMemory.BitBlt(0,0,SurfaceDesc.dwWidth,SurfaceDesc.dwHeight,pCDC,0,0,SRCCOPY);
pCDC->Detach();
dcMemory.Detach();
dcMemory.DeleteDC();
m_pDrawSurface->ReleaseDC(sourceHDC);
|
|
|
|
|
Instead of this:
kagelind wrote: CDC *pCDC = CDC::FromHandle(sourceHDC);
pCDC->Attach(sourceHDC);
do this:
CDC surfaceCDC;
surfaceCDC.Attach(surfaceHDC);
Use &surfaceCDC everywhere you used pDC.
Then instead of this:
kagelind wrote: pCDC->Detach();
do this:
surfaceCDC.Detach();
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
also, instead of this:
kagelind wrote: CBitmap *cBmp;
cBmp->CreateCompatibleBitmap(pCDC,SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
do this:
CBitmap cBmp;
cBmp.CreateCompatibleBitmap(&surfaceCDC, SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
and use &cBmp everywhere you need its address.
Also, when you select the bitmap into the dcMemory, store its old CBitmap and select it back into the memory DC before destroying it or you might end up leaking handles. So something like:
CBitmap *originalBmp = dcMemory.SelectObject(&cBmp);
...do what you need...
dcMEmory.SelectObject(originalBmp);
dcMemory.DeleteDC();
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
The code runs now but don't seems to work.
DDSURFACEDESC2 SurfaceDesc;
m_pDrawSurface->GetSurfaceDesc(&SurfaceDesc);
HDC sourceHDC = NULL;
m_pDrawSurface->GetDC(&sourceHDC);
CDC SurfaceCDC;
SurfaceCDC.Attach(sourceHDC);
CBitmap cBmp;
cBmp.CreateCompatibleBitmap(&SurfaceCDC,SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
CDC dcMemory;
dcMemory.CreateCompatibleDC(&SurfaceCDC);
CBitmap * orginalBmp = dcMemory.SelectObject(&cBmp);
dcMemory.BitBlt(0,0,SurfaceDesc.dwWidth,SurfaceDesc.dwHeight,&SurfaceCDC,0,0,SRCCOPY);
SurfaceCDC.Detach();
dcMemory.SelectObject((HBITMAP)orginalBmp);
dcMemory.DeleteDC();
m_pDrawSurface->ReleaseDC(sourceHDC);
If I try to save the CBitmap a get an assertion error. It looks like the HBITMAP is NULL
CImage saveImage;
saveImage.Attach(cBmp);
saveImage.Save(_T("test.bmp"));
saveImage.Detach();
|
|
|
|
|
Does this succeed:
kagelind wrote: cBmp.CreateCompatibleBitmap(&SurfaceCDC,SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
?
This:
kagelind wrote: dcMemory.SelectObject((HBITMAP)orginalBmp);
is completely wrong, it should be:
dcMemory.SelectObject(orginalBmp);
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
|
Glad it works.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
I want to study how to write my compiler, so need a open source compiler for study.
The GCC is too big. is there simple compiler?
|
|
|
|
|
Have a look at:
- LCC[^] (consider buying the book).
- TCC[^].
A nice reading (oldie-goldie) is Let's Build a Compiler - by Jack Crenshaw[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I can strongly recommend that you read the Dragon Book[^]. Writing a compiler is both simple and really complex at the same time. This book guides you through language definition, lexical analysis, syntax analysis and finally code generation. It also has advanced sections for related technologies.
With this book as a guide, writing a simple compiler from scratch is not too much work, and gives a great understanding of languages and compilers. This is not really an answer to your question, but still...
|
|
|
|
|
I am currently trying to convert a string that resides in a _bstr_t variable vFieldDate into a char array. I have found that I can type cast this via the (char *) with a variable I named holder which is a pointer to a char. The issue I am having a hard time solving is how to convert this to a char that can be stored within the char Date[ARR]. When I attempt the following code I get the compilation error "Cannot Convert From Char * to Char. How do I extract the value that resides in the holder location and save it into the array?
Date[cyc] = holder;
The below portions of code are a part of an ADO program that is accessing data from a database.
char Date[ARR] = {};
_bstr_t vFieldDate;
vFieldDate = rec->Fields->GetItem("Date")->Value;
char *holder = (char*)vFieldDate;
|
|
|
|
|
This question has been anwered with:
#include <cstring>
//...
strcpy( Date, holder );
|
|
|
|
|
This will only work if he is using a wide string, in which case it would be wcscpy because BSTR is a wide string.
To copy a BSTR into an ASCII string, you will need to convert the character set.
|
|
|
|
|
Disregarding the method of conversion, the assignment you used attempts to assigns an array of characters to single character: Date is defined as an array of ARR characters, and Date[cyc] denotes the character with the index cyc within that array.
What was your intention? I suspect that what you really wanted is to define Date as an array of strings rather than as an array of characters. In this case you should define Date as char* Date[ARR]; .
On a sidenote, what you are trying to achieve is like pouring milk into a crate for beer bottles: you can't just go ahead and assign the contents of one variable to another variable that is designed to hold something completely different - doing this will usually result in spilling the contents. Instead you have to use the proper function or method for transfering the contents of one variable into the other. Plus you might need to allocate proper containers first: so first thing, pick up an empty beer bottle, then pour the milk into it, and only then you can put that bottle into the crate.
With respect to these strings, the Date array corresponds to the crate for beer bottles. The beer bottles correspond to char-strings, and the milk corresponds to the contents of that _bstr_t. So what you have to do is:
- allocate an array of char, big enough to hold the _bstr_t
- call the appropriate method to convert a _bstr_t into a char*, and then
- put it into the Date array.
|
|
|
|
|
Hello
I have some trouble interpreting a string and I hope you can help me.
I have to convert a string, or a word in a number. Like five hundred fifty in 550. I dont know exactly how to do it.
I was thinking to try to analize each word, but this seems like a huge code. Or i was thinking that maybe you can check in a table, but then the table should be huge(numbers should go up to millions)
Is there a smarter way? What do you suggest?
Thank you very much
|
|
|
|
|
There is a simpler way of doing it. In fact if you google it, you will see many examples on the web. Here [^] is one such example.
|
|
|
|
|
Here is an algorithm that should do it:
1. search for the words that indicate a power of 1000 (thousand, million, etc);
2. each of those delimit a number that ranges from 1 to 999; and for each of them:
3. search for "hundred", what is to the left of it has to be a digit; what is to the right of it has to be less than 100.
So you still need some code that deals with 1..99; and you may need to handle (ignore?) any "and" in the string.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
|
OS Version: Windows XP Pro
boost Version: 1.44.0
Hi,
I want to monitor, whether a certain process is running.
The program of the process is written in C++ and is
a console app.
I've chosen the mutex concept, because I want to restrict usage
of the program's main to exactly one thread.
First I used the example from the boost site, which places the scoped_lock
within the main routine's block. But when the app was terminated via
the close button of the console window
the scoped_lock destructor was not called
which had a negative side effect: The mutex is associated with a file
in the All Users\Application Data tree,
directory boost_interprocess
and if this file is not deleted, the mutex can not be acquired, although
it is no more referenced by any application.
Hence I wrapped the mutex into a global object
(1) to instantiate it as soon as possible
(2) to release it under as many circumstances of program termination as possible via
the wrapper's destructor.
This is the wrapper's class - you can see
the mutex is
non-blocking and
controlled via a scoped lock
<br />
struct ApplicationLock<br />
{<br />
ApplicationLock() : appmutex(open_or_create, "SilvaCoreMutex"), applock(appmutex, try_to_lock)<br />
{}<br />
bool alreadylocked()<br />
{<br />
return (applock == 0);<br />
}<br />
private:<br />
named_mutex appmutex;<br />
scoped_lock<named_mutex> applock;<br />
};<br />
<br />
ApplicationLock appliclock;<br />
If the console window is closed, the desctructor is called and
the mutex released. But if the process is terminated due
to a crash or aborted via the task manager,
the mutex is not released. Even a system restart doesn't release it.
I thought a mutex should
be held in a memory shared area and exclusively depend on this shared area
and never depend on anything which is stored in the file system.
How can I get rid of that mutex, when it is no more referenced
by any application. Have I chosen the wrong concept? Have I
misunderstood the boost mutex technique?
Thanks in advance
Werner
|
|
|
|