The Wayback Machine - https://web.archive.org/web/20090216122840/http://www.codeproject.com:80/script/Forums/View.aspx?fid=4486
Click here to Skip to main content
5,892,890 members and growing! (17,659 online)
Announcements
* Bold indicates new messages since 2:28 16 Feb '09




BullFrog Power
Advanced Search
Sitemap

ATL / WTL / STL


Home > Forums > ATL / WTL / STL

 Msgs 1 to 25 of 171 (Total in Forum: 7,341) (Refresh)FirstPrevNext
QuestionWhy basic_string doesn't support back(), but vector do?memberfollowait18:52 13 Feb '09  
I need it when writing an algorithm, but surprisingly it is there.
AnswerRe: Why basic_string doesn't support back(), but vector do?member«_Superman_»20:44 13 Feb '09  
You could implement something like the following to get the same functionality
string s;

try
{
s.at(s.size() - 1)
}
catch (exception& e)
{
}


«_Superman_»

AnswerRe: Why basic_string doesn't support back(), but vector do?memberStuart Dootson21hrs 25mins ago 
The most flexible way to get that functionality is probably a function like this

template<class StringType>
typename StringType::value_type back(StringType const& s)
{
return *s.rbegin();
}


Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

QuestionHow do we Inherit struct from another struct in IDL filememberGopal_Kanchana0:44 12 Feb '09  
How do we Inherit struct from another struct in IDL file
QuestionHow to trap Excel 2007 cell events using ATL addinmemberSNI3:18 11 Feb '09  
Hi,
I have Add In developed in ATL COM which will take care of open, close etc...events. I am able to get the events for Word 2007 but when I am using perticular cell in Excel 2007 and my cursor is in the same cell I wont be able to get name of the excel file. Since my cursor is in cell then I wont get file activate event.
I would like to know how to get the name of excel file even if my cursor is in cell (note:- cell is not selected. cursor is present in the cell)

Thanks

SNI

QuestionProblem with ATL COM Dll.... Firing event in threadmemberchetanjoshi921:15 10 Feb '09  
Hi,

I am using the ATL COM DLL. In this I am createng two threads.
I have added new ATL object which supports connceting point, appartment thereaded model,
Dual interface and agregation=yes. While creating thread and passing the interface pointer as this pointer.

hStatusThread = CreateThread(NULL,
o,
LPTHREAD_START_ROUTINE(StatusThread),
(LPVOID)this,
0,
&dwThStId;);

::SetThreadPriority(hStatusThread, THREAD_PRIORITY_HIGHEST);

I am accessing the interface pointer in thread and firing the event..

UINT StatusThread(LPVOID param)
{
CMyConnectObj *ptrObj = NULL;
ptrObj = (CMyConnectObj*)param;

if(ptrObj == NULL)
return 0;

if(WaitForSingleObject(g_Mutex,INFINITE) == WAIT_OBJECT_0)
{
ptrObj->Fire_ErrorCode(lErrorCode);
ReleaseMutex(g_Mutex);
}

}

I am using vb6.0 client to use this dll.

but while firing event at line i
ptrObj->Fire_ErrorCode(lErrorCode);

it's giving error as "Unhandled Exception in ConnectProg.exe (MSVBVM60.dll)0x0000005: Access Violation.

But if I tried to fire event for one of the ATL object function there is no problem at all.

Please help me for this with perect solution..
It's very urgent.
AnswerRe: Problem with ATL COM Dll.... Firing event in threadmemberStuart Dootson23:56 10 Feb '09  
chetanjoshi9 wrote:
THREAD_PRIORITY_HIGHEST


That's a bit evil for a start - you really don't want to be altering thread priorities.

chetanjoshi9 wrote:
MSVBVM60


That's likely your problem - your contorl might be thread aware, but I don't think VB6 is...

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: Problem with ATL COM Dll.... Firing event in threadmemberchetanjoshi90:06 11 Feb '09  
what is mean by thread aware?
GeneralRe: Problem with ATL COM Dll.... Firing event in threadmemberStuart Dootson1:46 11 Feb '09  
Your control is aware that there can be more more than one thread, and deals with that. Visual Basic doesn't.

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: Problem with ATL COM Dll.... Firing event in threadmemberchetanjoshi91:52 11 Feb '09  
please tell me the settings required while creating the new ATL object if we want to fire event within the thread....
GeneralRe: Problem with ATL COM Dll.... Firing event in threadmemberStuart Dootson1:59 11 Feb '09  
First thing to try - you need to call CoInitializeEx[^] on the StatusThread, that way your event firing might be marshalled across into the VB thread.

Otherwise...have you thought about firing the event on the other thread, you know, the one VB calls?

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: Problem with ATL COM Dll.... Firing event in threadmemberchetanjoshi92:26 11 Feb '09  
hStatusThread = CreateThread(NULL,
0,
LPTHREAD_START_ROUTINE(StatusThread),
(LPVOID)this,
0,
(LPDWORD)&dwStID;);

::SetThreadPriority(hStatusThread, THREAD_PRIORITY_HIGHEST);




UINT StatusThread(LPVOID param)
{
MSG msg;

CMyTestObj *ptrObj = (CMyTestObj*)param;

while(1)
{
if(!GetMessage(&msg;, NULL, 0, 0))
return 0;

switch(msg.message)
{
case START_COMMAND:

ptrObj->Fire_ErrorCode(123);

break;
}
}
}


