|
I have an older program written in C laguage. can i add a COM component to it, so that i may use its funtionality.
any sample is highly appreciated.
|
|
|
|
|
Is it C or C++ ? If it's C++, does it use the WIN32 API ?
|
|
|
|
|
I am using simple c language no c++, currently there is no win api's, but in the future there may or may not use api's.
|
|
|
|
|
Yes you can. Here is an example calling Microsoft's DirectX diagnostic utilities. The
interface IDxDiagProvider is a C++ class or a C structure. Here it is a C structure and the V-Table methods are called through the lpVtbl structure of function pointers. Also the pointer to the object it self is passed into the first parameter since there is no "this" pointer.
HRESULT hr;<br />
BOOL bCleanupCOM = FALSE;<br />
IDxDiagProvider* pDxDiagProvider = NULL;<br />
DXDIAG_INIT_PARAMS dxDiagInitParams;<br />
VARIANT var;<br />
char strDestination[10];<br />
<br />
hr = CoInitialize( NULL );<br />
<br />
bCleanupCOM = SUCCEEDED( hr );<br />
<br />
hr = CoCreateInstance( &CLSID_DxDiagProvider, NULL, CLSCTX_INPROC_SERVER,<br />
&IID_IDxDiagProvider, (void**)&pDxDiagProvider );<br />
<br />
if( SUCCEEDED( hr ) )<br />
{<br />
ZeroMemory( &dxDiagInitParams, sizeof( DXDIAG_INIT_PARAMS ) );<br />
<br />
dxDiagInitParams.dwSize = sizeof( DXDIAG_INIT_PARAMS );<br />
dxDiagInitParams.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION;<br />
dxDiagInitParams.bAllowWHQLChecks = FALSE;<br />
dxDiagInitParams.pReserved = NULL;<br />
<br />
hr = pDxDiagProvider->lpVtbl->Initialize( pDxDiagProvider, &dxDiagInitParams );
I hope this helps.
Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
|
|
|
|
|
|
I have a problem with drawing a non rectangular bitmap using a mask bitmap.
The two bitmaps are derived from an icon file in the resources. I want to create a HBITMAP object that contains the correct result of the masked drawing.
<br />
HICON hIcon5 = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON12));<br />
GetIconInfo(hIcon5, &iinfo);
BITMAP bm;<br />
GetObject(iinfo.hbmColor,sizeof(bm),&bm);<br />
<br />
HDC hdcToolbar = GetDC(hToolbar);
HDC hdcBitmap5 = CreateCompatibleDC(hdcToolbar);<br />
HDC hdcMask = CreateCompatibleDC(hdcToolbar) ;<br />
HDC hdcColor = CreateCompatibleDC(hdcToolbar) ;<br />
<br />
HBITMAP hBitmap5 = CreateCompatibleBitmap(hdcBitmap5,bm.bmWidth,bm.bmHeight);<br />
HGDIOBJ hOldBitmap5 = SelectObject(hdcBitmap5, hBitmap5);<br />
HGDIOBJ hOldMask = SelectObject(hdcMask, iinfo.hbmMask) ;<br />
HGDIOBJ hOldColor = SelectObject(hdcColor, iinfo.hbmColor);<br />
<br />
BitBlt (hdcBitmap5, 0, 0, bm.bmWidth,bm.bmHeight, NULL, 0, 0, WHITENESS);<br />
BitBlt (hdcBitmap5, 0, 0, bm.bmWidth,bm.bmHeight, hdcMask, 0, 0, 0x220326);
BitBlt (hdcBitmap5, 0, 0, bm.bmWidth,bm.bmHeight, hdcColor, 0, 0, SRCPAINT) ;<br />
<br />
SelectObject(hdcMask, hOldMask) ;<br />
SelectObject(hdcColor, hOldColor);<br />
SelectObject(hdcBitmap5, hOldBitmap5);<br />
DeleteDC(hdcMask);<br />
DeleteDC(hdcColor);<br />
DeleteDC(hdcBitmap5);<br />
ReleaseDC(hToolbar, hdcToolbar);<br />
Download the icon i used for the test here
Can someone help me please?
thanks in advance,
Ward
|
|
|
|
|
Why not just use DrawIcon() ?
Ward wrote: HBITMAP hBitmap5 = CreateCompatibleBitmap(hdcBitmap5,bm.bmWidth,bm.bmHeight);
At this point in your code hdcBitmap5 has a one by one pixel monchrome bitmap selected into it. When you create a compatible bitmap it will also be a monochrome bitmap. You should use hdcToolbar as the HDC for creating compatible bitmaps.
[blatant self-promotion]
Have a look at http://www.codeproject.com/tools/imageviewer.asp[^]
[/blatant self-promotion]
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Well, at first I've tried DrawIcon, but when I wanted to use the bitmap hBitmap5 as the bitmap for a toolbar button (used in TB_ADDBUTTON-message) the area which was supposed to be the background color of the toolbarbuttons, were turned in white.
I did found a solution last friday (at last). First I fill the hBitmap5 with the color of the toolbar buttons. The color of the toolbar buttons I was able to retreive using GetSysColor. Then I used the DrawIcon on this hBitmap5. And finally I passed this hBitmap5 to the toolbar with the TB_ADDBUTTON-message.
The final result is now exact what I wanted.
Anyway, thanks for your reply.
kind regards,
Ward
-- modified at 16:09 Sunday 25th December, 2005
|
|
|
|
|
I am making an Application analyzer.
It involves analyzing menu structure of an application too.
For acrobat reader it doesn't return any text for a menu. I am getting the menu items correctly but no text. So tree nodes are empty. I guess it could be because it is "ownerdrawn" (not me;P).
But For Visual studio 2003 GetMenu returns NULL.
For Other windows it's working fine. For eg: Yahoo messenger.
Any ideas why this's happening.
Happy christmas friends. May the Love of My Lord and Saviour Jesus bring forth Joy and Happiness into your life too.
<marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" hspace="2" vspace="2">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
-- modified at 6:29 Thursday 22nd December, 2005
|
|
|
|
|
Hi all,
What is the difference between _tcscpy and lstrcpy?
Is there any advantage for _tcscpy or lstrcpy by means of speed, memory usage, etc. compare to other?
Thank you.
- NS -
|
|
|
|
|
|
Yes, exactly.
I know _tcscpy will become wcscpy, strcpy or _mbscpy with character setting (_UNICODE, _MBCS, tc).
But I would like to know that, what is the advantage of one over another?
- NS -
|
|
|
|
|
Here is a crazy one I discovered while investigating some shoddy source code : If you pass an invalid pointer into lstrcpy, it will 'silently' throw an accessviolation exception which it will then catch, and continue on its merry way
The _tcscpy will probably directly cause an unhandled access violation in similar circumstances.
No shirt, no shoes, no brains, no service.
-- modified at 11:41 Thursday 22nd December, 2005
|
|
|
|
|
Thank you.
This makes the lstrcpy better than _tcscpy... to write better programs!
Thank you once again.
- NS -
|
|
|
|
|
NS17 wrote: _tcscpy or lstrcpy
offcourse lstrcpy is better as it reduce the dependency of runtime c library.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
|
lstrcpy is a function of Windows API and _tcscpy is from C Runtime Library. This is the basic difference. Otherwise, both resolve to same things.
lstrcpyA does the same job as strcpy. lstrcpyW does the same job as wcscpy. (So lstrcpy does the same job as _tcscpy.) It's useful to use lstrXXX if you feel the need to eliminate the C library entirely.
Ahh... I didnt see Alok's reply. He had already said this.
-- modified at 0:59 Friday 23rd December, 2005
|
|
|
|
|
Thank you.
Please see the post of Blake Miller, which is also very significant.
- NS -
|
|
|
|
|
HI
I have written some class for learning and understanding ... but i got lost
At the beginning i learned "templates" the use of Iterators
Now i like to combine these Methodes
<br />
#if !defined(_TQUEUE_H_)<br />
#define _TQUEUE_H_<br />
<br />
<br />
typedef struct CPointPlus<br />
{<br />
CPoint m_punkt;<br />
int m_attribut;<br />
float m_freq;<br />
}CPointPlus;<br />
<br />
template <typename T><br />
class TQueue <br />
{<br />
public:<br />
typedef struct tqueue<br />
{<br />
struct tqueue *next;<br />
T entry;<br />
struct tqueue *prev;<br />
}tqueue;<br />
<br />
TQueue();<br />
virtual ~TQueue();<br />
<br />
void gethead();<br />
void gettail();<br />
void push(T*);<br />
T* getnext();<br />
T* get();<br />
void destroy();<br />
<br />
class Iterator;<br />
friend class Iterator;<br />
<br />
long counter(){return m_count;}<br />
private:<br />
long m_count;<br />
tqueue *first;<br />
tqueue *last;<br />
};<br />
<br />
template <typename T><br />
class TQueue<T>::Iterator<br />
{<br />
public:<br />
Iterator(TQueue &tq):g(tq)<br />
{}<br />
~Iterator()<br />
{}<br />
void reset()<br />
{<br />
aktuell = first;<br />
}<br />
void next()<br />
{<br />
if(aktuell)<br />
{<br />
tqueue *alt=aktuell;<br />
aktuell = alt->next;<br />
}<br />
}<br />
void prev()<br />
{<br />
if(aktuell)<br />
{<br />
tqueue *alt=aktuell;<br />
aktuell = alt->prev;<br />
}<br />
}<br />
T* get()<br />
{<br />
if(aktuell)<br />
return aktuell->eintrag;<br />
return NULL;<br />
}<br />
private:<br />
TQueue &q;<br />
tqueue* aktuell;<br />
};<br />
<br />
The cpp for TQueue is working fine ...
Now how to change the cpp part of Iterator to write this into TQueue.cpp??
And how to call the Iterator ??
<br />
TQueue<CPointPlus>::Iterator it(queue);<br />
is not working...
THX
LOL
T
-- modified at 6:15 Thursday 22nd December, 2005
|
|
|
|
|
Moin,
if you want to rewrite the STL's queue, the iterator should be used as follows:
TQueue<CPointPlus>::Iterator PointIter;
And then you could use it in a for-loop as follows:
for(PointIter = queue.begin(); PointIter != queue.end(); PointIter++)
{
}
I hope that gets you back on track. And if you have worked with the STL before, have a look at my problem and give me some hints
Der Weg ist das Ziel
For everyone not speaking German (in order to better understand tbrakes code):
Aktuell = current, actual
Alt = old
Punkt = point
The german comment says: overwrite at current pointer and move to next.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
-- modified at 7:41 Thursday 22nd December, 2005
|
|
|
|
|
HI
THX but using
<br />
TQueue::Iterator PointIter;<br />
Tells me template argumentlist missing
and
<br />
TQueue<CPointPlus>>::Iterator PointIter;<br />
tells me undefiened class Iterator
And now ??
THX T
|
|
|
|
|
I took it that you were trying - for training - to rewrite a simple "STL-like" queue and wanted to provide an "STL-like" Iterator for it.
If I had a STL vector like
std::vector<int> myIntVector;
then I would declare my iterator as follows:
std::vector<int>::iterator myIntIterator;
and use it in a for-loop in this manner:
for(myIntIterator = myIntVector.begin(); myIntIterator != myIntVector.end(); myIntIterator++)
{
std::cout << *myIntIterator << std::endl;
}
Ich denke einfach, du hast mehr davon, wenn du selbst drauf kommst.
Edit: Sorry, I didnt notice the board dropping the <tags>.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
-- modified at 7:40 Thursday 22nd December, 2005
|
|
|
|
|
Hi
Fine... Iterators themself are not hte problem and using stl is not the problem too.
But I like to know to manage my special QUEUE double linked template class with my own special ITERATOR for dynamic queues holding about 3.000.000 entries (each QUEUE) no arrays used!!!
Please tell my how to manage.
Ein Synonym für "kann ich nicht" lautet "trivial" oder "das bleibt dem Leser überlassen" ...
CU T
|
|
|
|
|
Sry, this has to be written in German. There was an musunderstanding.
Hallo tbrake,
Das ist auf keinen Fall trivial. Aber das wollte ich auch nicht ausdrücken. Was ich dir mitteilen wollte war: warum schaust du dir die STL nicht an? Es gibt genug C++ Standard Libraries, die im Quelltext verfügbar sind.
Ich wollte auf keinen Fall den Eindruck vermitteln, ich hielte mich für etwas Besseres. Ich hatte einfach unglaublich gute Laune (und dachte, das käme so rüber, sorry) und wollte dir vermitteln, dass du genug Quellen hast, um dein Problem zu lösen. Deswegen kam die Abkürzung STL auch so häufig in meinen Posts vor.
Das war nicht böse gemeint, und es tut mir leid, das du es so verstanden hast.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Hi
1.
my Solution for Iterator...
<br />
template <class T><br />
class TQueue <br />
{<br />
public:<br />
<br />
typedef struct tqueue<br />
{<br />
struct tqueue *next;<br />
T eintrag;<br />
struct tqueue *prev;<br />
}tqueue;<br />
<br />
<br />
<br />
class Iterator<br />
{<br />
public:<br />
Iterator(TQueue<T> &tq):q(tq) {}<br />
~Iterator() {}<br />
void reset() {aktuell = q.getfirst();}<br />
void next()<br />
{<br />
if(aktuell)<br />
{<br />
tqueue *alt=aktuell;<br />
aktuell = alt->next;<br />
}<br />
}<br />
void prev()<br />
{<br />
if(aktuell)<br />
{<br />
tqueue *alt=aktuell;<br />
aktuell = alt->prev;<br />
}<br />
}<br />
T* get()<br />
{<br />
if(aktuell)<br />
return &(aktuell->eintrag);<br />
return NULL;<br />
}<br />
private:<br />
TQueue<T> &q;<br />
tqueue* aktuell;<br />
};<br />
<br />
<br />
<br />
TQueue();<br />
virtual ~TQueue();<br />
<br />
void gethead();<br />
void gettail();<br />
void push(T*);<br />
T* getnext();<br />
T* getprev();<br />
T* prev();<br />
T* get();<br />
void destroy();<br />
<br />
<br />
tqueue *getfirst(){return first;}<br />
<br />
long counter(){return m_count;}<br />
public:<br />
long m_count;<br />
tqueue *curr;<br />
tqueue *last;<br />
protected:<br />
tqueue *first;<br />
};<br />
This is working :->
Not written the way i like to have it .. but working (so far)
2.
MeTo in orefull german
Wollte Dir auch nicht Deine Laune miesmachen ... sitze jetzt aber schon ein paar Stunden an diesem Problem ... Leider kann ich auch nicht so einfach auf stl umsteigen ... Habe hier ca 300 Klassen mit je 1000 Zeilen Code ... und dann ist es am einfachsten wenn Du es einfach nur erweiterst ...
Schwamm darüber ... es funst !!!
THX
CU
Timen
|
|
|
|
|