|
|
It can be done with VBScript object (ProgID - VBScript) and its IActiveScript**** interfaces. Especially, IActiveScriptParse.
CComPtr< IActiveScript > spScript;
HRESULT hr = spScript.CoCreateInstance( OLESTR("VBScript") );
if( SUCCEEDED(hr) )
{
CComQIPtr< IActiveScriptParse > spParser( spScript );
if( spParser )
{
hr = spScript->SetScriptSite( spScriptSite );
hr = spParser->InitNew();
hr = spScript->SetScriptState( SCRIPTSTATE_STARTED );
hr = spScript->AddTypeLib( CComModule::m_libid, 1, 0, 0L );
hr = spScript->AddNamedItem( OLESTR("Me"), SCRIPTITEM_ISVISIBLE );
...
spScript->Close();
}
}
With best wishes,
Vita
|
|
|
|
|
I have an stl list of pointers to objects.
When I need to insert an object to the list, I new it and push_back its
pointer.
When the list is not needed any more, I iterate through the entire list and
I delete each pointer.
First question: Is there a more elegant way to do this or is my
implementation ok?
Sometimes I wish to copy a pointer for one list into another list, meaning
that the two lists will contain a pointer to the same object.
When the first list is destroyed, I delete all pointers inside it, as
mentioned above.
When the second list is destroyed, I do the same, however my pointers are
already deleted and this of course crashes the program.
My first thought was to implement reference counting on my object, however I
am unsure of where to increment the reference.
The code looks something like this:
std::list<cmyobj*> list1;
std::list<cmyobj*> list2;
CMyObj* pOBJ = new CMyObj;
list1.push_back(pOBJ);
list2.insert(list2.begin(), list1.begin(), list1.end());
// delete all elements in list1
// delete all elements in list2 (crash)
When list2.insert is called, a copy of the pointer from list1 is inserted
into list2.
I will need to increment the reference of the pointer which is inserted,
however I am unsure of how to do this.
Does anyone have a solution to this?
Thanks in advance,
Jeremy Pullicino
C++ Developer
Homepage
|
|
|
|
|
Hi Jeremy,
As you correctly point out, some sort of ref counting is needed to address your problem. IMHO providing CMyObj with the ref counting machinery is not a good idea as this artifact properly does not belong to CMyObj semantics, but rather it is imposed by external conditions (the necessity of storing CMyObj pointers into several containers).
A much cleaner approach is to use some sort of smart pointer that does the ref counting to the objects pointed to and deletes them when the objects are no further referenced. If you feel comfortable with Boost, check Boost Smart Pointers Library[^]: in particular, boost::shared_ptr does exactly what you need.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I highly recommend Loki::SmartPtr[^] for that purpose. Or if you don't feel comfortable with this, use boost::shared_ptr.
|
|
|
|
|
Dear all,
I have a situation like this. For my application i have a bit map, and i wat to set this bitmap cursor in some area of my GUI. the bit map to be set as the cursor is not the original one from the resource, before that i want to rotate the bitmap according to some events like mouse scroll event, ok i can make it rotate the bitmap using the code,HBITMAP CRotateimageDlg::GetRotatedBitmapNT(HBITMAP hBitmap, float radians, COLORREF clrBack)
{
// Create a memory DC compatible with the display
CDC sourceDC, destDC;
sourceDC.CreateCompatibleDC( NULL );
destDC.CreateCompatibleDC( NULL );
// Get logical coordinates
BITMAP bm;
::GetObject( hBitmap, sizeof( bm ), &bm );
float cosine = (float)cos(radians);
float sine = (float)sin(radians);
// Compute dimensions of the resulting bitmap
// First get the coordinates of the 3 corners other than origin
int x1 = (int)(bm.bmHeight * sine);
int y1 = (int)(bm.bmHeight * cosine);
int x2 = (int)(bm.bmWidth * cosine + bm.bmHeight * sine);
int y2 = (int)(bm.bmHeight * cosine - bm.bmWidth * sine);
int x3 = (int)(bm.bmWidth * cosine);
int y3 = (int)(-bm.bmWidth * sine);
int minx = min(0,min(x1, min(x2,x3)));
int miny = min(0,min(y1, min(y2,y3)));
int maxx = max(0,max(x1, max(x2,x3)));
int maxy = max(0,max(y1, max(y2,y3)));
int w = maxx - minx;
int h = maxy - miny;
// Create a bitmap to hold the result
HBITMAP hbmResult = ::CreateCompatibleBitmap(CClientDC(NULL), w, h);
HBITMAP hbmOldSource = (HBITMAP)::SelectObject( sourceDC.m_hDC, hBitmap );
HBITMAP hbmOldDest = (HBITMAP)::SelectObject( destDC.m_hDC, hbmResult );
// Draw the background color before we change mapping mode
HBRUSH hbrBack = CreateSolidBrush( clrBack );
HBRUSH hbrOld = (HBRUSH)::SelectObject( destDC.m_hDC, hbrBack );
destDC.PatBlt( 0, 0, w, h, PATCOPY );
::DeleteObject( ::SelectObject( destDC.m_hDC, hbrOld ) );
// We will use world transform to rotate the bitmap
SetGraphicsMode(destDC.m_hDC, GM_ADVANCED);
XFORM xform;
xform.eM11 = cosine;
xform.eM12 = -sine;
xform.eM21 = sine;
xform.eM22 = cosine;
xform.eDx = (float)-minx;
xform.eDy = (float)-miny;
SetWorldTransform( destDC.m_hDC, &xform );
// Now do the actual rotating - a pixel at a time
destDC.BitBlt(0,0,bm.bmWidth, bm.bmHeight, &sourceDC, 0, 0, SRCCOPY );
// Restore DCs
::SelectObject( sourceDC.m_hDC, hbmOldSource );
::SelectObject( destDC.m_hDC, hbmOldDest );
return hbmResult;
} and can load it in to the image control, but my require ment is another one, how can i load the returned HBITMAP as a cursor?? pls get me if anybody has the idea, or if u have the code snipet pls let me know..
Thanks in advance.
AnuragVelekkattu
|
|
|
|
|
Hi all, what can i use in WTL for handling time/date information?, ibe been using the good old SYSTEMTIME struct till now, but now i have to do some time calculations, and its a real pain to do all the convert to FILETIME, etc, etc. stuff just to substract a date from another one!
Should i....
1.- Write my own WTL MFC-CTime equivalent class?
2.- Use COleDateTime? (can i do this without having to link to MFC libs?)
3.- Is there a wonderfull time/date handling class for WTL that i dont know about?
Thanks!
|
|
|
|
|
You could try the Boost date/time libraries...[^] You'd probably have to write functions to get to/from native Windows types, though.
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
You could consider converting to OLE Date/Time format without COleDateTime, using SystemTimeToVariantTime, which lets you then do subtraction for date/time differences. The integer part of the result is the number of days difference, and you can use VariantTimeToSystemTime to make extracting hh:mm:ss information simpler.
Steve S
|
|
|
|
|
Thanks Steve & Stuart, i decided to write my own time classes so from now on i never have time-troubles again so i wrote CWTime & CElapsedTime
and they seem to work sweet so far.
Thanks for your answers!
|
|
|
|
|
If you are lucky enough to get VS.NET, then you can use the classic MFC CTime class - it is now a shared ATL/MFC class (along with CString and others).
When I am king, you will be first against the wall.
|
|
|
|
|
Hi and thanks for your answer, i do have VS.NET, but about 1 month after buying it, i uninstalled it and went back to 6.0. why?
because quite simply, IT SUCKS!
(please note that i dont start a never ending devate on .net, this is my OWN PERSONAL OPINION, im shure many people find .net lovely)
NE way, i allready wrote a pair of time classes for wtl, sort of a "port" of the MFC´s CTime & CTimeSpan classes (ill be glad to share them with anyone interested), and they work just fine.
Cheers!
|
|
|
|
|
I know the VS.NET IDE sucks AND blows but you're missing out on ATL7 which is an excellent set of classes...
The Rob Blog
|
|
|
|
|
and even better with WTL7 installed, despite the 'glitches' that stop it being easy to install for VS.NET 2003.
Why don't MS realise what a success story WTL is, and make it an official part of the product? Is it that they're afraid no-one will use MFC, or is it self-preservation on the part of the author who realises that MS control freaks will kill the product?
Steve S
|
|
|
|
|
I think microsoft doesnt support wtl for one reason, They dont have to! or in other words, it wont make them any more money(and thats all they care about), they know that 90% of people will continue to use the arcane, buggy, and overcomplicated MFC libs even if they dont like it because its (sadly) become the "standard" for writting windows apps, and since its what "most people use", even the people that hate MFC (like me), are sometimes FORCED to use it, i had a customer (a systems manager for a hotel in my city) that told me exacly this: "if you dont do it on MFC, then i dont want it", when i asked her why, her answer was sadly true: "because if you do it on wtl, W32, or whatever, i will have a hard time finding some one to maintain it, but if you do it on MFC, then finding someone that knows/uses MFC is not a problem".
I think that microsoft should make WTL open source, its (in my opinion) a GREAT library that should continue to get supported, documented, etc.
|
|
|
|
|
|
Agreed, too few update to MFC/ATL and the IDE now mix-up with .nut, which make C/C++ more complicated as before.
|
|
|
|
|
|
Roger Stewart
"I Owe, I Owe, it's off to work I go..."
|
|
|
|
|
or in English;
"Can anyone tell me where I can download a free e-book on ATL development"
is my guess.
Steve S
|
|
|
|
|
Please tell me : How do ocx control by ATL in vs.net2003?
顺便问一下:这有中国的吗?我的英文不太好,用中文好交流!有的话: rqxiang@hotmail.com
|
|
|
|
|
When i am using it in ActiveX control, it is doing some odd stuff like on SetPos it doesnt show progress bar in right possition, quite frankly on first call it sets it to 2/3 and it stays there... anyone knows why and how to fix it (and I do know how to use progress bar ctrl )
|
|
|
|
|
According instruction, I try to install WTL 7.0 step by step. The wizard icon appears in the new/project dialog, but when I create a new project, it said: Object with program ID VsWizard.VsWizardEngine can not be created. Why? Could you help me? Thank you.
|
|
|
|
|
The WTL 7.0 Wizard isn't immediately compatible with VS.NET 2003 (there's some registry key differences). However, it can be fixed See this[^]
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Ah! Thank you! I found out about this little problem earlier today.
--
Im hayu samim et hamo'ach shelcha betoch tsipor, hi hayta matchila la'uf achora!
|
|
|
|
|