This is my code
I am firing event in thread as
PostThreadMessage(dwStID, START_COMMAND, NULL, NULL);

but application crashes at line "ptrObj->Fire_ErrorCode(123);"

But if fire event in any member function (without thread) it works fine..

Please help me for this..
it's very urgent

Thanks.
GeneralRe: Problem with ATL COM Dll.... Firing event in threadmemberStuart Dootson2:56 11 Feb '09  
No, that's not what I said, is it. Did I say something about adding a CoInitializeEx to StatusThread? Yes, I think I did. Try that first, it may enable the COM runtime to marshall the event fire across to the VB thread.

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: Problem with ATL COM Dll.... Firing event in threadmemberchetanjoshi93:19 11 Feb '09  
please tell me how to use CoInitialzeEx() on StatusThread..
I am not getting....

Please...
GeneralRe: Problem with ATL COM Dll.... Firing event in threadmemberStuart Dootson3:26 11 Feb '09  
Go away and learn about how COM and threads interact[^]. You need to understand this stuff before you try messing with COM and threads.

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

QuestionHelp required in writing a class to write/read log data to XML filesmemberRennie761:38 9 Feb '09  
I am relatively new to ATL/WTL. I am writing an application in VC++ using ATL/WTL (not using MFC).

I need to write helper classes for my application that will
- Write all the log information in the form of proper XML files. I need to follow a valid/standard schema with XSLT for writing the XML data.
- Parser to read the XML files using the above schema & iterate through the nodes.

I have never worked with XML before and I am only trying to use ATL/WTL with VC++, so I would greatly appreciate if anyone can instruct me on how I can go about implementing this, for example - point me to the right classes for implementing a XML wrapper for writing data in XML files & for parsing the XML files and iterating through the nodal data. Some sample code would also be very helpful for me in this regard.

modified on Monday, February 9, 2009 8:21 AM

AnswerRe: Help required in writing a class to write/read log data to XML filesmemberStuart Dootson3:33 9 Feb '09  
ATL's not going to help you much - it doesn't have any XML classes. I would use MSXML[^], I guess. You could use ATL smart pointer and BSTR wrapper classes.

Rennie76 wrote:
I need to follow a valid/standard schema with XSLT for writing the XML data


XML Schemas are XSD, not XSLT - XSLT is for transforming XML from one format to another.
GeneralRe: Help required in writing a class to write/read log data to XML filesmvpled mike6:28 10 Feb '09  
Stuart Dootson wrote:
I guess. You could use ATL smart pointer and BSTR wrapper classes.


Yes, I would not use MSXML without the ATL #import code. Also _com_error, _bstr_t, _variant_t
GeneralRe: Help required in writing a class to write/read log data to XML filesmemberRennie7622:38 10 Feb '09  
Thanks for the pointers!
AnswerRe: Help required in writing a class to write/read log data to XML filesmvpled mike6:31 10 Feb '09  
As already mentioned there is MSXML and also XMLLite.

Rennie76 wrote:
Some sample code would also be very helpful for me in this regard.


Both are documented on the msdn web site and I imagine sample code is available there as well.
GeneralRe: Help required in writing a class to write/read log data to XML filesmemberStuart Dootson7:37 10 Feb '09  
led mike wrote:
XMLLite


Ooooh - I'd forgotten about that one. Nice reminder.

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: Help required in writing a class to write/read log data to XML filesmemberRennie7623:00 10 Feb '09  
Thanks!
QuestionATL Simple Object Methods and retval [modified]memberbob169729:32 5 Feb '09  
When creating an ATL COM project and adding an ATL Simple Object, if I create a method for that class that has one [in] BSTR parameter and one [out,retval] BSTR* parameter...

What can I assume or assert about the retval in this circumstance? In other words, do I need to check the BSTR to ensure that it does not already point to something and deallocate it if I decide to set the value? Is it mandatory to set the BSTR's value to something?

STDMETHODIMP CSomeATLClass::SomeATLClassMethod(BSTR bstrIn, BSTR* retVal)
{
// Is retVal guaranteed to be pointing to a NULL BSTR at this point?

/*
Am I required to set the BSTR that retVal points to to something other than NULL
before the method returns?
*/

return S_OK;
}


modified on Thursday, February 5, 2009 3:04 PM

AnswerRe: ATL Simple Object Methods and retvalmemberJonathan Davies10:23 5 Feb '09  
An [out] BSTR* will not point to a valid BSTR when your method is entered; it will not be set to NULL either so will contain some invalid value.
Setting it to NULL on entering the method I would consider good practice - at least you know what its set to at that point. Your interface definition will say a BSTR is returned so a caller using it might not be too happy to have NULL returned where a string is expected. Using an assert to check its not null in the calling code would be a good idea.
Personally I like code to be simple in that if a BSTR is expected that's what I get, conveying some deeper meaning by setting the pointer to NULL, complicates things as far as I'm concerned. If you decide for some reason you can't return a BSTR why not use the HRESULT to convey this information?
GeneralRe: ATL Simple Object Methods and retvalmemberbob1697210:48 5 Feb '09  
I'm currently setting the BSTR to an empty string on error but with try/catch blocks in there, I was questioning myself if all the hoopla was really needed.

Thanks for taking the time out to assist me. I will keep the code that ensures an empty BSTR is returned.

Take care. Smile

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Last Updated 9 Aug 2007
Web10 | Advertise | Privacy
Copyright © CodeProject, 1999-2009
All Rights Reserved. Terms of Use