|
Maybe posting code...
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
|
|
|
|
|
|
I read that article but still i am not able to find the bug in my code. here is my code
CDC dcMem;
CBitmap bmpMem;
CBitmap *oldbm = NULL;
CDC dc;
HDC hdc = ::GetDC(m_pOcxItem->m_hWnd);
dc.Attach(hdc);
LPVOID lpvBits = NUL
// save the device context
int nHandle = ::SaveDC(hDC);
// create a memory device context for offscreen drawing
if (!dcMem.CreateCompatibleDC(&dc))
_com_issue_error(HRESULT_FROM_WIN32(::GetLastError()));
if (!bmpMem.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height()))
_com_issue_error(HRESULT_FROM_WIN32(::GetLastError()));
oldbm = dcMem.SelectObject(&bmpMem);
dcMem.SelectObject((HBRUSH)GetStockObject(WHITE_BRUSH));
// delesect the device dependent bitmap from the offscreen device context (must be out when GetDIBits is called)
dcMem.SelectObject(oldbm);
// get the header structure for a device independent bitmap (DIB) setup with the biggest possible palette
BITMAPINFO *bmi = (BITMAPINFO *) _alloca(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
memset(&bmi->bmiHeader, 0, sizeof(BITMAPINFOHEADER));
bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
// query for the bitmap information (NULL does a query)
int scanLineCount = GetDIBits(dcMem, bmpMem, 0, rect.Height(), NULL, bmi, DIB_RGB_COLORS);
if (!scanLineCount)
_com_issue_error(HRESULT_FROM_WIN32(::GetLastError()));
//here this is giving one of the parameter is incorrect
With the same code my another bitmap is getting printed with black background.
Any help is appreciated.
|
|
|
|
|
What happens if you change two lines of your code to this:
dcMem.CreateCompatibleDC(GetDC())
bmpMem.CreateCompatibleBitmap(GetDC(), rect.Width(), rect.Height()))
|
|
|
|
|
But GetDC() returns a HWND parameter where as CreateCompabileDC expect CDC* value
|
|
|
|
|
Are you sure? GetDC()//it returns CDC*
|
|
|
|
|
No GetDC returns HDC whereas createcompatable takes CDC pointer
|
|
|
|
|
No its not ture.
CDC dc*;
dc=GetDC();
HDC hdc;
hdc=::GetDC(HWND);
|
|
|
|
|
I made small modifications to your code and passed my window hwnd but the result is same. one of the parameter is incorrect
|
|
|
|
|
Can you tell me what do you want to do?
|
|
|
|
|
I know this is not the forum. I am printing activex controls. I was not able to print them. Last week i posted the problem in com forum. I found the solution. we have 4 legacy activex controls. out of them i am able to print two of them. One is raising one of the parameter is incorrect and another is printing with black background image. This is my problem.
|
|
|
|
|
Is it possible for you to print your bitmaps without any activex controls?
|
|
|
|
|
i found in the msdn GetDIBits returns zero if the header information is incorrect
BITMAPINFO *bmi = (BITMAPINFO *) _alloca(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
memset(&bmi->bmiHeader, 0, sizeof(BITMAPINFOHEADER));
bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
int scanLineCount = GetDIBits(dcMem, bmpMem, 0, rect.Height(), NULL, bmi, DIB_RGB_COLORS);
the value of bmi->bmiHeader.biSize is 40 while debugging.
what i have to do to pass the correct header information
|
|
|
|
|
|
Thanks for the article. But that didn't help. My code is working well for two activex controls but for another it is returning invalid argument(GetDIBits). I am assuming that i have to do something in the activex control. What i have to do in that. That i don't know. If any one knows please help me.
|
|
|
|
|
Hi,
I have vector<string>
and I want to have char**.
Is there any elegant way?
|
|
|
|
|
a vector of what is it ?
and why do you want to regress back to char** ?
|
|
|
|
|
Oh, Sorry for incomplete information.
I have a vector of strings
e.q. vector<<string>>
|
|
|
|
|
you didn't replied the second part of my question :
"and why do you want to regress back to char** ?"
BTW, you could do something like this, but I seriously doubt about the need of this:
std::vector<std::string> v;
size_t n = v.size();
char** str_arr = ::new char*[n];
int i = 0;
for (vector<string>::iterator it = v.begin(); it != v.end(); it++, i++) {
str_arr[i] = ::new char[(it->length())+1];
::strcpy(str_arr[i], it->c_str());
}
of course, don't forget to free all that memory allocated, otherwise, you're leading into memory leaks...
modified on Thursday, May 22, 2008 9:30 AM
|
|
|
|
|
I am using a legacy API which needs char** as [in] parameter.
Thanks for suggesting this solution.
I guess there is one typo
<br />
char** str_arr = new char*[n];<br />
Is there any other quick soln exists?
|
|
|
|
|
vikrams wrote: I guess there is one typo
you're totally right, I fixed it in my previous post.
vikrams wrote: Is there any other quick soln exists?
I sorted this one from the top of my head, but i doubt you'll find better/shorter solutions for this.
BTW, check that you're API needs or not a trailing nul ('\0') character at the end of the char* array (the one called str_arr ). if so, you'll have to change my code. if not, it's probably expecting an integer with the array size; that's what n is storing.
|
|
|
|
|
Thanks for quick response. I have working implementation of this type. But I was curious if any other soln exists.
|
|
|
|
|
Well, if the legaci API uses strings strictly as IN parameters then you have to option to drop the string copy operations.
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
|
|
|
|
|
CPallini wrote: Well, if the legaci API uses strings strictly as IN parameters then you have to option to drop the string copy operations.
hu, what ???
|
|
|
|
|
exactly.
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
|
|
|
|